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
618a3d12
Commit
618a3d12
authored
Jul 26, 2017
by
http://jneen.net/
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
move Recipient to its own NotificationRecipient file
parent
618b5d34
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
109 additions
and
109 deletions
+109
-109
app/models/notification_recipient.rb
app/models/notification_recipient.rb
+102
-0
app/services/notification_recipient_service.rb
app/services/notification_recipient_service.rb
+7
-109
No files found.
app/models/notification_recipient.rb
0 → 100644
View file @
618a3d12
class
NotificationRecipient
attr_reader
:user
,
:project
,
:type
def
initialize
(
user
,
project
,
type
,
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
@type
=
type
end
def
notification_setting
@notification_setting
||=
find_notification_setting
end
def
raw_notification_level
notification_setting
&
.
level
&
.
to_sym
end
def
notification_level
# custom is treated the same as watch if it's enabled - otherwise it's
# as :disabled.
@notification_level
||=
case
raw_notification_level
when
:custom
if
@custom_action
&&
notification_setting
.
event_enabled?
(
@custom_action
)
:watch
else
:custom
end
else
raw_notification_level
end
end
def
notifiable?
return
false
unless
has_access?
return
false
if
own_activity?
return
true
if
@type
==
:subscription
return
false
if
notification_level
.
nil?
||
notification_level
==
:disabled
return
%i[participating mention]
.
include?
(
@type
)
if
notification_level
==
:custom
return
false
if
%i[watch participating]
.
include?
(
notification_level
)
&&
excluded_watcher_action?
return
false
unless
NotificationSetting
.
levels
[
notification_level
]
<=
NotificationSetting
.
levels
[
type
]
return
false
if
unsubscribed?
true
end
def
unsubscribed?
return
false
unless
@target
return
false
unless
@target
.
respond_to?
(
:subscriptions
)
subscription
=
@target
.
subscriptions
.
find_by_user_id
(
@user
.
id
)
subscription
&&
!
subscription
.
subscribed
end
def
own_activity?
return
false
unless
@acting_user
return
false
if
@acting_user
.
notified_of_own_activity?
user
==
@acting_user
end
def
has_access?
return
false
unless
user
.
can?
(
:receive_notifications
)
return
true
unless
@read_ability
DeclarativePolicy
.
subject_scope
do
user
.
can?
(
@read_ability
,
@target
)
end
end
def
excluded_watcher_action?
return
false
unless
@custom_action
return
false
if
raw_notification_level
==
:custom
NotificationSetting
::
EXCLUDED_WATCHER_EVENTS
.
include?
(
@custom_action
)
end
private
def
find_notification_setting
project_setting
=
@project
&&
user
.
notification_settings_for
(
@project
)
return
project_setting
unless
project_setting
.
nil?
||
project_setting
.
global?
group_setting
=
@project
&
.
group
&&
user
.
notification_settings_for
(
@project
.
group
)
return
group_setting
unless
group_setting
.
nil?
||
group_setting
.
global?
user
.
global_notification_setting
end
end
app/services/notification_recipient_service.rb
View file @
618a3d12
...
...
@@ -2,8 +2,12 @@
# Used by NotificationService to determine who should receive notification
#
module
NotificationRecipientService
def
self
.
notifiable_users
(
*
a
)
Recipient
.
notifiable_users
(
*
a
)
def
self
.
notifiable_users
(
users
,
*
args
)
users
.
map
{
|
u
|
NotificationRecipient
.
new
(
u
,
*
args
)
}.
select
(
&
:notifiable?
).
map
(
&
:user
)
end
def
self
.
notifiable?
(
user
,
*
args
)
NotificationRecipient
.
new
(
user
,
*
args
).
notifiable?
end
def
self
.
build_recipients
(
*
a
)
...
...
@@ -18,112 +22,6 @@ module NotificationRecipientService
Builder
::
NewNote
.
new
(
*
a
).
recipient_users
end
class
Recipient
def
self
.
notifiable_users
(
users
,
*
args
)
users
.
map
{
|
u
|
new
(
u
,
*
args
)
}.
select
(
&
:notifiable?
).
map
(
&
:user
)
end
attr_reader
:user
,
:type
def
initialize
(
user
,
project
,
type
,
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
@type
=
type
end
def
notification_setting
@notification_setting
||=
find_notification_setting
end
def
raw_notification_level
notification_setting
&
.
level
&
.
to_sym
end
def
notification_level
# custom is treated the same as watch if it's enabled - otherwise it's
# as :disabled.
@notification_level
||=
case
raw_notification_level
when
:custom
if
@custom_action
&&
notification_setting
.
event_enabled?
(
@custom_action
)
:watch
else
:custom
end
else
raw_notification_level
end
end
def
notifiable?
return
false
unless
has_access?
return
false
if
own_activity?
return
true
if
@type
==
:subscription
return
false
if
notification_level
.
nil?
||
notification_level
==
:disabled
return
%i[participating mention]
.
include?
(
@type
)
if
notification_level
==
:custom
return
false
if
%i[watch participating]
.
include?
(
notification_level
)
&&
excluded_watcher_action?
return
false
unless
NotificationSetting
.
levels
[
notification_level
]
<=
NotificationSetting
.
levels
[
type
]
return
false
if
unsubscribed?
true
end
def
unsubscribed?
return
false
unless
@target
return
false
unless
@target
.
respond_to?
(
:subscriptions
)
subscription
=
@target
.
subscriptions
.
find_by_user_id
(
@user
.
id
)
subscription
&&
!
subscription
.
subscribed
end
def
own_activity?
return
false
unless
@acting_user
return
false
if
@acting_user
.
notified_of_own_activity?
user
==
@acting_user
end
def
has_access?
return
false
unless
user
.
can?
(
:receive_notifications
)
return
true
unless
@read_ability
DeclarativePolicy
.
subject_scope
do
user
.
can?
(
@read_ability
,
@target
)
end
end
def
excluded_watcher_action?
return
false
unless
@custom_action
return
false
if
raw_notification_level
==
:custom
NotificationSetting
::
EXCLUDED_WATCHER_EVENTS
.
include?
(
@custom_action
)
end
private
def
find_notification_setting
project_setting
=
project
&&
user
.
notification_settings_for
(
project
)
return
project_setting
unless
project_setting
.
nil?
||
project_setting
.
global?
group_setting
=
project
&
.
group
&&
user
.
notification_settings_for
(
project
.
group
)
return
group_setting
unless
group_setting
.
nil?
||
group_setting
.
global?
user
.
global_notification_setting
end
end
module
Builder
class
Base
def
initialize
(
*
)
...
...
@@ -158,7 +56,7 @@ module NotificationRecipientService
end
def
make_recipient
(
user
,
type
)
Recipient
.
new
(
user
,
project
,
type
,
Notification
Recipient
.
new
(
user
,
project
,
type
,
custom_action:
custom_action
,
target:
target
,
acting_user:
acting_user
,
...
...
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