diff options
Diffstat (limited to 'app/models/concerns/participable.rb')
-rw-r--r-- | app/models/concerns/participable.rb | 12 |
1 files changed, 11 insertions, 1 deletions
diff --git a/app/models/concerns/participable.rb b/app/models/concerns/participable.rb index 8130adf05f1..6035cb87c9b 100644 --- a/app/models/concerns/participable.rb +++ b/app/models/concerns/participable.rb @@ -152,7 +152,9 @@ module Participable end def source_visible_to_user?(source, user) - Ability.allowed?(user, "read_#{source.model_name.element}".to_sym, source) + ability = read_ability_for(source) + + Ability.allowed?(user, ability[:name], ability[:subject]) end def filter_by_ability(participants) @@ -172,6 +174,14 @@ module Participable participant.can?(:read_project, project) end end + + # Returns Hash containing ability name and subject needed to read a specific participable. + # Should be overridden if a different ability is required. + def read_ability_for(participable_source) + name = participable_source.try(:to_ability_name) || participable_source.model_name.element + + { name: "read_#{name}".to_sym, subject: participable_source } + end end Participable.prepend_mod_with('Participable') |