summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDouwe Maan <douwe@gitlab.com>2015-02-04 17:10:39 +0100
committerDouwe Maan <douwe@gitlab.com>2015-02-05 19:10:52 +0100
commit9910b7ff99c3d7f89f512c1915ce40ed0c1696e3 (patch)
tree8c1bde789456fd191afd928172174f6516f032b3
parent56a456b43dba7d772db45e2b73aa18b5eab53d37 (diff)
downloadgitlab-ce-9910b7ff99c3d7f89f512c1915ce40ed0c1696e3.tar.gz
Allow groups to be mentioned.
Resolves #1673.
-rw-r--r--app/controllers/projects_controller.rb2
-rw-r--r--app/models/concerns/mentionable.rb9
-rw-r--r--app/services/projects/participants_service.rb11
-rw-r--r--doc/markdown/markdown.md2
-rw-r--r--lib/gitlab/markdown.rb11
5 files changed, 25 insertions, 10 deletions
diff --git a/app/controllers/projects_controller.rb b/app/controllers/projects_controller.rb
index ebe48265c63..462ab3d4749 100644
--- a/app/controllers/projects_controller.rb
+++ b/app/controllers/projects_controller.rb
@@ -102,7 +102,7 @@ class ProjectsController < ApplicationController
note_type = params['type']
note_id = params['type_id']
autocomplete = ::Projects::AutocompleteService.new(@project)
- participants = ::Projects::ParticipantsService.new(@project).execute(note_type, note_id)
+ participants = ::Projects::ParticipantsService.new(@project, current_user).execute(note_type, note_id)
@suggestions = {
emojis: autocomplete_emojis,
diff --git a/app/models/concerns/mentionable.rb b/app/models/concerns/mentionable.rb
index 66f83b932d4..d640728519a 100644
--- a/app/models/concerns/mentionable.rb
+++ b/app/models/concerns/mentionable.rb
@@ -51,9 +51,12 @@ module Mentionable
identifier = match.delete "@"
if identifier == "all"
users.push(*project.team.members.flatten)
- else
- id = User.find_by(username: identifier).try(:id)
- users << User.find(id) unless id.blank?
+ elsif namespace = Namespace.find_by(path: identifier)
+ if namespace.type == "Group"
+ users.push(*namespace.users)
+ else
+ users << namespace.owner
+ end
end
end
users.uniq
diff --git a/app/services/projects/participants_service.rb b/app/services/projects/participants_service.rb
index e3b33de8d02..0be50fed7cc 100644
--- a/app/services/projects/participants_service.rb
+++ b/app/services/projects/participants_service.rb
@@ -1,7 +1,8 @@
module Projects
class ParticipantsService < BaseService
- def initialize(project)
- @project = project
+ def initialize(project, user)
+ @project = project
+ @user = user
end
def execute(note_type, note_id)
@@ -12,7 +13,7 @@ module Projects
[]
end
team_members = sorted(@project.team.members)
- participants = all_members + team_members + participating
+ participants = all_members + groups + team_members + participating
participants.uniq
end
@@ -37,6 +38,10 @@ module Projects
users.uniq.to_a.compact.sort_by(&:username).map { |user| { username: user.username, name: user.name } }
end
+ def groups
+ @user.authorized_groups.sort_by(&:path).map { |group| { username: group.path, name: group.name } }
+ end
+
def all_members
[{ username: "all", name: "Project and Group Members" }]
end
diff --git a/doc/markdown/markdown.md b/doc/markdown/markdown.md
index 7b79cd5d98b..b9b9ca17678 100644
--- a/doc/markdown/markdown.md
+++ b/doc/markdown/markdown.md
@@ -170,7 +170,7 @@ GFM will turn that reference into a link so you can navigate between them easily
GFM will recognize the following:
-- @foo : for team members
+- @foo : for specific team members or groups
- @all : for the whole team
- #123 : for issues
- !123 : for merge requests
diff --git a/lib/gitlab/markdown.rb b/lib/gitlab/markdown.rb
index c0e83fb3078..78627f413c2 100644
--- a/lib/gitlab/markdown.rb
+++ b/lib/gitlab/markdown.rb
@@ -202,8 +202,15 @@ module Gitlab
if identifier == "all"
link_to("@all", project_url(project), options)
- elsif User.find_by(username: identifier)
- link_to("@#{identifier}", user_url(identifier), options)
+ elsif namespace = Namespace.find_by(path: identifier)
+ url =
+ if namespace.type == "Group"
+ group_url(identifier)
+ else
+ user_url(identifier)
+ end
+
+ link_to("@#{identifier}", url, options)
end
end