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
eaa503d6
Commit
eaa503d6
authored
Aug 02, 2017
by
http://jneen.net/
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
move the read_ability logic into NotificationRecipient
parent
56a40a2b
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
18 additions
and
21 deletions
+18
-21
app/models/notification_recipient.rb
app/models/notification_recipient.rb
+18
-4
app/services/notification_recipient_service.rb
app/services/notification_recipient_service.rb
+0
-16
app/services/notification_service.rb
app/services/notification_service.rb
+0
-1
No files found.
app/models/notification_recipient.rb
View file @
eaa503d6
...
@@ -5,12 +5,10 @@ class NotificationRecipient
...
@@ -5,12 +5,10 @@ class NotificationRecipient
custom_action:
nil
,
custom_action:
nil
,
target:
nil
,
target:
nil
,
acting_user:
nil
,
acting_user:
nil
,
read_ability:
nil
,
project:
nil
project:
nil
)
)
@custom_action
=
custom_action
@custom_action
=
custom_action
@acting_user
=
acting_user
@acting_user
=
acting_user
@read_ability
=
read_ability
@target
=
target
@target
=
target
@project
=
project
||
@target
&
.
project
@project
=
project
||
@target
&
.
project
@user
=
user
@user
=
user
...
@@ -81,10 +79,10 @@ class NotificationRecipient
...
@@ -81,10 +79,10 @@ class NotificationRecipient
return
false
unless
user
.
can?
(
:receive_notifications
)
return
false
unless
user
.
can?
(
:receive_notifications
)
return
false
if
@project
&&
!
user
.
can?
(
:read_project
,
@project
)
return
false
if
@project
&&
!
user
.
can?
(
:read_project
,
@project
)
return
true
unless
@
read_ability
return
true
unless
read_ability
return
true
unless
DeclarativePolicy
.
has_policy?
(
@target
)
return
true
unless
DeclarativePolicy
.
has_policy?
(
@target
)
user
.
can?
(
@
read_ability
,
@target
)
user
.
can?
(
read_ability
,
@target
)
end
end
end
end
...
@@ -97,6 +95,22 @@ class NotificationRecipient
...
@@ -97,6 +95,22 @@ class NotificationRecipient
private
private
def
read_ability
return
@read_ability
if
instance_variable_defined?
(
:@read_ability
)
@read_ability
=
case
@target
when
Issuable
:"read_
#{
@target
.
to_ability_name
}
"
when
Ci
::
Pipeline
:read_build
# We have build trace in pipeline emails
when
ActiveRecord
::
Base
:"read_
#{
@target
.
class
.
model_name
.
name
.
underscore
}
"
else
nil
end
end
def
find_notification_setting
def
find_notification_setting
project_setting
=
@project
&&
user
.
notification_settings_for
(
@project
)
project_setting
=
@project
&&
user
.
notification_settings_for
(
@project
)
...
...
app/services/notification_recipient_service.rb
View file @
eaa503d6
...
@@ -76,7 +76,6 @@ module NotificationRecipientService
...
@@ -76,7 +76,6 @@ module NotificationRecipientService
custom_action:
custom_action
,
custom_action:
custom_action
,
target:
target
,
target:
target
,
acting_user:
acting_user
,
acting_user:
acting_user
,
read_ability:
read_ability
)
)
end
end
...
@@ -91,15 +90,6 @@ module NotificationRecipientService
...
@@ -91,15 +90,6 @@ module NotificationRecipientService
end
end
end
end
def
read_ability
case
target
when
Issuable
:"read_
#{
target
.
to_ability_name
}
"
when
Ci
::
Pipeline
:read_build
# We have build trace in pipeline emails
end
end
def
custom_action
def
custom_action
nil
nil
end
end
...
@@ -285,12 +275,6 @@ module NotificationRecipientService
...
@@ -285,12 +275,6 @@ module NotificationRecipientService
note
.
project
note
.
project
end
end
def
read_ability
return
nil
if
target
.
nil?
:"read_
#{
target
.
class
.
model_name
.
name
.
underscore
}
"
end
def
build!
def
build!
# Add all users participating in the thread (author, assignee, comment authors)
# Add all users participating in the thread (author, assignee, comment authors)
add_participants
(
note
.
author
)
add_participants
(
note
.
author
)
...
...
app/services/notification_service.rb
View file @
eaa503d6
...
@@ -303,7 +303,6 @@ class NotificationService
...
@@ -303,7 +303,6 @@ class NotificationService
recipients
||=
NotificationRecipientService
.
notifiable_users
(
recipients
||=
NotificationRecipientService
.
notifiable_users
(
[
pipeline
.
user
],
:watch
,
[
pipeline
.
user
],
:watch
,
custom_action: :"
#{
pipeline
.
status
}
_pipeline"
,
custom_action: :"
#{
pipeline
.
status
}
_pipeline"
,
read_ability: :read_build
,
target:
pipeline
target:
pipeline
).
map
(
&
:notification_email
)
).
map
(
&
:notification_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