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 ...@@ -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 ...@@ -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
......
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