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
38f16582
Commit
38f16582
authored
Nov 01, 2016
by
Douglas Barbosa Alexandre
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Refactoring notification service to find subscriptions per project
parent
7fcd469e
Changes
2
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
92 additions
and
50 deletions
+92
-50
app/services/notification_service.rb
app/services/notification_service.rb
+13
-13
spec/services/notification_service_spec.rb
spec/services/notification_service_spec.rb
+79
-37
No files found.
app/services/notification_service.rb
View file @
38f16582
...
@@ -75,7 +75,7 @@ class NotificationService
...
@@ -75,7 +75,7 @@ class NotificationService
# * watchers of the issue's labels
# * watchers of the issue's labels
#
#
def
relabeled_issue
(
issue
,
added_labels
,
current_user
)
def
relabeled_issue
(
issue
,
added_labels
,
current_user
)
relabeled_resource_email
(
issue
,
added_labels
,
current_user
,
:relabeled_issue_email
)
relabeled_resource_email
(
issue
,
issue
.
project
,
added_labels
,
current_user
,
:relabeled_issue_email
)
end
end
# When create a merge request we should send an email to:
# When create a merge request we should send an email to:
...
@@ -118,7 +118,7 @@ class NotificationService
...
@@ -118,7 +118,7 @@ class NotificationService
# * watchers of the mr's labels
# * watchers of the mr's labels
#
#
def
relabeled_merge_request
(
merge_request
,
added_labels
,
current_user
)
def
relabeled_merge_request
(
merge_request
,
added_labels
,
current_user
)
relabeled_resource_email
(
merge_request
,
added_labels
,
current_user
,
:relabeled_merge_request_email
)
relabeled_resource_email
(
merge_request
,
merge_request
.
target_project
,
added_labels
,
current_user
,
:relabeled_merge_request_email
)
end
end
def
close_mr
(
merge_request
,
current_user
)
def
close_mr
(
merge_request
,
current_user
)
...
@@ -205,7 +205,7 @@ class NotificationService
...
@@ -205,7 +205,7 @@ class NotificationService
recipients
=
reject_muted_users
(
recipients
,
note
.
project
)
recipients
=
reject_muted_users
(
recipients
,
note
.
project
)
recipients
=
add_subscribed_users
(
recipients
,
note
.
noteable
)
recipients
=
add_subscribed_users
(
recipients
,
note
.
project
,
note
.
noteable
)
recipients
=
reject_unsubscribed_users
(
recipients
,
note
.
noteable
)
recipients
=
reject_unsubscribed_users
(
recipients
,
note
.
noteable
)
recipients
=
reject_users_without_access
(
recipients
,
note
.
noteable
)
recipients
=
reject_users_without_access
(
recipients
,
note
.
noteable
)
...
@@ -505,17 +505,17 @@ class NotificationService
...
@@ -505,17 +505,17 @@ class NotificationService
end
end
end
end
def
add_subscribed_users
(
recipients
,
target
)
def
add_subscribed_users
(
recipients
,
project
,
target
)
return
recipients
unless
target
.
respond_to?
:subscribers
return
recipients
unless
target
.
respond_to?
:subscribers
recipients
+
target
.
subscribers
recipients
+
target
.
subscribers
(
project
)
end
end
def
add_labels_subscribers
(
recipients
,
target
,
labels:
nil
)
def
add_labels_subscribers
(
recipients
,
project
,
target
,
labels:
nil
)
return
recipients
unless
target
.
respond_to?
:labels
return
recipients
unless
target
.
respond_to?
:labels
(
labels
||
target
.
labels
).
each
do
|
label
|
(
labels
||
target
.
labels
).
each
do
|
label
|
recipients
+=
label
.
subscribers
recipients
+=
label
.
subscribers
(
project
)
end
end
recipients
recipients
...
@@ -571,8 +571,8 @@ class NotificationService
...
@@ -571,8 +571,8 @@ class NotificationService
end
end
end
end
def
relabeled_resource_email
(
target
,
labels
,
current_user
,
method
)
def
relabeled_resource_email
(
target
,
project
,
labels
,
current_user
,
method
)
recipients
=
build_relabeled_recipients
(
target
,
current_user
,
labels:
labels
)
recipients
=
build_relabeled_recipients
(
target
,
project
,
current_user
,
labels:
labels
)
label_names
=
labels
.
map
(
&
:name
)
label_names
=
labels
.
map
(
&
:name
)
recipients
.
each
do
|
recipient
|
recipients
.
each
do
|
recipient
|
...
@@ -608,10 +608,10 @@ class NotificationService
...
@@ -608,10 +608,10 @@ class NotificationService
end
end
recipients
=
reject_muted_users
(
recipients
,
project
)
recipients
=
reject_muted_users
(
recipients
,
project
)
recipients
=
add_subscribed_users
(
recipients
,
target
)
recipients
=
add_subscribed_users
(
recipients
,
project
,
target
)
if
[
:new_issue
,
:new_merge_request
].
include?
(
custom_action
)
if
[
:new_issue
,
:new_merge_request
].
include?
(
custom_action
)
recipients
=
add_labels_subscribers
(
recipients
,
target
)
recipients
=
add_labels_subscribers
(
recipients
,
project
,
target
)
end
end
recipients
=
reject_unsubscribed_users
(
recipients
,
target
)
recipients
=
reject_unsubscribed_users
(
recipients
,
target
)
...
@@ -622,8 +622,8 @@ class NotificationService
...
@@ -622,8 +622,8 @@ class NotificationService
recipients
.
uniq
recipients
.
uniq
end
end
def
build_relabeled_recipients
(
target
,
current_user
,
labels
:)
def
build_relabeled_recipients
(
target
,
project
,
current_user
,
labels
:)
recipients
=
add_labels_subscribers
([],
target
,
labels:
labels
)
recipients
=
add_labels_subscribers
([],
project
,
target
,
labels:
labels
)
recipients
=
reject_unsubscribed_users
(
recipients
,
target
)
recipients
=
reject_unsubscribed_users
(
recipients
,
target
)
recipients
=
reject_users_without_access
(
recipients
,
target
)
recipients
=
reject_users_without_access
(
recipients
,
target
)
recipients
.
delete
(
current_user
)
recipients
.
delete
(
current_user
)
...
...
spec/services/notification_service_spec.rb
View file @
38f16582
This diff is collapsed.
Click to expand it.
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