diff --git a/app/abilities/people_manager_ability.rb b/app/abilities/people_manager_ability.rb index 1956d88..1cc6536 100644 --- a/app/abilities/people_manager_ability.rb +++ b/app/abilities/people_manager_ability.rb @@ -11,20 +11,35 @@ class PeopleManagerAbility < AbilityDsl::Base permission(:any).may(:new_managed, :new_manager).everybody permission(:any).may(:create_managed, :destroy_managed).if_can_change_managed permission(:any).may(:create_manager, :destroy_manager).if_can_change_manager + permission(:any).may(:show).for_leaded_events + permission(:any).may(:show).for_readable_manageds end def if_can_change_manager - can?(:change_managers, subject.managed) || creating_new_managed_person? + can?(:change_managers, managed) || creating_new_managed_person? end def if_can_change_managed can?(:update, subject.manager) end + def for_leaded_events + leaded_event_ids = user_context.events_with_permission(:event_full) + managed&.event_participations.exists?(event_id: leaded_event_ids) + end + + def for_readable_manageds + can?(:show, managed) + end + private + def managed + subject.managed + end + def creating_new_managed_person? - subject.managed&.new_record? && + managed&.new_record? && FeatureGate.enabled?("people.people_managers.self_service_managed_creation") end diff --git a/app/views/event/participations/_people_managers.html.haml b/app/views/event/participations/_people_managers.html.haml index 5c76151..d27f520 100644 --- a/app/views/event/participations/_people_managers.html.haml +++ b/app/views/event/participations/_people_managers.html.haml @@ -5,8 +5,7 @@ - # or later. See the COPYING file at the top-level directory or at - # https://github.com/hitobito/hitobito. - - FeatureGate.if('people.people_managers') do - if entry.person.people_managers.any? %section - = render 'person/managers/list', person: entry.person + = render 'person/managers/list', person: entry.person, readonly: true diff --git a/app/views/person/managers/_list.html.haml b/app/views/person/managers/_list.html.haml index 80c5a80..23a2c0d 100644 --- a/app/views/person/managers/_list.html.haml +++ b/app/views/person/managers/_list.html.haml @@ -3,19 +3,23 @@ - # or later. See the COPYING file at the top-level directory or at - # https://github.com/hitobito/hitobito_youth. +- readonly = defined?(readonly) && readonly - content_for(:section_header) do = t('people_managers.managers_heading') - %span.float-end - = Dropdown::AddPeopleManager.new(self, person).to_s -= render layout: 'people_managers/section', locals: { list: person.people_managers } do + - if !readonly + %span.float-end + = Dropdown::AddPeopleManager.new(self, person).to_s + += render layout: 'people_managers/section', locals: { readonly: readonly } do - person.people_managers.each do |item| - %tr - %td - %strong= link_to_if(can?(:show, item.manager), item.manager, item.manager, data: { turbo_frame: :_top }) - %div.d-flex.gap-2 - = mail_to(item.email) - = phone_to(item.phone_number.number, item.phone_number) if item.phone_number.present? + - if can?(:show, item) + %tr + %td + %strong= link_to_if(can?(:show, item.manager), item.manager, item.manager, data: { turbo_frame: :_top }) + %div.d-flex.gap-2 + = mail_to(item.email) + = phone_to(item.phone_number.number, item.phone_number) if item.phone_number.present? - - if can?(:destroy_manager, item) - %td=render 'people_managers/delete_link', path: person_manager_path(person_id: person.id, id: item.id) + - if !readonly && can?(:destroy_manager, item) + %td=render 'people_managers/delete_link', path: person_manager_path(person_id: person.id, id: item.id)