BigW Consortium Gitlab
Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
G
gitlab-ce
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
Forest Godfrey
gitlab-ce
Commits
9b0efdb7
Unverified
Commit
9b0efdb7
authored
Nov 17, 2015
by
Dmitriy Zaporozhets
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Remove code duplication in notification_service.rb
Signed-off-by:
Dmitriy Zaporozhets
<
dmitriy.zaporozhets@gmail.com
>
parent
616675b4
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
18 additions
and
28 deletions
+18
-28
notification_service.rb
app/services/notification_service.rb
+18
-28
No files found.
app/services/notification_service.rb
View file @
9b0efdb7
...
@@ -113,7 +113,7 @@ class NotificationService
...
@@ -113,7 +113,7 @@ class NotificationService
end
end
# Add all users participating in the thread (author, assignee, comment authors)
# Add all users participating in the thread (author, assignee, comment authors)
participants
=
participants
=
if
target
.
respond_to?
(
:participants
)
if
target
.
respond_to?
(
:participants
)
target
.
participants
(
note
.
author
)
target
.
participants
(
note
.
author
)
else
else
...
@@ -276,35 +276,25 @@ class NotificationService
...
@@ -276,35 +276,25 @@ class NotificationService
# Remove users with disabled notifications from array
# Remove users with disabled notifications from array
# Also remove duplications and nil recipients
# Also remove duplications and nil recipients
def
reject_muted_users
(
users
,
project
=
nil
)
def
reject_muted_users
(
users
,
project
=
nil
)
users
=
users
.
to_a
.
compact
.
uniq
reject_users
(
users
,
:disabled?
,
project
)
users
=
users
.
reject
(
&
:blocked?
)
users
.
reject
do
|
user
|
next
user
.
notification
.
disabled?
unless
project
member
=
project
.
project_members
.
find_by
(
user_id:
user
.
id
)
if
!
member
&&
project
.
group
member
=
project
.
group
.
group_members
.
find_by
(
user_id:
user
.
id
)
end
# reject users who globally disabled notification and has no membership
next
user
.
notification
.
disabled?
unless
member
# reject users who disabled notification in project
next
true
if
member
.
notification
.
disabled?
# reject users who have N_GLOBAL in project and disabled in global settings
member
.
notification
.
global?
&&
user
.
notification
.
disabled?
end
end
end
# Remove users with notification level 'Mentioned'
# Remove users with notification level 'Mentioned'
def
reject_mention_users
(
users
,
project
=
nil
)
def
reject_mention_users
(
users
,
project
=
nil
)
reject_users
(
users
,
:mention?
,
project
)
end
# Reject users which method_name from notification object returns true.
#
# Example:
# reject_users(users, :watch?, project)
#
def
reject_users
(
users
,
method_name
,
project
=
nil
)
users
=
users
.
to_a
.
compact
.
uniq
users
=
users
.
to_a
.
compact
.
uniq
users
=
users
.
reject
(
&
:blocked?
)
users
.
reject
do
|
user
|
users
.
reject
do
|
user
|
next
user
.
notification
.
mention?
unless
project
next
user
.
notification
.
send
(
method_name
)
unless
project
member
=
project
.
project_members
.
find_by
(
user_id:
user
.
id
)
member
=
project
.
project_members
.
find_by
(
user_id:
user
.
id
)
...
@@ -313,19 +303,19 @@ class NotificationService
...
@@ -313,19 +303,19 @@ class NotificationService
end
end
# reject users who globally set mention notification and has no membership
# reject users who globally set mention notification and has no membership
next
user
.
notification
.
mention?
unless
member
next
user
.
notification
.
send
(
method_name
)
unless
member
# reject users who set mention notification in project
# reject users who set mention notification in project
next
true
if
member
.
notification
.
mention?
next
true
if
member
.
notification
.
send
(
method_name
)
# reject users who have N_MENTION in project and disabled in global settings
# reject users who have N_MENTION in project and disabled in global settings
member
.
notification
.
global?
&&
user
.
notification
.
mention?
member
.
notification
.
global?
&&
user
.
notification
.
send
(
method_name
)
end
end
end
end
def
reject_unsubscribed_users
(
recipients
,
target
)
def
reject_unsubscribed_users
(
recipients
,
target
)
return
recipients
unless
target
.
respond_to?
:subscriptions
return
recipients
unless
target
.
respond_to?
:subscriptions
recipients
.
reject
do
|
user
|
recipients
.
reject
do
|
user
|
subscription
=
target
.
subscriptions
.
find_by_user_id
(
user
.
id
)
subscription
=
target
.
subscriptions
.
find_by_user_id
(
user
.
id
)
subscription
&&
!
subscription
.
subscribed
subscription
&&
!
subscription
.
subscribed
...
@@ -343,7 +333,7 @@ class NotificationService
...
@@ -343,7 +333,7 @@ class NotificationService
recipients
recipients
end
end
end
end
def
new_resource_email
(
target
,
project
,
method
)
def
new_resource_email
(
target
,
project
,
method
)
recipients
=
build_recipients
(
target
,
project
,
target
.
author
)
recipients
=
build_recipients
(
target
,
project
,
target
.
author
)
...
...
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