diff --git a/app/abilities/people_manager_ability.rb b/app/abilities/people_manager_ability.rb index 1cc6536..66db36a 100644 --- a/app/abilities/people_manager_ability.rb +++ b/app/abilities/people_manager_ability.rb @@ -11,8 +11,7 @@ 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 + permission(:any).may(:show).for_leaded_events_or_readable_manageds end def if_can_change_manager @@ -23,13 +22,13 @@ 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) + def for_leaded_events_or_readable_manageds + for_leaded_events || can?(:show, managed) end - def for_readable_manageds - can?(:show, managed) + def for_leaded_events + leaded_event_ids = user_context.events_with_permission(:event_full) + managed&.event_participations&.exists?(event_id: leaded_event_ids) end private diff --git a/app/views/person/managers/_list.html.haml b/app/views/person/managers/_list.html.haml index 23a2c0d..4217470 100644 --- a/app/views/person/managers/_list.html.haml +++ b/app/views/person/managers/_list.html.haml @@ -11,7 +11,7 @@ %span.float-end = Dropdown::AddPeopleManager.new(self, person).to_s -= render layout: 'people_managers/section', locals: { readonly: readonly } do += render layout: 'people_managers/section', locals: { readonly: readonly, list: person.people_managers } do - person.people_managers.each do |item| - if can?(:show, item) %tr diff --git a/spec/abilities/people_manager_ability_spec.rb b/spec/abilities/people_manager_ability_spec.rb index 9a55ae0..1ec051b 100644 --- a/spec/abilities/people_manager_ability_spec.rb +++ b/spec/abilities/people_manager_ability_spec.rb @@ -18,6 +18,35 @@ def build(managed: nil, manager: nil) PeopleManager.new(managed: managed, manager: manager) end + describe :show do + let(:person) { Fabricate(:person) } + let(:manager) { Fabricate(:person) } + let(:managed) { bottom_member } + let(:people_manager) { build(managed: managed, manager: manager) } + + context 'with no relation' do + it { is_expected.not_to be_able_to(:show, people_manager) } + end + + context 'with leader role on participation event' do + let(:event) { events(:top_event) } + before do + roles = { person => Event::Role::Leader, people_manager.managed => Event::Role::Participant } + x = roles.map do |person, role| + Fabricate(role.name, participation: Fabricate(:event_participation, event: event, person: person)) + end + people_manager.save + people_manager.reload + end + it { is_expected.to be_able_to(:show, people_manager) } + end + + context 'with layer permissions' do + let(:person) { top_leader } + it { is_expected.to be_able_to(:show, people_manager) } + end + end + [:create_manager, :destroy_manager].each do |action| context 'top leader' do