Refactor Mentionable mentioned users to use ReferenceExtractor.

This commit is contained in:
Douwe Maan 2015-03-27 11:45:06 +01:00
parent ca58e369c9
commit d2bd606759
2 changed files with 16 additions and 19 deletions

View File

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

View File

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