Commit f13212a6 authored by Kaspar Vollenweider's avatar Kaspar Vollenweider 👻 Committed by Kaspar
Browse files

Volunteer gets directly to volunteers_controller#show after login

-
parent ec2b9b3c
......@@ -7,6 +7,7 @@ class ApplicationController < ActionController::Base
rescue_from Pundit::NotAuthorizedError, with: :user_not_authorized
def after_sign_in_path_for(current_user)
return volunteer_path(current_user.volunteer.id) if current_user.volunteer?
return new_profile_path if current_user.profile.blank?
if policy(Department).manager_with_department?
return department_path(current_user.department.first.id)
......
......@@ -45,6 +45,7 @@ class VolunteersController < ApplicationController
def invite_volunteer_user
new_user = User.new(email: @volunteer.email, password: Devise.friendly_token, role: 'volunteer')
new_user.save
@volunteer.user = new_user
new_user.invite!
redirect_to volunteers_path, notice: t('invite_sent', email: new_user.email)
end
......
......@@ -20,15 +20,19 @@ class User < ApplicationRecord
scope :department_assocable, (-> { where(role: [SUPERADMIN, DEPARTMENT_MANAGER]) })
def superadmin?
role == User::SUPERADMIN
role == SUPERADMIN
end
def social_worker?
role == User::SOCIAL_WORKER
role == SOCIAL_WORKER
end
def department_manager?
role == User::DEPARTMENT_MANAGER
role == DEPARTMENT_MANAGER
end
def volunteer?
role == VOLUNTEER
end
def superadmin_or_department_manager?
......
......@@ -19,15 +19,15 @@ class VolunteerPolicy < ApplicationPolicy
end
def show?
user.superadmin?
user.superadmin? || (user.volunteer? && user.volunteer.id == volunteer.id)
end
def edit?
user.superadmin?
user.superadmin? || (user.volunteer? && user.volunteer.id == volunteer.id)
end
def update?
user.superadmin?
user.superadmin? || (user.volunteer? && user.volunteer.id == volunteer.id)
end
def destroy?
......
......@@ -28,10 +28,11 @@ nav.navbar.navbar-top
= current_user.email
span.caret
ul.dropdown-menu
li
- if current_user.profile.blank?
= link_to t('create_profile'), new_profile_path
- else
= link_to t('show_profile'), current_user.profile
- unless current_user.volunteer?
li
- if current_user.profile.blank?
= link_to t('create_profile'), new_profile_path
- else
= link_to t('show_profile'), current_user.profile
li
= link_to t('logout'), destroy_user_session_path, method: :delete
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment