summaryrefslogtreecommitdiff
path: root/app/models/concerns/participable.rb
diff options
context:
space:
mode:
Diffstat (limited to 'app/models/concerns/participable.rb')
-rw-r--r--app/models/concerns/participable.rb32
1 files changed, 19 insertions, 13 deletions
diff --git a/app/models/concerns/participable.rb b/app/models/concerns/participable.rb
index ffc874357fd..85367f89f4f 100644
--- a/app/models/concerns/participable.rb
+++ b/app/models/concerns/participable.rb
@@ -12,7 +12,7 @@
#
# # ...
#
-# participant :author, :assignee, :mentioned_users, :notes
+# participant :author, :assignee, :notes, ->(current_user) { mentioned_users(current_user) }
# end
#
# issue = Issue.last
@@ -27,7 +27,7 @@ module Participable
module ClassMethods
def participant(*attrs)
- participant_attrs.concat(attrs.map(&:to_s))
+ participant_attrs.concat(attrs)
end
def participant_attrs
@@ -37,33 +37,39 @@ module Participable
# Be aware that this method makes a lot of sql queries.
# Save result into variable if you are going to reuse it inside same request
- def participants(current_user = self.author)
- self.class.participant_attrs.flat_map do |attr|
- meth = method(attr)
-
+ def participants(current_user = self.author, load_lazy_references: true)
+ participants = self.class.participant_attrs.flat_map do |attr|
value =
- if meth.arity == 1 || meth.arity == -1
- meth.call(current_user)
+ if attr.respond_to?(:call)
+ instance_exec(current_user, &attr)
else
- meth.call
+ send(attr)
end
participants_for(value, current_user)
- end.compact.uniq.select do |user|
- user.can?(:read_project, self.project)
+ end.compact.uniq
+
+ if load_lazy_references
+ participants = Gitlab::Markdown::ReferenceFilter::LazyReference.load(participants).uniq
+
+ participants.select! do |user|
+ user.can?(:read_project, project)
+ end
end
+
+ participants
end
private
def participants_for(value, current_user = nil)
case value
- when User
+ when User, Gitlab::Markdown::ReferenceFilter::LazyReference
[value]
when Enumerable, ActiveRecord::Relation
value.flat_map { |v| participants_for(v, current_user) }
when Participable
- value.participants(current_user)
+ value.participants(current_user, load_lazy_references: false)
end
end
end