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
Jérome Perrin
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
# * watchers of the issue's labels
#
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
# When create a merge request we should send an email to:
...
...
@@ -118,7 +118,7 @@ class NotificationService
# * watchers of the mr's labels
#
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
def
close_mr
(
merge_request
,
current_user
)
...
...
@@ -205,7 +205,7 @@ class NotificationService
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_users_without_access
(
recipients
,
note
.
noteable
)
...
...
@@ -505,17 +505,17 @@ class NotificationService
end
end
def
add_subscribed_users
(
recipients
,
target
)
def
add_subscribed_users
(
recipients
,
project
,
target
)
return
recipients
unless
target
.
respond_to?
:subscribers
recipients
+
target
.
subscribers
recipients
+
target
.
subscribers
(
project
)
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
(
labels
||
target
.
labels
).
each
do
|
label
|
recipients
+=
label
.
subscribers
recipients
+=
label
.
subscribers
(
project
)
end
recipients
...
...
@@ -571,8 +571,8 @@ class NotificationService
end
end
def
relabeled_resource_email
(
target
,
labels
,
current_user
,
method
)
recipients
=
build_relabeled_recipients
(
target
,
current_user
,
labels:
labels
)
def
relabeled_resource_email
(
target
,
project
,
labels
,
current_user
,
method
)
recipients
=
build_relabeled_recipients
(
target
,
project
,
current_user
,
labels:
labels
)
label_names
=
labels
.
map
(
&
:name
)
recipients
.
each
do
|
recipient
|
...
...
@@ -608,10 +608,10 @@ class NotificationService
end
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
)
recipients
=
add_labels_subscribers
(
recipients
,
target
)
recipients
=
add_labels_subscribers
(
recipients
,
project
,
target
)
end
recipients
=
reject_unsubscribed_users
(
recipients
,
target
)
...
...
@@ -622,8 +622,8 @@ class NotificationService
recipients
.
uniq
end
def
build_relabeled_recipients
(
target
,
current_user
,
labels
:)
recipients
=
add_labels_subscribers
([],
target
,
labels:
labels
)
def
build_relabeled_recipients
(
target
,
project
,
current_user
,
labels
:)
recipients
=
add_labels_subscribers
([],
project
,
target
,
labels:
labels
)
recipients
=
reject_unsubscribed_users
(
recipients
,
target
)
recipients
=
reject_users_without_access
(
recipients
,
target
)
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