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
Boxiang Sun
gitlab-ce
Commits
b010a556
Commit
b010a556
authored
Jul 20, 2017
by
http://jneen.net/
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
factor out the `target` argument to helpers
parent
947bff88
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
19 additions
and
19 deletions
+19
-19
app/services/notification_recipient_service.rb
app/services/notification_recipient_service.rb
+19
-19
No files found.
app/services/notification_recipient_service.rb
View file @
b010a556
...
@@ -30,7 +30,7 @@ class NotificationRecipientService
...
@@ -30,7 +30,7 @@ class NotificationRecipientService
raise
'abstract'
raise
'abstract'
end
end
def
build
(
*
)
def
target
raise
'abstract'
raise
'abstract'
end
end
...
@@ -44,7 +44,7 @@ class NotificationRecipientService
...
@@ -44,7 +44,7 @@ class NotificationRecipientService
# Ensure that if we modify this array, we aren't modifying the memoised
# Ensure that if we modify this array, we aren't modifying the memoised
# participants on the target.
# participants on the target.
def
participants
(
target
,
user
)
def
participants
(
user
)
return
unless
target
.
respond_to?
(
:participants
)
return
unless
target
.
respond_to?
(
:participants
)
target
.
participants
(
user
).
dup
target
.
participants
(
user
).
dup
...
@@ -92,7 +92,7 @@ class NotificationRecipientService
...
@@ -92,7 +92,7 @@ class NotificationRecipientService
reject_users
(
users
,
:mention
)
reject_users
(
users
,
:mention
)
end
end
def
add_subscribed_users
(
recipients
,
target
)
def
add_subscribed_users
(
recipients
)
return
recipients
unless
target
.
respond_to?
:subscribers
return
recipients
unless
target
.
respond_to?
:subscribers
recipients
+
target
.
subscribers
(
project
)
recipients
+
target
.
subscribers
(
project
)
...
@@ -184,7 +184,7 @@ class NotificationRecipientService
...
@@ -184,7 +184,7 @@ class NotificationRecipientService
end
end
end
end
def
reject_unsubscribed_users
(
recipients
,
target
)
def
reject_unsubscribed_users
(
recipients
)
return
recipients
unless
target
.
respond_to?
:subscriptions
return
recipients
unless
target
.
respond_to?
:subscriptions
recipients
.
reject
do
|
user
|
recipients
.
reject
do
|
user
|
...
@@ -193,7 +193,7 @@ class NotificationRecipientService
...
@@ -193,7 +193,7 @@ class NotificationRecipientService
end
end
end
end
def
reject_users_without_access
(
recipients
,
target
)
def
reject_users_without_access
(
recipients
)
recipients
=
recipients
.
select
{
|
u
|
u
.
can?
(
:receive_notifications
)
}
recipients
=
recipients
.
select
{
|
u
|
u
.
can?
(
:receive_notifications
)
}
ability
=
case
target
ability
=
case
target
...
@@ -210,7 +210,7 @@ class NotificationRecipientService
...
@@ -210,7 +210,7 @@ class NotificationRecipientService
end
end
end
end
def
add_labels_subscribers
(
recipients
,
target
,
labels:
nil
)
def
add_labels_subscribers
(
recipients
,
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
|
...
@@ -246,7 +246,7 @@ class NotificationRecipientService
...
@@ -246,7 +246,7 @@ class NotificationRecipientService
def
build
def
build
custom_action
=
build_custom_key
(
action
,
target
)
custom_action
=
build_custom_key
(
action
,
target
)
recipients
=
participants
(
target
,
current_user
)
recipients
=
participants
(
current_user
)
recipients
=
add_project_watchers
(
recipients
)
recipients
=
add_project_watchers
(
recipients
)
recipients
=
add_custom_notifications
(
recipients
,
custom_action
)
recipients
=
add_custom_notifications
(
recipients
,
custom_action
)
recipients
=
reject_mention_users
(
recipients
)
recipients
=
reject_mention_users
(
recipients
)
...
@@ -265,14 +265,14 @@ class NotificationRecipientService
...
@@ -265,14 +265,14 @@ class NotificationRecipientService
end
end
recipients
=
reject_muted_users
(
recipients
)
recipients
=
reject_muted_users
(
recipients
)
recipients
=
add_subscribed_users
(
recipients
,
target
)
recipients
=
add_subscribed_users
(
recipients
)
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
)
end
end
recipients
=
reject_unsubscribed_users
(
recipients
,
target
)
recipients
=
reject_unsubscribed_users
(
recipients
)
recipients
=
reject_users_without_access
(
recipients
,
target
)
recipients
=
reject_users_without_access
(
recipients
)
recipients
.
delete
(
current_user
)
if
skip_current_user
&&
!
current_user
.
notified_of_own_activity?
recipients
.
delete
(
current_user
)
if
skip_current_user
&&
!
current_user
.
notified_of_own_activity?
...
@@ -311,7 +311,7 @@ class NotificationRecipientService
...
@@ -311,7 +311,7 @@ class NotificationRecipientService
return
[]
if
(
notification_setting
.
watch?
||
notification_setting
.
participating?
)
&&
NotificationSetting
::
EXCLUDED_WATCHER_EVENTS
.
include?
(
custom_action
)
return
[]
if
(
notification_setting
.
watch?
||
notification_setting
.
participating?
)
&&
NotificationSetting
::
EXCLUDED_WATCHER_EVENTS
.
include?
(
custom_action
)
reject_users_without_access
([
current_user
]
,
target
)
reject_users_without_access
([
current_user
])
end
end
end
end
...
@@ -328,9 +328,9 @@ class NotificationRecipientService
...
@@ -328,9 +328,9 @@ class NotificationRecipientService
end
end
def
build
def
build
recipients
=
add_labels_subscribers
([],
target
,
labels:
labels
)
recipients
=
add_labels_subscribers
([],
labels:
labels
)
recipients
=
reject_unsubscribed_users
(
recipients
,
target
)
recipients
=
reject_unsubscribed_users
(
recipients
)
recipients
=
reject_users_without_access
(
recipients
,
target
)
recipients
=
reject_users_without_access
(
recipients
)
recipients
.
delete
(
current_user
)
unless
current_user
.
notified_of_own_activity?
recipients
.
delete
(
current_user
)
unless
current_user
.
notified_of_own_activity?
recipients
.
uniq
recipients
.
uniq
end
end
...
@@ -356,7 +356,7 @@ class NotificationRecipientService
...
@@ -356,7 +356,7 @@ class NotificationRecipientService
mentioned_users
=
note
.
mentioned_users
.
select
{
|
user
|
user
.
can?
(
ability
,
subject
)
}
mentioned_users
=
note
.
mentioned_users
.
select
{
|
user
|
user
.
can?
(
ability
,
subject
)
}
# Add all users participating in the thread (author, assignee, comment authors)
# Add all users participating in the thread (author, assignee, comment authors)
recipients
=
participants
(
target
,
note
.
author
)
||
mentioned_users
recipients
=
participants
(
note
.
author
)
||
mentioned_users
unless
note
.
for_personal_snippet?
unless
note
.
for_personal_snippet?
# Merge project watchers
# Merge project watchers
...
@@ -372,9 +372,9 @@ class NotificationRecipientService
...
@@ -372,9 +372,9 @@ class NotificationRecipientService
recipients
=
reject_muted_users
(
recipients
)
recipients
=
reject_muted_users
(
recipients
)
recipients
=
add_subscribed_users
(
recipients
,
note
.
noteable
)
recipients
=
add_subscribed_users
(
recipients
)
recipients
=
reject_unsubscribed_users
(
recipients
,
note
.
noteable
)
recipients
=
reject_unsubscribed_users
(
recipients
)
recipients
=
reject_users_without_access
(
recipients
,
note
.
noteable
)
recipients
=
reject_users_without_access
(
recipients
)
recipients
.
delete
(
note
.
author
)
unless
note
.
author
.
notified_of_own_activity?
recipients
.
delete
(
note
.
author
)
unless
note
.
author
.
notified_of_own_activity?
recipients
.
uniq
recipients
.
uniq
...
...
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