Skip to content

Commit

Permalink
fix: add specs and fix linting (hitobito_jubla#78)
Browse files Browse the repository at this point in the history
  • Loading branch information
diegosteiner committed Dec 5, 2024
1 parent 8630116 commit 971b001
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 8 deletions.
13 changes: 6 additions & 7 deletions app/abilities/people_manager_ability.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion app/views/person/managers/_list.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
29 changes: 29 additions & 0 deletions spec/abilities/people_manager_ability_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 971b001

Please sign in to comment.