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
0
Merge Requests
0
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
iv
gitlab-ce
Commits
61824973
Commit
61824973
authored
Mar 28, 2013
by
Dmitriy Zaporozhets
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
rebuild notification on notes logic
parent
63e6f055
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
67 additions
and
16 deletions
+67
-16
app/services/notification_service.rb
app/services/notification_service.rb
+28
-16
spec/services/notification_service_spec.rb
spec/services/notification_service_spec.rb
+39
-0
No files found.
app/services/notification_service.rb
View file @
61824973
...
@@ -99,22 +99,34 @@ class NotificationService
...
@@ -99,22 +99,34 @@ class NotificationService
# TODO: split on methods and refactor
# TODO: split on methods and refactor
#
#
def
new_note
(
note
)
def
new_note
(
note
)
if
note
.
notify
# ignore wall messages
users
=
note
.
project
.
users
return
true
unless
note
.
noteable_type
.
present?
users
=
reject_muted_users
(
users
)
users
.
delete
(
note
.
author
)
# Note: wall posts are not "attached" to anything, so fall back to "Wall"
opts
=
{
noteable_type:
note
.
noteable_type
,
project_id:
note
.
project_id
}
noteable_type
=
note
.
noteable_type
.
presence
||
"Wall"
notify_method
=
"note_
#{
noteable_type
.
underscore
}
_email"
.
to_sym
if
Notify
.
respond_to?
notify_method
if
note
.
commit_id
users
.
each
do
|
user
|
opts
.
merge!
(
commit_id:
note
.
commit_id
)
Notify
.
delay
.
send
(
notify_method
,
user
.
id
,
note
.
id
)
else
opts
.
merge!
(
noteable_id:
note
.
noteable_id
)
end
end
end
elsif
note
.
notify_author
&&
note
.
commit_author
# Get users who left comment in thread
Notify
.
delay
.
note_commit_email
(
note
.
commit_author
.
id
,
note
.
id
)
recipients
=
User
.
where
(
id:
Note
.
where
(
opts
).
pluck
(
:author_id
))
# Merge project watchers
recipients
=
recipients
.
concat
(
project_watchers
(
note
.
project
)).
compact
.
uniq
# Reject mutes users
recipients
=
reject_muted_users
(
recipients
)
# Reject author
recipients
.
delete
(
note
.
author
)
# build notify method like 'note_commit_email'
notify_method
=
"note_
#{
note
.
noteable_type
.
underscore
}
_email"
.
to_sym
recipients
.
each
do
|
recipient
|
Notify
.
delay
.
send
(
notify_method
,
recipient
.
id
,
note
.
id
)
end
end
end
end
...
...
spec/services/notification_service_spec.rb
View file @
61824973
...
@@ -20,6 +20,45 @@ describe NotificationService do
...
@@ -20,6 +20,45 @@ describe NotificationService do
end
end
end
end
describe
'Notes'
do
let
(
:note
)
{
create
:note_on_commit
}
before
do
build_team
(
note
.
project
)
end
describe
:new_note
do
it
do
should_email
(
@u_watcher
.
id
)
should_not_email
(
note
.
author_id
)
should_not_email
(
@u_participating
.
id
)
should_not_email
(
@u_disabled
.
id
)
notification
.
new_note
(
note
)
end
it
do
create
(
:note_on_commit
,
author:
@u_participating
,
project_id:
note
.
project_id
,
commit_id:
note
.
commit_id
)
should_email
(
@u_watcher
.
id
)
should_email
(
@u_participating
.
id
)
should_not_email
(
note
.
author_id
)
should_not_email
(
@u_disabled
.
id
)
notification
.
new_note
(
note
)
end
def
should_email
(
user_id
)
Notify
.
should_receive
(
:note_commit_email
).
with
(
user_id
,
note
.
id
)
end
def
should_not_email
(
user_id
)
Notify
.
should_not_receive
(
:note_commit_email
).
with
(
user_id
,
note
.
id
)
end
end
end
describe
'Issues'
do
describe
'Issues'
do
let
(
:issue
)
{
create
:issue
,
assignee:
create
(
:user
)
}
let
(
:issue
)
{
create
:issue
,
assignee:
create
(
:user
)
}
...
...
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