Refactor Mentionable mentioned users to use ReferenceExtractor.
This commit is contained in:
parent
ca58e369c9
commit
d2bd606759
|
@ -43,28 +43,17 @@ module Mentionable
|
||||||
end
|
end
|
||||||
|
|
||||||
def mentioned_users
|
def mentioned_users
|
||||||
users = []
|
return [] if mentionable_text.blank?
|
||||||
return users if mentionable_text.blank?
|
|
||||||
has_project = self.respond_to? :project
|
ext = Gitlab::ReferenceExtractor.new(self.project)
|
||||||
matches = mentionable_text.scan(/@[a-zA-Z][a-zA-Z0-9_\-\.]*/)
|
ext.analyze(text)
|
||||||
matches.each do |match|
|
ext.users.uniq
|
||||||
identifier = match.delete "@"
|
|
||||||
if identifier == "all"
|
|
||||||
users.push(*project.team.members.flatten)
|
|
||||||
elsif namespace = Namespace.find_by(path: identifier)
|
|
||||||
if namespace.is_a?(Group)
|
|
||||||
users.push(*namespace.users)
|
|
||||||
else
|
|
||||||
users << namespace.owner
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
users.uniq
|
|
||||||
end
|
end
|
||||||
|
|
||||||
# Extract GFM references to other Mentionables from this Mentionable. Always excludes its #local_reference.
|
# Extract GFM references to other Mentionables from this Mentionable. Always excludes its #local_reference.
|
||||||
def references(p = project, text = mentionable_text)
|
def references(p = project, text = mentionable_text)
|
||||||
return [] if text.blank?
|
return [] if text.blank?
|
||||||
|
|
||||||
ext = Gitlab::ReferenceExtractor.new(p)
|
ext = Gitlab::ReferenceExtractor.new(p)
|
||||||
ext.analyze(text)
|
ext.analyze(text)
|
||||||
|
|
||||||
|
|
|
@ -34,8 +34,16 @@ module Gitlab
|
||||||
|
|
||||||
def users
|
def users
|
||||||
references[:users].map do |entry|
|
references[:users].map do |entry|
|
||||||
project.users.where(username: entry[:id]).first
|
if entry[:id] == "all"
|
||||||
end.compact
|
project.team.members.flatten
|
||||||
|
elsif namespace = Namespace.find_by(path: entry[:id])
|
||||||
|
if namespace.is_a?(Group)
|
||||||
|
namespace.users
|
||||||
|
else
|
||||||
|
namespace.owner
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end.flatten.compact
|
||||||
end
|
end
|
||||||
|
|
||||||
def labels
|
def labels
|
||||||
|
|
Loading…
Reference in New Issue