Commit 7454ad19 authored by Dmitriy Zaporozhets's avatar Dmitriy Zaporozhets

Merge branch 'at_mention_all_project_members' into 'master'

At mention all project and group members
parents d52df8e7 4c575b72
...@@ -124,18 +124,12 @@ class ProjectsController < ApplicationController ...@@ -124,18 +124,12 @@ class ProjectsController < ApplicationController
def autocomplete_sources def autocomplete_sources
note_type = params['type'] note_type = params['type']
note_id = params['type_id'] note_id = params['type_id']
participating = if note_type && note_id participants = ::Projects::ParticipantsService.new(@project).execute(note_type, note_id)
participants_in(note_type, note_id)
else
[]
end
team_members = sorted(@project.team.members)
participants = team_members + participating
@suggestions = { @suggestions = {
emojis: Emoji.names.map { |e| { name: e, path: view_context.image_url("emoji/#{e}.png") } }, emojis: Emoji.names.map { |e| { name: e, path: view_context.image_url("emoji/#{e}.png") } },
issues: @project.issues.select([:iid, :title, :description]), issues: @project.issues.select([:iid, :title, :description]),
mergerequests: @project.merge_requests.select([:iid, :title, :description]), mergerequests: @project.merge_requests.select([:iid, :title, :description]),
members: participants.uniq members: participants
} }
respond_to do |format| respond_to do |format|
...@@ -191,25 +185,4 @@ class ProjectsController < ApplicationController ...@@ -191,25 +185,4 @@ class ProjectsController < ApplicationController
def user_layout def user_layout
current_user ? "projects" : "public_projects" current_user ? "projects" : "public_projects"
end end
def participants_in(type, id)
users = case type
when "Issue"
issue = @project.issues.find_by_iid(id)
issue ? issue.participants : []
when "MergeRequest"
merge_request = @project.merge_requests.find_by_iid(id)
merge_request ? merge_request.participants : []
when "Commit"
author_ids = Note.for_commit_id(id).pluck(:author_id).uniq
User.where(id: author_ids)
else
[]
end
sorted(users)
end
def sorted(users)
users.uniq.to_a.compact.sort_by(&:username).map { |user| { username: user.username, name: user.name } }
end
end end
...@@ -49,13 +49,17 @@ module Mentionable ...@@ -49,13 +49,17 @@ module Mentionable
matches = mentionable_text.scan(/@[a-zA-Z][a-zA-Z0-9_\-\.]*/) matches = mentionable_text.scan(/@[a-zA-Z][a-zA-Z0-9_\-\.]*/)
matches.each do |match| matches.each do |match|
identifier = match.delete "@" identifier = match.delete "@"
if identifier == "all"
users += project.team.members.flatten
else
if has_project if has_project
id = project.team.members.find_by(username: identifier).try(:id) id = project.team.members.find_by(username: identifier).try(:id)
else else
id = User.where(username: identifier).pluck(:id).first id = User.find_by(username: identifier).try(:id)
end end
users << User.find(id) unless id.blank? users << User.find(id) unless id.blank?
end end
end
users.uniq users.uniq
end end
......
module Projects
class ParticipantsService < BaseService
def initialize(project)
@project = project
end
def execute(note_type, note_id)
participating = if note_type && note_id
participants_in(note_type, note_id)
else
[]
end
team_members = sorted(@project.team.members)
participants = all_members + team_members + participating
participants.uniq
end
def participants_in(type, id)
users = case type
when "Issue"
issue = @project.issues.find_by_iid(id)
issue ? issue.participants : []
when "MergeRequest"
merge_request = @project.merge_requests.find_by_iid(id)
merge_request ? merge_request.participants : []
when "Commit"
author_ids = Note.for_commit_id(id).pluck(:author_id).uniq
User.where(id: author_ids)
else
[]
end
sorted(users)
end
def sorted(users)
users.uniq.to_a.compact.sort_by(&:username).map { |user| { username: user.username, name: user.name } }
end
def all_members
[{ username: "all", name: "Project and Group Members" }]
end
end
end
...@@ -169,10 +169,13 @@ module Gitlab ...@@ -169,10 +169,13 @@ module Gitlab
end end
def reference_user(identifier, project = @project) def reference_user(identifier, project = @project)
if user = User.find_by(username: identifier)
options = html_options.merge( options = html_options.merge(
class: "gfm gfm-team_member #{html_options[:class]}" class: "gfm gfm-team_member #{html_options[:class]}"
) )
if identifier == "all"
link_to("@all", project_url(project), options)
elsif user = User.find_by(username: identifier)
link_to("@#{identifier}", user_url(identifier), options) link_to("@#{identifier}", user_url(identifier), options)
end end
end end
......
...@@ -95,6 +95,49 @@ describe NotificationService do ...@@ -95,6 +95,49 @@ describe NotificationService do
end end
end end
context 'issue note mention' do
let(:issue) { create(:issue, assignee: create(:user)) }
let(:mentioned_issue) { create(:issue, assignee: issue.assignee) }
let(:note) { create(:note_on_issue, noteable: issue, project_id: issue.project_id, note: '@all mentioned') }
before do
build_team(note.project)
end
describe :new_note do
it do
# Notify all team members
note.project.team.members.each do |member|
# User with disabled notification should not be notified
next if member.id == @u_disabled.id
should_email(member.id)
end
should_email(note.noteable.author_id)
should_email(note.noteable.assignee_id)
should_not_email(note.author_id)
should_not_email(@u_disabled.id)
should_not_email(@u_not_mentioned.id)
notification.new_note(note)
end
it 'filters out "mentioned in" notes' do
mentioned_note = Note.create_cross_reference_note(mentioned_issue, issue, issue.author, issue.project)
Notify.should_not_receive(:note_issue_email)
notification.new_note(mentioned_note)
end
end
def should_email(user_id)
Notify.should_receive(:note_issue_email).with(user_id, note.id)
end
def should_not_email(user_id)
Notify.should_not_receive(:note_issue_email).with(user_id, note.id)
end
end
context 'commit note' do context 'commit note' do
let(:note) { create(:note_on_commit) } let(:note) { create(:note_on_commit) }
...@@ -312,6 +355,7 @@ describe NotificationService do ...@@ -312,6 +355,7 @@ describe NotificationService do
@u_disabled = create(:user, notification_level: Notification::N_DISABLED) @u_disabled = create(:user, notification_level: Notification::N_DISABLED)
@u_mentioned = create(:user, username: 'mention', notification_level: Notification::N_PARTICIPATING) @u_mentioned = create(:user, username: 'mention', notification_level: Notification::N_PARTICIPATING)
@u_committer = create(:user, username: 'committer') @u_committer = create(:user, username: 'committer')
@u_not_mentioned = create(:user, username: 'regular', notification_level: Notification::N_PARTICIPATING)
project.team << [@u_watcher, :master] project.team << [@u_watcher, :master]
project.team << [@u_participating, :master] project.team << [@u_participating, :master]
......
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