Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
1
Merge Requests
1
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
nexedi
gitlab-ce
Commits
7454ad19
Commit
7454ad19
authored
Jun 24, 2014
by
Dmitriy Zaporozhets
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'at_mention_all_project_members' into 'master'
At mention all project and group members
parents
d52df8e7
4c575b72
Changes
5
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
102 additions
and
35 deletions
+102
-35
app/controllers/projects_controller.rb
app/controllers/projects_controller.rb
+2
-29
app/models/concerns/mentionable.rb
app/models/concerns/mentionable.rb
+8
-4
app/services/projects/participants_service.rb
app/services/projects/participants_service.rb
+43
-0
lib/gitlab/markdown.rb
lib/gitlab/markdown.rb
+5
-2
spec/services/notification_service_spec.rb
spec/services/notification_service_spec.rb
+44
-0
No files found.
app/controllers/projects_controller.rb
View file @
7454ad19
...
...
@@ -124,18 +124,12 @@ class ProjectsController < ApplicationController
def
autocomplete_sources
note_type
=
params
[
'type'
]
note_id
=
params
[
'type_id'
]
participating
=
if
note_type
&&
note_id
participants_in
(
note_type
,
note_id
)
else
[]
end
team_members
=
sorted
(
@project
.
team
.
members
)
participants
=
team_members
+
participating
participants
=
::
Projects
::
ParticipantsService
.
new
(
@project
).
execute
(
note_type
,
note_id
)
@suggestions
=
{
emojis:
Emoji
.
names
.
map
{
|
e
|
{
name:
e
,
path:
view_context
.
image_url
(
"emoji/
#{
e
}
.png"
)
}
},
issues:
@project
.
issues
.
select
([
:iid
,
:title
,
:description
]),
mergerequests:
@project
.
merge_requests
.
select
([
:iid
,
:title
,
:description
]),
members:
participants
.
uniq
members:
participants
}
respond_to
do
|
format
|
...
...
@@ -191,25 +185,4 @@ class ProjectsController < ApplicationController
def
user_layout
current_user
?
"projects"
:
"public_projects"
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
app/models/concerns/mentionable.rb
View file @
7454ad19
...
...
@@ -49,13 +49,17 @@ module Mentionable
matches
=
mentionable_text
.
scan
(
/@[a-zA-Z][a-zA-Z0-9_\-\.]*/
)
matches
.
each
do
|
match
|
identifier
=
match
.
delete
"@"
if
identifier
==
"all"
users
+=
project
.
team
.
members
.
flatten
else
if
has_project
id
=
project
.
team
.
members
.
find_by
(
username:
identifier
).
try
(
:id
)
else
id
=
User
.
where
(
username:
identifier
).
pluck
(
:id
).
first
id
=
User
.
find_by
(
username:
identifier
).
try
(
:id
)
end
users
<<
User
.
find
(
id
)
unless
id
.
blank?
end
end
users
.
uniq
end
...
...
app/services/projects/participants_service.rb
0 → 100644
View file @
7454ad19
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
lib/gitlab/markdown.rb
View file @
7454ad19
...
...
@@ -169,10 +169,13 @@ module Gitlab
end
def
reference_user
(
identifier
,
project
=
@project
)
if
user
=
User
.
find_by
(
username:
identifier
)
options
=
html_options
.
merge
(
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
)
end
end
...
...
spec/services/notification_service_spec.rb
View file @
7454ad19
...
...
@@ -95,6 +95,49 @@ describe NotificationService do
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
let
(
:note
)
{
create
(
:note_on_commit
)
}
...
...
@@ -312,6 +355,7 @@ describe NotificationService do
@u_disabled
=
create
(
:user
,
notification_level:
Notification
::
N_DISABLED
)
@u_mentioned
=
create
(
:user
,
username:
'mention'
,
notification_level:
Notification
::
N_PARTICIPATING
)
@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_participating
,
:master
]
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment