diff options
Diffstat (limited to 'app/models/concerns/participable.rb')
-rw-r--r-- | app/models/concerns/participable.rb | 35 |
1 files changed, 29 insertions, 6 deletions
diff --git a/app/models/concerns/participable.rb b/app/models/concerns/participable.rb index af105629398..acd654bd229 100644 --- a/app/models/concerns/participable.rb +++ b/app/models/concerns/participable.rb @@ -56,18 +56,34 @@ module Participable # This method processes attributes of objects in breadth-first order. # # Returns an Array of User instances. - def participants(current_user = nil) - all_participants[current_user] + def participants(user = nil) + filtered_participants_hash[user] + end + + # Checks if the user is a participant in a discussion. + # + # This method processes attributes of objects in breadth-first order. + # + # Returns a Boolean. + def participant?(user) + can_read_participable?(user) && + all_participants_hash[user].include?(user) end private - def all_participants - @all_participants ||= Hash.new do |hash, user| + def all_participants_hash + @all_participants_hash ||= Hash.new do |hash, user| hash[user] = raw_participants(user) end end + def filtered_participants_hash + @filtered_participants_hash ||= Hash.new do |hash, user| + hash[user] = filter_by_ability(all_participants_hash[user]) + end + end + def raw_participants(current_user = nil) current_user ||= author ext = Gitlab::ReferenceExtractor.new(project, current_user) @@ -98,8 +114,6 @@ module Participable end participants.merge(ext.users) - - filter_by_ability(participants) end def filter_by_ability(participants) @@ -110,6 +124,15 @@ module Participable Ability.users_that_can_read_project(participants.to_a, project) end end + + def can_read_participable?(participant) + case self + when PersonalSnippet + participant.can?(:read_snippet, self) + else + participant.can?(:read_project, project) + end + end end Participable.prepend_if_ee('EE::Participable') |