Skip to content

Commit

Permalink
Allow managers to create and manage event participations of their man…
Browse files Browse the repository at this point in the history
…ageds

Most of the changes here can use the new for_self_or_manageds mechanism.
But when a condition combines her_own_or_something_else, then we must
manually add the manager option, to make sure that the manager only
inherits the her_own part, not the something_else part.

Refs hitobito/hitobito#1967
  • Loading branch information
carlobeltrame committed Apr 14, 2023
1 parent 299684f commit 1d5fb9a
Show file tree
Hide file tree
Showing 5 changed files with 93 additions and 2 deletions.
19 changes: 19 additions & 0 deletions app/abilities/youth/event/application_ability.rb
@@ -0,0 +1,19 @@
# encoding: utf-8

# Copyright (c) 2023, Pfadibewegung Schweiz. This file is part of
# hitobito_youth and licensed under the Affero General Public License version 3
# or later. See the COPYING file at the top-level directory or at
# https://github.com/hitobito/hitobito_youth.

module Youth::Event::ApplicationAbility
extend ActiveSupport::Concern

included do
on(Event::Application) do
for_self_or_manageds do
# abilities which managers inherit from their managed children
permission(:any).may(:show_priorities, :show_approval).her_own
end
end
end
end
19 changes: 19 additions & 0 deletions app/abilities/youth/event/invitation_ability.rb
@@ -0,0 +1,19 @@
# encoding: utf-8

# Copyright (c) 2023, Pfadibewegung Schweiz. This file is part of
# hitobito_youth and licensed under the Affero General Public License version 3
# or later. See the COPYING file at the top-level directory or at
# https://github.com/hitobito/hitobito_youth.

module Youth::Event::InvitationAbility
extend ActiveSupport::Concern

included do
on(Event::Invitation) do
for_self_or_manageds do
# abilities which managers inherit from their managed children
permission(:any).may(:decline).own_invitation
end
end
end
end
29 changes: 28 additions & 1 deletion app/abilities/youth/event/participation_ability.rb
@@ -1,6 +1,6 @@
# encoding: utf-8

# Copyright (c) 2012-2014, Pfadibewegung Schweiz. This file is part of
# Copyright (c) 2012-2023, Pfadibewegung Schweiz. This file is part of
# hitobito_youth and licensed under the Affero General Public License version 3
# or later. See the COPYING file at the top-level directory or at
# https://github.com/hitobito/hitobito_youth.
Expand All @@ -10,6 +10,16 @@ module Youth::Event::ParticipationAbility

included do
on(Event::Participation) do
# abilities which managers inherit from their managed children
permission(:any).may(:show).her_own_or_manager_or_for_participations_read_events
permission(:any).may(:show_details, :print).
her_own_or_manager_or_for_participations_full_events
for_self_or_manageds do
permission(:any).may(:create).her_own_if_application_possible
permission(:any).may(:destroy).her_own_if_application_cancelable
general(:create).at_least_one_group_not_deleted
end

permission(:any).may(:cancel, :absent, :assign, :attend).for_participations_full_events
permission(:group_full).may(:cancel, :reject, :absent, :assign, :attend).in_same_group
permission(:group_and_below_full).
Expand All @@ -26,6 +36,14 @@ module Youth::Event::ParticipationAbility
end
end

def her_own_or_manager_or_for_participations_read_events
her_own_or_for_participations_read_events || manager
end

def her_own_or_manager_or_for_participations_full_events
her_own_or_for_participations_full_events || manager
end

def person_in_same_layer
person.nil? || permission_in_layers?(person.layer_group_ids)
end
Expand All @@ -45,8 +63,17 @@ def if_application
event.supports_applications && participation.application_id?
end

def participant_can_show_event?
participation.person &&
(AbilityWithoutManagerAbilities.new(participation.person).can? :show, participation.event)
end

private

def manager
contains_any?([user.id], person.managers.pluck(:id))
end

def event
participation.event
end
Expand Down
19 changes: 19 additions & 0 deletions app/abilities/youth/event/participation_contact_data_ability.rb
@@ -0,0 +1,19 @@
# encoding: utf-8

# Copyright (c) 2023, Pfadibewegung Schweiz. This file is part of
# hitobito_youth and licensed under the Affero General Public License version 3
# or later. See the COPYING file at the top-level directory or at
# https://github.com/hitobito/hitobito_youth.

module Youth::Event::ParticipationContactDataAbility
extend ActiveSupport::Concern

included do
on(Event::ParticipationContactData) do
for_self_or_manageds do
# abilities which managers inherit from their managed children
permission(:any).may(:show, :update).her_own
end
end
end
end
9 changes: 8 additions & 1 deletion app/abilities/youth/event_ability.rb
@@ -1,6 +1,6 @@
# encoding: utf-8

# Copyright (c) 2012-2014, Pfadibewegung Schweiz. This file is part of
# Copyright (c) 2012-2023, Pfadibewegung Schweiz. This file is part of
# hitobito_youth and licensed under the Affero General Public License version 3
# or later. See the COPYING file at the top-level directory or at
# https://github.com/hitobito/hitobito_youth.
Expand All @@ -10,6 +10,13 @@ module Youth::EventAbility

included do
on(Event::Course) do

for_self_or_manageds do
# abilities which managers inherit from their managed children
class_side(:list_available).if_any_role
permission(:any).may(:show).in_same_layer_or_globally_visible_or_participating
end

permission(:any).
may(:index_revoked_participations, :list_tentatives).
for_participations_full_events
Expand Down

0 comments on commit 1d5fb9a

Please sign in to comment.