Skip to content

Commit

Permalink
Add fallback option to punctually check abilities without inheriting …
Browse files Browse the repository at this point in the history
…from manageds

Refs hitobito/hitobito#1967
  • Loading branch information
carlobeltrame committed Apr 14, 2023
1 parent a41015e commit 299684f
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
20 changes: 20 additions & 0 deletions app/abilities/ability_without_manager_abilities.rb
@@ -0,0 +1,20 @@
# frozen_string_literal: true

# 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.

# Most of the time, managers inherit a fixed list of abilities from their manageds.
# But sometimes, we need to check whether the manager would be allowed something
# even if they weren't a manager. In the youth wagon, we override the default
# ability class to take the inherited abilities into account. This ability class here
# allows us to revert back to the core behaviour in the few places where we need it.
class AbilityWithoutManagerAbilities < Ability

private

def define_user_abilities(current_store, current_user_context)
super(current_store, current_user_context, false)
end
end
3 changes: 2 additions & 1 deletion app/abilities/youth/ability.rb
Expand Up @@ -22,8 +22,9 @@ module Youth::Ability

private

def define_user_abilities(current_store, current_user_context)
def define_user_abilities(current_store, current_user_context, include_manageds = true)
super
return unless include_manageds

user.manageds.each do |managed|
managed_user_context = AbilityDsl::UserContext.new(managed)
Expand Down

0 comments on commit 299684f

Please sign in to comment.