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
Léo-Paul Géneau
gitlab-ce
Commits
b69e81c3
Commit
b69e81c3
authored
Jul 25, 2017
by
http://jneen.net/
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
rm the @builder argument and factor out .notifiable_users
parent
943baa13
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
38 additions
and
15 deletions
+38
-15
app/services/notification_recipient_service.rb
app/services/notification_recipient_service.rb
+37
-13
app/services/notification_service.rb
app/services/notification_service.rb
+1
-2
No files found.
app/services/notification_recipient_service.rb
View file @
b69e81c3
...
@@ -21,16 +21,25 @@ class NotificationRecipientService
...
@@ -21,16 +21,25 @@ class NotificationRecipientService
end
end
class
Recipient
class
Recipient
def
self
.
notifiable_users
(
users
,
*
args
)
users
.
map
{
|
u
|
new
(
u
,
*
args
)
}.
select
(
&
:notifiable?
).
map
(
&
:user
)
end
attr_reader
:user
,
:type
attr_reader
:user
,
:type
def
initialize
(
builder
,
user
,
type
)
def
initialize
(
user
,
project
,
type
,
@builder
=
builder
custom_action:
nil
,
target:
nil
,
acting_user:
nil
,
read_ability:
nil
)
@project
=
project
@custom_action
=
custom_action
@acting_user
=
acting_user
@read_ability
=
read_ability
@target
=
target
@user
=
user
@user
=
user
@type
=
type
@type
=
type
end
end
def
notification_setting
def
notification_setting
@notification_setting
||=
@notification_setting
||=
NotificationRecipientService
.
notification_setting_for_user_project
(
user
,
@
builder
.
project
)
NotificationRecipientService
.
notification_setting_for_user_project
(
user
,
@project
)
end
end
def
raw_notification_level
def
raw_notification_level
...
@@ -43,7 +52,11 @@ class NotificationRecipientService
...
@@ -43,7 +52,11 @@ class NotificationRecipientService
@notification_level
||=
@notification_level
||=
case
raw_notification_level
case
raw_notification_level
when
:custom
when
:custom
notification_setting
.
event_enabled?
(
@builder
.
custom_action
)
?
:watch
:
:custom
if
!
@custom_action
||
notification_setting
.
event_enabled?
(
@custom_action
)
:watch
else
:custom
end
else
else
raw_notification_level
raw_notification_level
end
end
...
@@ -69,32 +82,34 @@ class NotificationRecipientService
...
@@ -69,32 +82,34 @@ class NotificationRecipientService
end
end
def
unsubscribed?
def
unsubscribed?
return
false
unless
@builder
.
target
.
respond_to?
(
:subscriptions
)
return
false
unless
@target
return
false
unless
@target
.
respond_to?
(
:subscriptions
)
subscription
=
@
builder
.
target
.
subscriptions
.
find_by_user_id
(
@user
.
id
)
subscription
=
@target
.
subscriptions
.
find_by_user_id
(
@user
.
id
)
subscription
&&
!
subscription
.
subscribed
subscription
&&
!
subscription
.
subscribed
end
end
def
own_activity?
def
own_activity?
return
false
unless
@
builder
.
acting_user
return
false
unless
@acting_user
return
false
if
@
builder
.
acting_user
.
notified_of_own_activity?
return
false
if
@acting_user
.
notified_of_own_activity?
user
==
@
builder
.
acting_user
user
==
@acting_user
end
end
def
has_access?
def
has_access?
return
false
unless
user
.
can?
(
:receive_notifications
)
return
false
unless
user
.
can?
(
:receive_notifications
)
return
true
unless
@
builder
.
read_ability
return
true
unless
@read_ability
DeclarativePolicy
.
subject_scope
do
DeclarativePolicy
.
subject_scope
do
user
.
can?
(
@
builder
.
read_ability
,
@builder
.
target
)
user
.
can?
(
@
read_ability
,
@
target
)
end
end
end
end
def
excluded_watcher_action?
def
excluded_watcher_action?
return
false
unless
@custom_action
return
false
if
raw_notification_level
==
:custom
return
false
if
raw_notification_level
==
:custom
NotificationSetting
::
EXCLUDED_WATCHER_EVENTS
.
include?
(
@
builder
.
custom_action
)
NotificationSetting
::
EXCLUDED_WATCHER_EVENTS
.
include?
(
@custom_action
)
end
end
end
end
...
@@ -128,7 +143,16 @@ class NotificationRecipientService
...
@@ -128,7 +143,16 @@ class NotificationRecipientService
users
,
type
=
arg
users
,
type
=
arg
users
=
Array
(
users
)
users
=
Array
(
users
)
users
.
compact!
users
.
compact!
recipients
.
concat
(
users
.
map
{
|
u
|
Recipient
.
new
(
self
,
u
,
type
)
})
recipients
.
concat
(
users
.
map
{
|
u
|
make_recipient
(
u
,
type
)
})
end
def
make_recipient
(
user
,
type
)
Recipient
.
new
(
user
,
project
,
type
,
custom_action:
custom_action
,
target:
target
,
acting_user:
acting_user
,
read_ability:
read_ability
)
end
end
def
recipient_users
def
recipient_users
...
...
app/services/notification_service.rb
View file @
b69e81c3
...
@@ -270,8 +270,7 @@ class NotificationService
...
@@ -270,8 +270,7 @@ class NotificationService
end
end
def
project_was_moved
(
project
,
old_path_with_namespace
)
def
project_was_moved
(
project
,
old_path_with_namespace
)
recipients
=
project
.
team
.
members
recipients
=
NotificationRecipientService
::
Recipient
.
notifiable_users
(
project
.
team
.
members
,
project
,
:watch
)
recipients
=
NotificationRecipientService
.
new
(
project
).
reject_muted_users
(
recipients
)
recipients
.
each
do
|
recipient
|
recipients
.
each
do
|
recipient
|
mailer
.
project_was_moved_email
(
mailer
.
project_was_moved_email
(
...
...
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