Commit 96b4750d authored by Tugce Nur Tas's avatar Tugce Nur Tas
Browse files

unify comments policy

parent f8c0fa38
Pipeline #19514 failed with stage
in 11 minutes and 1 second
......@@ -15,7 +15,7 @@ class AssignmentPolicy < ApplicationPolicy
alias_method :new?, :superadmin_or_department_manager?
alias_method :create?, :superadmin_or_department_manager?
alias_method :find_client?, :superadmin_or_department_manager?
alias_method :comments?, :superadmin_or_department_manager?
alias_method :show_comments?, :superadmin_or_department_manager?
alias_method :show?,
:superadmin_or_department_manager_creation_or_volunteer_related?
......
......@@ -28,7 +28,7 @@ class ClientPolicy < ApplicationPolicy
# suplementary policies
alias_method :superadmin_privileges?, :superadmin?
alias_method :comments?, :superadmin_or_department_manager_or_social_worker?
alias_method :show_comments?, :superadmin_or_department_manager_or_social_worker?
def acceptance_collection
if superadmin_or_department_managers_record?
......
......@@ -11,7 +11,7 @@ class GroupAssignmentPolicy < ApplicationPolicy
alias_method :create?, :superadmin_or_department_manager_offer?
alias_method :terminated_index?, :superadmin_or_department_manager?
alias_method :comments?, :superadmin_or_department_manager?
alias_method :show_comments?, :superadmin_or_department_manager?
alias_method :edit?, :superadmin_or_department_manager_creation?
alias_method :set_end_today?, :superadmin_or_department_manager_creation?
......
......@@ -33,4 +33,5 @@ class GroupOfferPolicy < ApplicationPolicy
# supplemental policies
alias_method :supervisor_privileges?, :superadmin?
alias_method :show_comments?, :superadmin_or_department_manager_is_responsible?
end
......@@ -6,7 +6,7 @@ table.table.table-striped.assignment-logs-table
th= t_attr(:period_start, Assignment)
th= t_attr(:period_end, Assignment)
th Fallführende Stelle
- if policy(Assignment).comments?
- if policy(Assignment).show_comments?
th= t_attr(:comments)
th colspan=2
tbody
......@@ -30,7 +30,7 @@ table.table.table-striped.assignment-logs-table
profile_link(assignment.creator)
td= link_to_if(assignment.assignment && policy(assignment.assignment).show?,
t_action(:show), assignment.assignment) { '' }
- if policy(Assignment).comments?
- if policy(Assignment).show_comments?
= td_truncate_content_modal(assignment.comments, 'Bemerkungen')
td.index-action-cell.hidden-print
span
......
......@@ -6,7 +6,7 @@ table.table.table-striped.assignments-table
th= t_attr(:period_start, Assignment)
th= t_attr(:period_end, Assignment)
th= t_attr(:created_by)
- if policy(Assignment).comments?
- if policy(Assignment).show_comments?
th Bemerkungen
tbody
......@@ -19,6 +19,6 @@ table.table.table-striped.assignments-table
td= link_to_if policy(User).show?,
assignment.client.involved_authority&.full_name || assignment.creator.full_name,
profile_link(assignment.client.involved_authority || assignment.creator)
- if policy(Assignment).comments?
- if policy(Assignment).show_comments?
= td_truncate_content_modal(assignment.comments, 'Bemerkungen')
......@@ -14,7 +14,7 @@ tr
td= link_to_if policy(User).show?,
assignment.client.involved_authority&.full_name || assignment.creator.full_name,
profile_link(assignment.client.involved_authority || assignment.creator)
- if policy(Assignment).comments?
- if policy(Assignment).show_comments?
= td_truncate_content_modal(assignment.comments, 'Bemerkungen')
- if controller_name == 'volunteers' && !assignment.volunteer.external?
- if policy(TrialFeedback).index?
......
......@@ -11,7 +11,7 @@
th= sort_link @q, :period_start, t_attr(:period_start, Assignment)
th= sort_link @q, :period_end, t_attr(:period_end, Assignment)
th= 'Fallführende Stelle'
- if policy(Assignment).comments?
- if policy(Assignment).show_comments?
th= t_attr(:comments)
th.hidden-print colspan='4'
......
......@@ -17,7 +17,7 @@
.col-xs-12.col-md-6
= f.input :period, as: :date_range_picker, label: false
- if policy(Assignment).comments?
- if policy(Assignment).show_comments?
.col-xs-12.col-md-6
= f.input :comments
.col-xs-12.col-md-6
......
......@@ -27,5 +27,5 @@ tr
td= link_to client.involved_authority.full_name, profile_link(client.involved_authority) if client.involved_authority
td= client.competent_authority
td.no-wrap= l(client.created_at.to_date)
- if policy(Client).comments?
- if policy(Client).show_comments?
= td_truncate_content_modal(client.comments, 'Bemerkungen')
......@@ -73,6 +73,6 @@ fieldset
= f.input :competent_authority
= f.input :cost_unit, collection: Client.cost_unit_collection, include_blank: true
- if policy(Client).comments?
- if policy(Client).show_comments?
= f.input :comments
= f.input :additional_comments
......@@ -28,7 +28,7 @@ h1 Klient/innen
span= sort_link @q, :competent_authority, t_attr(:competent_authority, Client)
th.truncate-th
span= sort_link @q, :created_at, t_attr(:created_at, Client)
- if policy(Client).comments?
- if policy(Client).show_comments?
th= t_attr(:comments, Client)
tbody
= render @clients
......
......@@ -69,7 +69,7 @@ h1.m-b-20= @client.contact.full_name
td= t_attr(:created_by)
td= link_to @client.user.full_name, profile_link(@client.user)
- if policy(Client).comments?
- if policy(Client).show_comments?
tr
td= t_attr(:comments)
td= @client.comments
......
......@@ -10,7 +10,7 @@
.row
.col-xs-12.col-md-6
= f.input :period, as: :date_range_picker, label: false
- if policy(GroupAssignment).comments?
- if policy(GroupAssignment).show_comments?
= f.input :comments
= f.input :additional_comments
= f.input :agreement_text, input_html: { class: 'text-body' }, label: t('assignment_pdf.agreement_text')
......
......@@ -8,7 +8,7 @@ table.table.table-striped.group-assignments-table
th= t_attr(:role, GroupAssignment)
th= t_attr(:period_start, GroupAssignment)
th= t_attr(:period_end, GroupAssignment)
- if policy(GroupAssignment).comments?
- if policy(GroupAssignment).show_comments?
th= t_attr(:comments)
th colspan=(editable ? '7' : '2')
tbody
......@@ -44,7 +44,7 @@ table.table.table-striped.group-assignments-table
= t_attr(:member, GroupAssignment)
td= l(group_assignment.period_start) if group_assignment.period_start
td= l(group_assignment.period_end) if group_assignment.period_end
- if policy(GroupAssignment).comments?
- if policy(GroupAssignment).show_comments?
= td_truncate_content_modal(group_assignment.comments, 'Bemerkungen')
- if editable && !@volunteer.external?
td.index-action-cell.hidden-print
......
......@@ -5,7 +5,7 @@ table.table.table-striped.group-assignments-table
th= t_attr(:role, GroupAssignment)
th= t_attr(:period_start, GroupAssignment)
th= t_attr(:period_end, GroupAssignment)
- if policy(GroupAssignment).comments?
- if policy(GroupAssignment).show_comments?
th= t_attr(:comments)
th colspan=2
tbody
......@@ -16,7 +16,7 @@ table.table.table-striped.group-assignments-table
td= t_attr(group_assignment.responsible ? :responsible : :member, GroupAssignment)
td= l(group_assignment.period_start) if group_assignment.period_start
td= l(group_assignment.period_end) if group_assignment.period_end
- if policy(GroupAssignment).comments?
- if policy(GroupAssignment).show_comments?
= td_truncate_content_modal(group_assignment.comments, 'Bemerkungen')
td= link_to_if(policy(group_assignment.group_offer).show? && !group_assignment.group_offer.deleted?,
t_action(:show), group_offer_path(group_assignment.group_offer)) { '' }
......
......@@ -49,7 +49,7 @@
- availabilities.each do |availability|
= f.input availability, label: t("availability.#{availability}")
- if policy(GroupOffer).edit?
- if policy(GroupOffer).show_comments?
.row
.col-xs-12.col-md-12= f.input :comments
......
......@@ -2,19 +2,19 @@ require 'test_helper'
class AssignmentPolicyTest < PolicyAssertions::Test
test 'superadmin_can_use_all_actions' do
assert_permit(create(:user), Assignment, *actions_list, 'comments?')
assert_permit(create(:user), Assignment, *actions_list, 'show_comments?')
end
test 'department_manager_has_limited_access' do
department_manager = create(:department_manager)
assignment_department_manager = create :assignment, creator: department_manager
assert_permit(department_manager, Assignment,
'comments?', *actions_list(
'show_comments?', *actions_list(
:index, :terminated_index, :volunteer_search, :client_search, :new, :create,
:hours_and_feedbacks_submitted
))
assert_permit(department_manager, assignment_department_manager,
'comments?', *actions_list(
'show_comments?', *actions_list(
:find_client, :show, :edit, :update,
:terminate, :update_terminated_at,
:update_submitted_at, :last_submitted_hours_and_feedbacks
......@@ -28,7 +28,7 @@ class AssignmentPolicyTest < PolicyAssertions::Test
end
test 'social_worker_has_no_access' do
refute_permit(create(:social_worker), Assignment, *actions_list, 'comments?')
refute_permit(create(:social_worker), Assignment, *actions_list, 'show_comments?')
end
test 'volunteer_has_limited_access' do
......@@ -41,12 +41,12 @@ class AssignmentPolicyTest < PolicyAssertions::Test
:hours_and_feedbacks_submitted
))
refute_permit(volunteer.user, Assignment,
'comments?', *actions_list(
'show_comments?', *actions_list(
:index, :terminated_index, :volunteer_search, :client_search,
:new, :create, :edit, :update,
:terminate, :update_terminated_at, :verify_termination
))
refute_permit(volunteer.user, other_assignment,
'comments?', *actions_list(except: [:hours_and_feedbacks_submitted]))
'show_comments?', *actions_list(except: [:hours_and_feedbacks_submitted]))
end
end
......@@ -14,14 +14,14 @@ class ClientPolicyTest < PolicyAssertions::Test
test 'superadmin_can_use_all_actions' do
assert_permit(@superadmin, Client,
'superadmin_privileges?', 'comments?', *actions_list)
'superadmin_privileges?', 'show_comments?', *actions_list)
end
test 'department_manager_has_limited_access' do
assert_permit(@department_manager, @manager_client,
*actions_list(:edit, :update, :set_terminated), 'comments?')
*actions_list(:edit, :update, :set_terminated), 'show_comments?')
assert_permit(@department_manager, Client,
*actions_list(:index, :search, :new, :create, :show), 'comments?')
*actions_list(:index, :search, :new, :create, :show), 'show_comments?')
refute_permit(@department_manager, create(:client),
*actions_list(:edit, :update, :set_terminated))
refute_permit(@department_manager, Client, 'superadmin_privileges?',
......@@ -30,9 +30,9 @@ class ClientPolicyTest < PolicyAssertions::Test
test 'social_worker_has_limited_access' do
assert_permit(@social_worker, Client,
*actions_list(:index, :search, :new, :create, :show), 'comments?')
assert_permit(@social_worker, @social_client, *actions_list(:edit, :update), 'comments?')
assert_permit(@social_worker, @social_involved, *actions_list(:edit, :update), 'comments?')
*actions_list(:index, :search, :new, :create, :show), 'show_comments?')
assert_permit(@social_worker, @social_client, *actions_list(:edit, :update), 'show_comments?')
assert_permit(@social_worker, @social_involved, *actions_list(:edit, :update), 'show_comments?')
refute_permit(@social_worker, create(:client), *actions_list(:edit, :update, :set_terminated))
refute_permit(@social_worker, Client, 'superadmin_privileges?', *actions_list(:set_terminated))
end
......
......@@ -2,7 +2,7 @@ require 'test_helper'
class GroupAssignmentPolicyTest < PolicyAssertions::Test
test 'superadmin_can_use_all_actions' do
assert_permit(create(:user), GroupAssignment, *actions_list, 'comments?')
assert_permit(create(:user), GroupAssignment, *actions_list, 'show_comments?')
end
test 'department_manager_has_limited_access' do
......@@ -10,9 +10,9 @@ class GroupAssignmentPolicyTest < PolicyAssertions::Test
department_manager_group_assignment = create :group_assignment,
group_offer: create(:group_offer, creator: department_manager)
refute_permit(department_manager, GroupAssignment, *actions_list(:verify_termination))
assert_permit(department_manager, GroupAssignment, *actions_list(:terminated_index), 'comments?')
assert_permit(department_manager, GroupAssignment, *actions_list(:terminated_index), 'show_comments?')
assert_permit(department_manager, department_manager_group_assignment,
*actions_list(except: [:verify_termination, :terminated_index]), 'comments?')
*actions_list(except: [:verify_termination, :terminated_index]), 'show_comments?')
refute_permit(department_manager, create(:group_assignment),
*actions_list(
except: [:verify_termination, :terminated_index, :hours_and_feedbacks_submitted]
......@@ -20,14 +20,14 @@ class GroupAssignmentPolicyTest < PolicyAssertions::Test
end
test 'social_worker_has_no_access' do
refute_permit(create(:social_worker), GroupAssignment, *actions_list, 'comments?')
refute_permit(create(:social_worker), GroupAssignment, *actions_list, 'show_comments?')
end
test 'volunteer_has_limited_access' do
volunteer = create :volunteer_with_user
volunteer_group_assignment = create :group_assignment, volunteer: volunteer
refute_permit(volunteer.user, GroupAssignment,
'comments?', *actions_list(
'show_comments?', *actions_list(
:verify_termination, :terminated_index, :edit, :set_end_today, :update
))
assert_permit(volunteer.user, volunteer_group_assignment,
......@@ -36,7 +36,7 @@ class GroupAssignmentPolicyTest < PolicyAssertions::Test
:last_submitted_hours_and_feedbacks, :hours_and_feedbacks_submitted
))
refute_permit(volunteer.user, create(:group_assignment),
'comments?', *actions_list(
'show_comments?', *actions_list(
:terminate, :update_submitted_at, :show, :update_terminated_at,
:last_submitted_hours_and_feedbacks
))
......
Markdown is supported
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