Commit de9d2687 authored by Chrysanthi Lagodimou's avatar Chrysanthi Lagodimou Committed by Tugce Nur Tas
Browse files

acceptance available if one can terminate

parent aea8c2e1
......@@ -2,21 +2,20 @@ class VolunteerPolicy < ApplicationPolicy
class Scope < ApplicationScope
def resolve
return all if superadmin?
return scope.seeking_clients.distinct if department_manager?
return scope.where(registrar_id: user) if department_manager?
none
end
alias :seeking_clients :resolve
end
def volunteer_managing_or_volunteers_profile?
superadmin_or_department_manager_or_social_worker? || user_owns_record?
superadmin_or_department_managers_registration? || user_owns_record?
end
# controller action policies
alias_method :index?, :superadmin_or_department_manager_or_social_worker?
alias_method :search?, :superadmin_or_department_manager_or_social_worker?
alias_method :new?, :superadmin_or_department_manager_or_social_worker?
alias_method :create?, :superadmin_or_department_manager_or_social_worker?
alias_method :index?, :superadmin_or_department_manager?
alias_method :search?, :superadmin_or_department_manager?
alias_method :new?, :superadmin_or_department_manager?
alias_method :create?, :superadmin_or_department_manager?
alias_method :seeking_clients?, :superadmin_or_department_manager?
alias_method :terminate?, :superadmin_or_department_managers_registration?
alias_method :show?, :volunteer_managing_or_volunteers_profile?
......@@ -25,4 +24,5 @@ class VolunteerPolicy < ApplicationPolicy
# supplementary policies
alias_method :superadmin_privileges?, :superadmin?
alias_method :show_acceptance?, :superadmin_or_department_manager?
end
......@@ -18,7 +18,7 @@
th= sort_link @q, :working_percent
th= sort_link @q, :expectations
th= sort_link @q, :interests
- if policy(Volunteer).superadmin_privileges?
- if policy(Volunteer).show_acceptance?
th= sort_link @q, :acceptance
th= sort_link @q, :external
th= t_attr(:created_by)
......
......@@ -13,7 +13,7 @@ tr
td = "#{volunteer.working_percent}%" if volunteer.working_percent.present?
td = volunteer.expectations
td = volunteer.interests
- if policy(Volunteer).superadmin_privileges?
- if policy(Volunteer).show_acceptance?
td.button-acceptance = link_to t(".acceptance.#{volunteer.acceptance}"), '#',
class: "btn btn-xs btn-acceptance-#{volunteer.acceptance}"
td = volunteer.external? ? t_attr(:external) : t_attr(:internal)
......
......@@ -19,7 +19,7 @@ nav.navbar.section-navigation
ul.list-inline
li= button_link t('clear_filters'), volunteers_path, dimension: 'sm'
li= button_link navigation_fa_icon(:xlsx), url_for(format: :xlsx, q: search_parameters), dimension: 'sm'
- if policy(Volunteer).superadmin_privileges?
- if policy(Volunteer).show_acceptance?
= enum_filter_dropdown(:acceptance, Volunteer.acceptances)
= boolean_toggler_filter_dropdown(:active, 'Einsatz', 'Aktiv', 'Inaktiv')
= boolean_toggler_filter_dropdown(:external, 'Intern/Extern', 'Extern', 'Intern')
......
......@@ -10,10 +10,11 @@ nav.navbar.section-navigation
- if policy(Volunteer).superadmin_privileges?
li= button_link 'Journal', polymorphic_path([@volunteer, Journal]), 'primary'
ul.list-inline
- if policy(Volunteer).superadmin_privileges?
- if policy(@volunteer).terminate?
li.button-acceptance = link_to t(".acceptance.#{@volunteer.acceptance}"), '#',
class: "btn btn-acceptance-#{@volunteer.acceptance}"
li= button_link 'Beenden', terminate_volunteer_path(@volunteer)
- if policy(Volunteer).superadmin_privileges?
ul.list-inline
- if @volunteer.seeking_clients?
li= button_link t_title(:new, Assignment), new_assignment_path(volunteer_id: @volunteer)
......
......@@ -3,7 +3,7 @@ require 'test_helper'
class VolunteerPolicyTest < PolicyAssertions::Test
def setup
@actions = ['index?', 'search?', 'new?', 'create?', 'seeking_clients?', 'terminate?', 'show?',
'edit?', 'update?', 'superadmin_privileges?']
'edit?', 'update?', 'show_acceptance?', 'superadmin_privileges?']
end
test 'superadmin_can_use_all_actions' do
......@@ -14,16 +14,15 @@ class VolunteerPolicyTest < PolicyAssertions::Test
department_manager = create :department_manager
department_manager_volunteer = create :volunteer_with_user
department_manager_volunteer.registrar = department_manager
assert_permit(department_manager, Volunteer, *@actions[0..4], *@actions[6..8])
assert_permit(department_manager, department_manager_volunteer, *@actions[5])
refute_permit(department_manager, create(:volunteer), *@actions[5])
refute_permit(department_manager, Volunteer, *@actions[-2..-1])
assert_permit(department_manager, Volunteer, *@actions[0..4], *@actions[-2])
assert_permit(department_manager, department_manager_volunteer, *@actions[5..8])
refute_permit(department_manager, create(:volunteer), *@actions[5..8])
refute_permit(department_manager, Volunteer, *@actions[-1])
end
test 'social_worker_has_limited_access' do
test 'social_worker_has_no_access' do
social_worker = create :social_worker
assert_permit(social_worker, Volunteer, *@actions[0..3], *@actions[6..8])
refute_permit(social_worker, Volunteer, *@actions[4..5], *@actions[-2..-1])
refute_permit(social_worker, Volunteer, *@actions)
end
test 'volunteer_has_limited_access' do
......@@ -31,6 +30,6 @@ class VolunteerPolicyTest < PolicyAssertions::Test
volunteer_two = create :volunteer_with_user
assert_permit(volunteer_one.user, volunteer_one, *@actions[6..8])
refute_permit(volunteer_one.user, volunteer_two, *@actions[6..8])
refute_permit(volunteer_one.user, Volunteer, *@actions[0..5], *@actions[-2..-1])
refute_permit(volunteer_one.user, Volunteer, *@actions[0..5], *@actions[9..-1])
end
end
......@@ -31,7 +31,7 @@ class DepartmentManagerTest < ApplicationSystemTestCase
end
test 'can see a group offer volunteer and return to the group offer' do
volunteer = create :volunteer
volunteer = create :volunteer, registrar: @department_manager
group_offer = create :group_offer, volunteers: [volunteer],
department: @department_manager.department.first
visit volunteer_path(volunteer)
......@@ -53,8 +53,8 @@ class DepartmentManagerTest < ApplicationSystemTestCase
assert page.has_text? 'new title'
end
test 'department manager has no destroy and feedback links on volunteer show' do
volunteer = create :volunteer
test 'department_manager_has_no_destroy_and_feedback_links_on_volunteer_show' do
volunteer = create :volunteer, registrar: @department_manager
group_offer = create :group_offer, volunteers: [volunteer],
department: @department_manager.department.first
assignment = create :assignment, volunteer: volunteer
......
......@@ -198,28 +198,23 @@ class VolunteersTest < ApplicationSystemTestCase
end
end
test 'department_manager_can_see_volunteer_index_and_only_seeking_clients_volunteers' do
test 'department_manager_can_see_volunteer_index_and_only_her_own_volunteers' do
department_manager = create :department_manager
login_as department_manager
volunteer_department_manager = create :volunteer, registrar: department_manager
other_volunteer = create :volunteer
volunteer_seeks = create :volunteer_with_user
create :assignment, period_start: 500.days.ago, period_end: 200.days.ago,
volunteer: volunteer_seeks
volunteer_not_seeking = create :volunteer_with_user
create :assignment, period_start: 10.days.ago, period_end: nil,
volunteer: volunteer_not_seeking
visit volunteers_path
assert page.has_text? volunteer_seeks.contact.full_name
refute page.has_text? volunteer_not_seeking.contact.full_name
assert page.has_text? volunteer_department_manager.contact.full_name
refute page.has_text? other_volunteer.contact.full_name
end
test 'social_worker_can_see_volunteer_index' do
social_worker = create :social_worker
login_as social_worker
test 'social_worker_cannot_see_volunteer_index' do
login_as create(:social_worker)
visit volunteers_path
assert page.has_text? 'Freiwillige'
assert page.has_text? 'You are not authorized to perform this action.'
end
test 'social_worker_cant_see_volunteer_seeking_clients' do
......@@ -259,9 +254,10 @@ class VolunteersTest < ApplicationSystemTestCase
end
test 'department manager has no link to group offer of not their own' do
volunteer = create :volunteer
department_manager = create :department_manager
volunteer = create :volunteer, registrar: department_manager
group_offer = create :group_offer, volunteers: [volunteer]
login_as create :department_manager
login_as department_manager
visit volunteer_path(volunteer)
assert page.has_text? group_offer.title
refute page.has_link? group_offer.title
......
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