Commit d2bd6067 authored by Douwe Maan's avatar Douwe Maan

Refactor Mentionable mentioned users to use ReferenceExtractor.

parent ca58e369
......@@ -43,28 +43,17 @@ module Mentionable
end
def mentioned_users
users = []
return users if mentionable_text.blank?
has_project = self.respond_to? :project
matches = mentionable_text.scan(/@[a-zA-Z][a-zA-Z0-9_\-\.]*/)
matches.each do |match|
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
return [] if mentionable_text.blank?
ext = Gitlab::ReferenceExtractor.new(self.project)
ext.analyze(text)
ext.users.uniq
end
# Extract GFM references to other Mentionables from this Mentionable. Always excludes its #local_reference.
def references(p = project, text = mentionable_text)
return [] if text.blank?
ext = Gitlab::ReferenceExtractor.new(p)
ext.analyze(text)
......
......@@ -34,8 +34,16 @@ module Gitlab
def users
references[:users].map do |entry|
project.users.where(username: entry[:id]).first
end.compact
if entry[:id] == "all"
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
def labels
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment