Skip to content

Commit

Permalink
fix: add new ability :show to PeopleManager
Browse files Browse the repository at this point in the history
  • Loading branch information
diegosteiner committed Oct 16, 2024
1 parent c8704b7 commit a40ce65
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 15 deletions.
19 changes: 17 additions & 2 deletions app/abilities/people_manager_ability.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
3 changes: 1 addition & 2 deletions app/views/event/participations/_people_managers.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -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
26 changes: 15 additions & 11 deletions app/views/person/managers/_list.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -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)

0 comments on commit a40ce65

Please sign in to comment.