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
1
Merge Requests
1
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
nexedi
gitlab-ce
Commits
89a2c873
Commit
89a2c873
authored
May 31, 2016
by
Felipe Artur
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Implement custom notification level options
parent
8bfbafbb
Changes
18
Hide whitespace changes
Inline
Side-by-side
Showing
18 changed files
with
354 additions
and
78 deletions
+354
-78
CHANGELOG
CHANGELOG
+1
-0
app/assets/javascripts/dispatcher.js.coffee
app/assets/javascripts/dispatcher.js.coffee
+1
-0
app/assets/javascripts/notifications_form.js.coffee
app/assets/javascripts/notifications_form.js.coffee
+49
-0
app/assets/javascripts/project.js.coffee
app/assets/javascripts/project.js.coffee
+20
-15
app/assets/stylesheets/pages/projects.scss
app/assets/stylesheets/pages/projects.scss
+17
-5
app/controllers/projects/notification_settings_controller.rb
app/controllers/projects/notification_settings_controller.rb
+9
-4
app/models/notification_setting.rb
app/models/notification_setting.rb
+36
-1
app/services/notification_service.rb
app/services/notification_service.rb
+60
-34
app/views/projects/buttons/_notifications.html.haml
app/views/projects/buttons/_notifications.html.haml
+20
-10
app/views/shared/projects/_custom_notifications.html.haml
app/views/shared/projects/_custom_notifications.html.haml
+26
-0
app/views/shared/projects/_notification_dropdown.html.haml
app/views/shared/projects/_notification_dropdown.html.haml
+9
-0
db/migrate/20160614301627_add_events_to_notification_settings.rb
...ate/20160614301627_add_events_to_notification_settings.rb
+7
-0
doc/workflow/notifications.md
doc/workflow/notifications.md
+4
-2
doc/workflow/notifications/settings.png
doc/workflow/notifications/settings.png
+0
-0
features/steps/project/project.rb
features/steps/project/project.rb
+1
-1
spec/controllers/projects/notification_settings_controller_spec.rb
...rollers/projects/notification_settings_controller_spec.rb
+19
-0
spec/models/notification_setting_spec.rb
spec/models/notification_setting_spec.rb
+25
-0
spec/services/notification_service_spec.rb
spec/services/notification_service_spec.rb
+50
-6
No files found.
CHANGELOG
View file @
89a2c873
...
@@ -54,6 +54,7 @@ v 8.9.0 (unreleased)
...
@@ -54,6 +54,7 @@ v 8.9.0 (unreleased)
- Remove 'main language' feature
- Remove 'main language' feature
- Pipelines can be canceled only when there are running builds
- Pipelines can be canceled only when there are running builds
- Use downcased path to container repository as this is expected path by Docker
- Use downcased path to container repository as this is expected path by Docker
- Customized notification settings for projects
- Projects pending deletion will render a 404 page
- Projects pending deletion will render a 404 page
- Measure queue duration between gitlab-workhorse and Rails
- Measure queue duration between gitlab-workhorse and Rails
- Make Omniauth providers specs to not modify global configuration
- Make Omniauth providers specs to not modify global configuration
...
...
app/assets/javascripts/dispatcher.js.coffee
View file @
89a2c873
...
@@ -75,6 +75,7 @@ class Dispatcher
...
@@ -75,6 +75,7 @@ class Dispatcher
when
'projects:show'
when
'projects:show'
shortcut_handler
=
new
ShortcutsNavigation
()
shortcut_handler
=
new
ShortcutsNavigation
()
new
NotificationsForm
()
new
TreeView
()
if
$
(
'#tree-slider'
).
length
new
TreeView
()
if
$
(
'#tree-slider'
).
length
when
'groups:activity'
when
'groups:activity'
new
Activities
()
new
Activities
()
...
...
app/assets/javascripts/notifications_form.js.coffee
0 → 100644
View file @
89a2c873
class
@
NotificationsForm
constructor
:
->
@
form
=
$
(
'.custom-notifications-form'
)
@
removeEventListeners
()
@
initEventListeners
()
removeEventListeners
:
->
$
(
document
).
off
'change'
,
'.js-custom-notification-event'
initEventListeners
:
->
$
(
document
).
on
'change'
,
'.js-custom-notification-event'
,
@
toggleCheckbox
toggleCheckbox
:
(
e
)
=>
$checkbox
=
$
(
e
.
currentTarget
)
$parent
=
$checkbox
.
closest
(
'.checkbox'
)
@
saveEvent
(
$checkbox
,
$parent
)
showCheckboxLoadingSpinner
:
(
$parent
)
->
$parent
.
addClass
'is-loading'
.
find
'.custom-notification-event-loading'
.
removeClass
'fa-check'
.
addClass
'fa-spin fa-spinner'
.
removeClass
'is-done'
saveEvent
:
(
$checkbox
,
$parent
)
->
$
.
ajax
(
url
:
@
form
.
attr
(
'action'
)
method
:
'patch'
dataType
:
'json'
data
:
@
form
.
serialize
()
beforeSend
:
=>
@
showCheckboxLoadingSpinner
(
$parent
)
).
done
(
data
)
->
$checkbox
.
enable
()
if
data
.
saved
$parent
.
find
'.custom-notification-event-loading'
.
toggleClass
'fa-spin fa-spinner fa-check is-done'
setTimeout
(
->
$parent
.
removeClass
'is-loading'
.
find
'.custom-notification-event-loading'
.
toggleClass
'fa-spin fa-spinner fa-check is-done'
,
2000
)
app/assets/javascripts/project.js.coffee
View file @
89a2c873
...
@@ -34,21 +34,26 @@ class @Project
...
@@ -34,21 +34,26 @@ class @Project
$
(
@
).
parents
(
'.no-password-message'
).
remove
()
$
(
@
).
parents
(
'.no-password-message'
).
remove
()
e
.
preventDefault
()
e
.
preventDefault
()
$
(
'.update-notification'
).
on
'click'
,
(
e
)
->
$
(
document
)
e
.
preventDefault
()
.
off
'click'
,
'.update-notification'
notification_level
=
$
(
@
).
data
'notification-level'
.
on
'click'
,
'.update-notification'
,
(
e
)
->
label
=
$
(
@
).
data
'notification-title'
e
.
preventDefault
()
$
(
'#notification_setting_level'
).
val
(
notification_level
)
notificationLevel
=
$
(
@
).
data
'notification-level'
$
(
'#notification-form'
).
submit
()
label
=
$
(
@
).
data
'notification-title'
$
(
'#notifications-button'
).
empty
().
append
(
"<i class='fa fa-bell'></i>"
+
label
+
"<i class='fa fa-angle-down'></i>"
)
$
(
'.js-notification-loading'
).
toggleClass
'fa-bell fa-spin fa-spinner'
$
(
@
).
parents
(
'ul'
).
find
(
'li.active'
).
removeClass
'active'
$
(
'#notification_setting_level'
).
val
(
notificationLevel
)
$
(
@
).
parent
().
addClass
'active'
$
(
'#notification-form'
).
submit
()
$
(
'#notification-form'
).
on
'ajax:success'
,
(
e
,
data
)
->
$
(
document
)
if
data
.
saved
.
off
'ajax:success'
,
'#notification-form'
new
Flash
(
"Notification settings saved"
,
"notice"
)
.
on
'ajax:success'
,
'#notification-form'
,
(
e
,
data
)
->
else
if
data
.
saved
new
Flash
(
"Failed to save new settings"
,
"alert"
)
new
Flash
(
'Notification settings saved'
,
'notice'
)
$
(
'.js-notification-toggle-btns'
)
.
closest
(
'.notification-dropdown'
)
.
replaceWith
(
data
.
html
)
else
new
Flash
(
'Failed to save new settings'
,
'alert'
)
@
projectSelectDropdown
()
@
projectSelectDropdown
()
...
...
app/assets/stylesheets/pages/projects.scss
View file @
89a2c873
...
@@ -133,11 +133,6 @@
...
@@ -133,11 +133,6 @@
}
}
}
}
.btn-group
:not
(
:first-child
)
:not
(
:last-child
)
>
.btn
{
border-top-right-radius
:
3px
;
border-bottom-right-radius
:
3px
;
}
form
{
form
{
margin-left
:
10px
;
margin-left
:
10px
;
}
}
...
@@ -607,3 +602,20 @@ pre.light-well {
...
@@ -607,3 +602,20 @@ pre.light-well {
}
}
}
}
}
}
.custom-notifications-form
{
.is-loading
{
.custom-notification-event-loading
{
display
:
inline-block
;
}
}
}
.custom-notification-event-loading
{
display
:
none
;
margin-left
:
5px
;
&
.is-done
{
color
:
$gl-text-green
;
}
}
app/controllers/projects/notification_settings_controller.rb
View file @
89a2c873
...
@@ -2,15 +2,20 @@ class Projects::NotificationSettingsController < Projects::ApplicationController
...
@@ -2,15 +2,20 @@ class Projects::NotificationSettingsController < Projects::ApplicationController
before_action
:authenticate_user!
before_action
:authenticate_user!
def
update
def
update
notification_setting
=
current_user
.
notification_settings_for
(
project
)
@
notification_setting
=
current_user
.
notification_settings_for
(
project
)
saved
=
notification_setting
.
update_attributes
(
notification_setting_params
)
saved
=
@
notification_setting
.
update_attributes
(
notification_setting_params
)
render
json:
{
saved:
saved
}
render
json:
{
html:
view_to_html_string
(
"projects/buttons/_notifications"
,
locals:
{
project:
@project
,
notification_setting:
@notification_setting
}),
saved:
saved
}
end
end
private
private
def
notification_setting_params
def
notification_setting_params
params
.
require
(
:notification_setting
).
permit
(
:level
)
allowed_fields
=
NotificationSetting
::
EMAIL_EVENTS
.
dup
allowed_fields
<<
:level
params
.
require
(
:notification_setting
).
permit
(
allowed_fields
)
end
end
end
end
app/models/notification_setting.rb
View file @
89a2c873
class
NotificationSetting
<
ActiveRecord
::
Base
class
NotificationSetting
<
ActiveRecord
::
Base
enum
level:
{
global:
3
,
watch:
2
,
mention:
4
,
participating:
1
,
disabled:
0
}
enum
level:
{
global:
3
,
watch:
2
,
mention:
4
,
participating:
1
,
disabled:
0
,
custom:
5
}
default_value_for
:level
,
NotificationSetting
.
levels
[
:global
]
default_value_for
:level
,
NotificationSetting
.
levels
[
:global
]
...
@@ -15,6 +15,24 @@ class NotificationSetting < ActiveRecord::Base
...
@@ -15,6 +15,24 @@ class NotificationSetting < ActiveRecord::Base
scope
:for_groups
,
->
{
where
(
source_type:
'Namespace'
)
}
scope
:for_groups
,
->
{
where
(
source_type:
'Namespace'
)
}
scope
:for_projects
,
->
{
where
(
source_type:
'Project'
)
}
scope
:for_projects
,
->
{
where
(
source_type:
'Project'
)
}
EMAIL_EVENTS
=
[
:new_note
,
:new_issue
,
:reopen_issue
,
:close_issue
,
:reassign_issue
,
:new_merge_request
,
:reopen_merge_request
,
:close_merge_request
,
:reassign_merge_request
,
:merge_merge_request
]
store
:events
,
accessors:
EMAIL_EVENTS
,
coder:
JSON
before_create
:set_events
before_save
:events_to_boolean
def
self
.
find_or_create_for
(
source
)
def
self
.
find_or_create_for
(
source
)
setting
=
find_or_initialize_by
(
source:
source
)
setting
=
find_or_initialize_by
(
source:
source
)
...
@@ -24,4 +42,21 @@ class NotificationSetting < ActiveRecord::Base
...
@@ -24,4 +42,21 @@ class NotificationSetting < ActiveRecord::Base
setting
setting
end
end
# Set all event attributes to false when level is not custom or being initialized for UX reasons
def
set_events
return
if
custom?
EMAIL_EVENTS
.
each
do
|
event
|
events
[
event
]
=
false
end
end
# Validates store accessors values as boolean
# It is a text field so it does not cast correct boolean values in JSON
def
events_to_boolean
EMAIL_EVENTS
.
each
do
|
event
|
events
[
event
]
=
ActiveRecord
::
ConnectionAdapters
::
Column
::
TRUE_VALUES
.
include?
(
events
[
event
])
end
end
end
end
app/services/notification_service.rb
View file @
89a2c873
...
@@ -29,9 +29,10 @@ class NotificationService
...
@@ -29,9 +29,10 @@ class NotificationService
# * issue assignee if their notification level is not Disabled
# * issue assignee if their notification level is not Disabled
# * project team members with notification level higher then Participating
# * project team members with notification level higher then Participating
# * watchers of the issue's labels
# * watchers of the issue's labels
# * users with custom level checked with "new issue"
#
#
def
new_issue
(
issue
,
current_user
)
def
new_issue
(
issue
,
current_user
)
new_resource_email
(
issue
,
issue
.
project
,
'new_issue_email'
)
new_resource_email
(
issue
,
issue
.
project
,
:new_issue_email
)
end
end
# When we close an issue we should send an email to:
# When we close an issue we should send an email to:
...
@@ -39,18 +40,20 @@ class NotificationService
...
@@ -39,18 +40,20 @@ class NotificationService
# * issue author if their notification level is not Disabled
# * issue author if their notification level is not Disabled
# * issue assignee if their notification level is not Disabled
# * issue assignee if their notification level is not Disabled
# * project team members with notification level higher then Participating
# * project team members with notification level higher then Participating
# * users with custom level checked with "close issue"
#
#
def
close_issue
(
issue
,
current_user
)
def
close_issue
(
issue
,
current_user
)
close_resource_email
(
issue
,
issue
.
project
,
current_user
,
'closed_issue_email'
)
close_resource_email
(
issue
,
issue
.
project
,
current_user
,
:closed_issue_email
)
end
end
# When we reassign an issue we should send an email to:
# When we reassign an issue we should send an email to:
#
#
# * issue old assignee if their notification level is not Disabled
# * issue old assignee if their notification level is not Disabled
# * issue new assignee if their notification level is not Disabled
# * issue new assignee if their notification level is not Disabled
# * users with custom level checked with "reassign issue"
#
#
def
reassigned_issue
(
issue
,
current_user
)
def
reassigned_issue
(
issue
,
current_user
)
reassign_resource_email
(
issue
,
issue
.
project
,
current_user
,
'reassigned_issue_email'
)
reassign_resource_email
(
issue
,
issue
.
project
,
current_user
,
:reassigned_issue_email
)
end
end
# When we add labels to an issue we should send an email to:
# When we add labels to an issue we should send an email to:
...
@@ -58,7 +61,7 @@ class NotificationService
...
@@ -58,7 +61,7 @@ class NotificationService
# * watchers of the issue's labels
# * watchers of the issue's labels
#
#
def
relabeled_issue
(
issue
,
added_labels
,
current_user
)
def
relabeled_issue
(
issue
,
added_labels
,
current_user
)
relabeled_resource_email
(
issue
,
added_labels
,
current_user
,
'relabeled_issue_email'
)
relabeled_resource_email
(
issue
,
added_labels
,
current_user
,
:relabeled_issue_email
)
end
end
# When create a merge request we should send an email to:
# When create a merge request we should send an email to:
...
@@ -66,18 +69,20 @@ class NotificationService
...
@@ -66,18 +69,20 @@ class NotificationService
# * mr assignee if their notification level is not Disabled
# * mr assignee if their notification level is not Disabled
# * project team members with notification level higher then Participating
# * project team members with notification level higher then Participating
# * watchers of the mr's labels
# * watchers of the mr's labels
# * users with custom level checked with "new merge request"
#
#
def
new_merge_request
(
merge_request
,
current_user
)
def
new_merge_request
(
merge_request
,
current_user
)
new_resource_email
(
merge_request
,
merge_request
.
target_project
,
'new_merge_request_email'
)
new_resource_email
(
merge_request
,
merge_request
.
target_project
,
:new_merge_request_email
)
end
end
# When we reassign a merge_request we should send an email to:
# When we reassign a merge_request we should send an email to:
#
#
# * merge_request old assignee if their notification level is not Disabled
# * merge_request old assignee if their notification level is not Disabled
# * merge_request assignee if their notification level is not Disabled
# * merge_request assignee if their notification level is not Disabled
# * users with custom level checked with "reassign merge request"
#
#
def
reassigned_merge_request
(
merge_request
,
current_user
)
def
reassigned_merge_request
(
merge_request
,
current_user
)
reassign_resource_email
(
merge_request
,
merge_request
.
target_project
,
current_user
,
'reassigned_merge_request_email'
)
reassign_resource_email
(
merge_request
,
merge_request
.
target_project
,
current_user
,
:reassigned_merge_request_email
)
end
end
# When we add labels to a merge request we should send an email to:
# When we add labels to a merge request we should send an email to:
...
@@ -85,15 +90,15 @@ class NotificationService
...
@@ -85,15 +90,15 @@ class NotificationService
# * watchers of the mr's labels
# * watchers of the mr's labels
#
#
def
relabeled_merge_request
(
merge_request
,
added_labels
,
current_user
)
def
relabeled_merge_request
(
merge_request
,
added_labels
,
current_user
)
relabeled_resource_email
(
merge_request
,
added_labels
,
current_user
,
'relabeled_merge_request_email'
)
relabeled_resource_email
(
merge_request
,
added_labels
,
current_user
,
:relabeled_merge_request_email
)
end
end
def
close_mr
(
merge_request
,
current_user
)
def
close_mr
(
merge_request
,
current_user
)
close_resource_email
(
merge_request
,
merge_request
.
target_project
,
current_user
,
'closed_merge_request_email'
)
close_resource_email
(
merge_request
,
merge_request
.
target_project
,
current_user
,
:closed_merge_request_email
)
end
end
def
reopen_issue
(
issue
,
current_user
)
def
reopen_issue
(
issue
,
current_user
)
reopen_resource_email
(
issue
,
issue
.
project
,
current_user
,
'issue_status_changed_email'
,
'reopened'
)
reopen_resource_email
(
issue
,
issue
.
project
,
current_user
,
:issue_status_changed_email
,
'reopened'
)
end
end
def
merge_mr
(
merge_request
,
current_user
)
def
merge_mr
(
merge_request
,
current_user
)
...
@@ -101,7 +106,7 @@ class NotificationService
...
@@ -101,7 +106,7 @@ class NotificationService
merge_request
,
merge_request
,
merge_request
.
target_project
,
merge_request
.
target_project
,
current_user
,
current_user
,
'merged_merge_request_email'
:merged_merge_request_email
)
)
end
end
...
@@ -110,7 +115,7 @@ class NotificationService
...
@@ -110,7 +115,7 @@ class NotificationService
merge_request
,
merge_request
,
merge_request
.
target_project
,
merge_request
.
target_project
,
current_user
,
current_user
,
'merge_request_status_email'
,
:merge_request_status_email
,
'reopened'
'reopened'
)
)
end
end
...
@@ -153,6 +158,9 @@ class NotificationService
...
@@ -153,6 +158,9 @@ class NotificationService
# Merge project watchers
# Merge project watchers
recipients
=
add_project_watchers
(
recipients
,
note
.
project
)
recipients
=
add_project_watchers
(
recipients
,
note
.
project
)
# Merge project with custom notification
recipients
=
add_project_custom_notifications
(
recipients
,
note
.
project
,
:new_note
)
# Reject users with Mention notification level, except those mentioned in _this_ note.
# Reject users with Mention notification level, except those mentioned in _this_ note.
recipients
=
reject_mention_users
(
recipients
-
mentioned_users
,
note
.
project
)
recipients
=
reject_mention_users
(
recipients
-
mentioned_users
,
note
.
project
)
recipients
=
recipients
+
mentioned_users
recipients
=
recipients
+
mentioned_users
...
@@ -268,12 +276,22 @@ class NotificationService
...
@@ -268,12 +276,22 @@ class NotificationService
protected
protected
# Get project/group users with CUSTOM notification level
def
add_project_custom_notifications
(
recipients
,
project
,
action
)
user_ids
=
[]
user_ids
+=
notification_settings_for
(
project
,
:custom
,
action
)
user_ids
+=
notification_settings_for
(
project
.
group
,
:custom
,
action
)
recipients
.
concat
(
User
.
find
(
user_ids
))
end
# Get project users with WATCH notification level
# Get project users with WATCH notification level
def
project_watchers
(
project
)
def
project_watchers
(
project
)
project_members
=
project_member_notification
(
project
)
project_members
=
notification_settings_for
(
project
)
users_with_project_level_global
=
project_member_notification
(
project
,
:global
)
users_with_project_level_global
=
notification_settings_for
(
project
,
:global
)
users_with_group_level_global
=
group_member_notification
(
project
,
:global
)
users_with_group_level_global
=
notification_settings_for
(
project
,
:global
)
users
=
users_with_global_level_watch
([
users_with_project_level_global
,
users_with_group_level_global
].
flatten
.
uniq
)
users
=
users_with_global_level_watch
([
users_with_project_level_global
,
users_with_group_level_global
].
flatten
.
uniq
)
users_with_project_setting
=
select_project_member_setting
(
project
,
users_with_project_level_global
,
users
)
users_with_project_setting
=
select_project_member_setting
(
project
,
users_with_project_level_global
,
users
)
...
@@ -282,19 +300,15 @@ class NotificationService
...
@@ -282,19 +300,15 @@ class NotificationService
User
.
where
(
id:
users_with_project_setting
.
concat
(
users_with_group_setting
).
uniq
).
to_a
User
.
where
(
id:
users_with_project_setting
.
concat
(
users_with_group_setting
).
uniq
).
to_a
end
end
def
project_member_notification
(
project
,
notification_level
=
nil
)
def
notification_settings_for
(
resource
,
notification_level
=
nil
,
action
=
nil
)
if
notification_level
return
[]
unless
resource
project
.
notification_settings
.
where
(
level:
NotificationSetting
.
levels
[
notification_level
]).
pluck
(
:user_id
)
else
project
.
notification_settings
.
pluck
(
:user_id
)
end
end
def
group_member_notification
(
project
,
notification_level
)
if
notification_level
if
project
.
group
settings
=
resource
.
notification_settings
.
where
(
level:
NotificationSetting
.
levels
[
notification_level
])
project
.
group
.
notification_settings
.
where
(
level:
NotificationSetting
.
levels
[
notification_level
]).
pluck
(
:user_id
)
settings
=
settings
.
select
{
|
setting
|
setting
.
events
[
action
]
}
if
action
.
present?
settings
.
map
(
&
:user_id
)
else
else
[]
resource
.
notification_settings
.
pluck
(
:user_id
)
end
end
end
end
...
@@ -308,7 +322,7 @@ class NotificationService
...
@@ -308,7 +322,7 @@ class NotificationService
# Build a list of users based on project notifcation settings
# Build a list of users based on project notifcation settings
def
select_project_member_setting
(
project
,
global_setting
,
users_global_level_watch
)
def
select_project_member_setting
(
project
,
global_setting
,
users_global_level_watch
)
users
=
project_member_notification
(
project
,
:watch
)
users
=
notification_settings_for
(
project
,
:watch
)
# If project setting is global, add to watch list if global setting is watch
# If project setting is global, add to watch list if global setting is watch
global_setting
.
each
do
|
user_id
|
global_setting
.
each
do
|
user_id
|
...
@@ -322,7 +336,7 @@ class NotificationService
...
@@ -322,7 +336,7 @@ class NotificationService
# Build a list of users based on group notification settings
# Build a list of users based on group notification settings
def
select_group_member_setting
(
project
,
project_members
,
global_setting
,
users_global_level_watch
)
def
select_group_member_setting
(
project
,
project_members
,
global_setting
,
users_global_level_watch
)
uids
=
group_member_notification
(
project
,
:watch
)
uids
=
notification_settings_for
(
project
,
:watch
)
# Group setting is watch, add to users list if user is not project member
# Group setting is watch, add to users list if user is not project member
users
=
[]
users
=
[]
...
@@ -343,7 +357,7 @@ class NotificationService
...
@@ -343,7 +357,7 @@ class NotificationService
end
end
def
add_project_watchers
(
recipients
,
project
)
def
add_project_watchers
(
recipients
,
project
)
recipients
.
concat
(
project_watchers
(
project
)).
compact
.
uniq
recipients
.
concat
(
project_watchers
(
project
)).
compact
end
end
# Remove users with disabled notifications from array
# Remove users with disabled notifications from array
...
@@ -428,7 +442,7 @@ class NotificationService
...
@@ -428,7 +442,7 @@ class NotificationService
end
end
def
new_resource_email
(
target
,
project
,
method
)
def
new_resource_email
(
target
,
project
,
method
)
recipients
=
build_recipients
(
target
,
project
,
target
.
author
,
action:
:new
)
recipients
=
build_recipients
(
target
,
project
,
target
.
author
,
action:
"new"
)
recipients
.
each
do
|
recipient
|
recipients
.
each
do
|
recipient
|
mailer
.
send
(
method
,
recipient
.
id
,
target
.
id
).
deliver_later
mailer
.
send
(
method
,
recipient
.
id
,
target
.
id
).
deliver_later
...
@@ -436,7 +450,8 @@ class NotificationService
...
@@ -436,7 +450,8 @@ class NotificationService
end
end
def
close_resource_email
(
target
,
project
,
current_user
,
method
)
def
close_resource_email
(
target
,
project
,
current_user
,
method
)
recipients
=
build_recipients
(
target
,
project
,
current_user
)
action
=
method
==
:merged_merge_request_email
?
"merge"
:
"close"
recipients
=
build_recipients
(
target
,
project
,
current_user
,
action:
action
)
recipients
.
each
do
|
recipient
|
recipients
.
each
do
|
recipient
|
mailer
.
send
(
method
,
recipient
.
id
,
target
.
id
,
current_user
.
id
).
deliver_later
mailer
.
send
(
method
,
recipient
.
id
,
target
.
id
,
current_user
.
id
).
deliver_later
...
@@ -447,7 +462,7 @@ class NotificationService
...
@@ -447,7 +462,7 @@ class NotificationService
previous_assignee_id
=
previous_record
(
target
,
'assignee_id'
)
previous_assignee_id
=
previous_record
(
target
,
'assignee_id'
)
previous_assignee
=
User
.
find_by
(
id:
previous_assignee_id
)
if
previous_assignee_id
previous_assignee
=
User
.
find_by
(
id:
previous_assignee_id
)
if
previous_assignee_id
recipients
=
build_recipients
(
target
,
project
,
current_user
,
action:
:reassign
,
previous_assignee:
previous_assignee
)
recipients
=
build_recipients
(
target
,
project
,
current_user
,
action:
"reassign"
,
previous_assignee:
previous_assignee
)
recipients
.
each
do
|
recipient
|
recipients
.
each
do
|
recipient
|
mailer
.
send
(
mailer
.
send
(
...
@@ -470,7 +485,7 @@ class NotificationService
...
@@ -470,7 +485,7 @@ class NotificationService
end
end
def
reopen_resource_email
(
target
,
project
,
current_user
,
method
,
status
)
def
reopen_resource_email
(
target
,
project
,
current_user
,
method
,
status
)
recipients
=
build_recipients
(
target
,
project
,
current_user
)
recipients
=
build_recipients
(
target
,
project
,
current_user
,
action:
"reopen"
)
recipients
.
each
do
|
recipient
|
recipients
.
each
do
|
recipient
|
mailer
.
send
(
method
,
recipient
.
id
,
target
.
id
,
status
,
current_user
.
id
).
deliver_later
mailer
.
send
(
method
,
recipient
.
id
,
target
.
id
,
status
,
current_user
.
id
).
deliver_later
...
@@ -478,14 +493,19 @@ class NotificationService
...
@@ -478,14 +493,19 @@ class NotificationService
end
end
def
build_recipients
(
target
,
project
,
current_user
,
action:
nil
,
previous_assignee:
nil
)
def
build_recipients
(
target
,
project
,
current_user
,
action:
nil
,
previous_assignee:
nil
)
custom_action
=
build_custom_key
(
action
,
target
)
recipients
=
target
.
participants
(
current_user
)
recipients
=
target
.
participants
(
current_user
)
recipients
=
add_project_watchers
(
recipients
,
project
)
recipients
=
add_project_watchers
(
recipients
,
project
)
recipients
=
add_project_custom_notifications
(
recipients
,
project
,
custom_action
)
recipients
=
reject_mention_users
(
recipients
,
project
)
recipients
=
reject_mention_users
(
recipients
,
project
)
recipients
=
recipients
.
uniq
# Re-assign is considered as a mention of the new assignee so we add the
# Re-assign is considered as a mention of the new assignee so we add the
# new assignee to the list of recipients after we rejected users with
# new assignee to the list of recipients after we rejected users with
# the "on mention" notification level
# the "on mention" notification level
if
action
==
:reassign
if
[
:reassign_merge_request
,
:reassign_issue
].
include?
(
custom_action
)
recipients
<<
previous_assignee
if
previous_assignee
recipients
<<
previous_assignee
if
previous_assignee
recipients
<<
target
.
assignee
recipients
<<
target
.
assignee
end
end
...
@@ -493,7 +513,7 @@ class NotificationService
...
@@ -493,7 +513,7 @@ class NotificationService
recipients
=
reject_muted_users
(
recipients
,
project
)
recipients
=
reject_muted_users
(
recipients
,
project
)
recipients
=
add_subscribed_users
(
recipients
,
target
)
recipients
=
add_subscribed_users
(
recipients
,
target
)
if
action
==
:new
if
[
:new_issue
,
:new_merge_request
].
include?
(
custom_action
)
recipients
=
add_labels_subscribers
(
recipients
,
target
)
recipients
=
add_labels_subscribers
(
recipients
,
target
)
end
end
...
@@ -523,4 +543,10 @@ class NotificationService
...
@@ -523,4 +543,10 @@ class NotificationService
end
end
end
end
end
end
# Build event key to search on custom notification level
# Check NotificationSetting::EMAIL_EVENTS
def
build_custom_key
(
action
,
object
)
"
#{
action
}
_
#{
object
.
class
.
name
.
underscore
}
"
.
to_sym
end
end
end
app/views/projects/buttons/_notifications.html.haml
View file @
89a2c873
-
if
@notification_setting
-
if
@notification_setting
=
form_for
@notification_setting
,
url:
namespace_project_notification_setting_path
(
@project
.
namespace
.
becomes
(
Namespace
),
@project
),
method: :patch
,
remote:
true
,
html:
{
class:
'inline'
,
id:
'notification-form'
}
do
|
f
|
.dropdown.notification-dropdown.pull-right
=
f
.
hidden_field
:level
=
form_for
@notification_setting
,
url:
namespace_project_notification_setting_path
(
@project
.
namespace
.
becomes
(
Namespace
),
@project
),
method: :patch
,
remote:
true
,
html:
{
class:
"inline"
,
id:
"notification-form"
}
do
|
f
|
.dropdown.hidden-sm
=
f
.
hidden_field
:level
%button
.btn.btn-default.notifications-btn
#notifications-button
{
data:
{
toggle:
"dropdown"
},
aria:
{
haspopup:
"true"
,
expanded:
"false"
}
}
.js-notification-toggle-btns
=
icon
(
'bell'
)
-
if
@notification_setting
.
custom?
=
notification_title
(
@notification_setting
.
level
)
.btn-group
=
icon
(
'caret-down'
)
%button
.dropdown-new.btn.btn-default.notifications-btn
#notifications-button
{
type:
"button"
,
data:
{
toggle:
"modal"
,
target:
"#custom-notifications-modal"
}
}
%ul
.dropdown-menu.dropdown-menu-no-wrap.dropdown-menu-align-right.dropdown-menu-selectable.dropdown-menu-large
{
role:
"menu"
}
=
icon
(
"bell"
,
class:
"js-notification-loading"
)
-
NotificationSetting
.
levels
.
each
do
|
level
|
=
notification_title
(
@notification_setting
.
level
)
=
notification_list_item
(
level
.
first
,
@notification_setting
)
%button
.btn.btn-danger.dropdown-toggle
{
data:
{
toggle:
"dropdown"
,
target:
".notification-dropdown"
}
}
%span
.caret
.sr-only
Toggle dropdown
-
else
%button
.dropdown-new.btn.btn-default.notifications-btn
#notifications-button
{
type:
"button"
,
data:
{
toggle:
"dropdown"
,
target:
".notification-dropdown"
}
}
=
icon
(
"bell"
,
class:
"js-notification-loading"
)
=
notification_title
(
@notification_setting
.
level
)
=
icon
(
"caret-down"
)
=
render
"shared/projects/notification_dropdown"
=
content_for
:scripts_body
do
=
render
"shared/projects/custom_notifications"
app/views/shared/projects/_custom_notifications.html.haml
0 → 100644
View file @
89a2c873
#custom-notifications-modal
.modal.fade
{
tabindex:
"-1"
,
role:
"dialog"
,
aria:
{
labelledby:
"custom-notifications-title"
}
}
.modal-dialog
.modal-content
.modal-header
%button
.close
{
type:
"button"
,
data:
{
dismiss:
"modal"
},
aria:
{
label:
"close"
}
}
%span
{
aria:
{
hidden:
"true"
}
}
×
%h4
#custom-notifications-title
.modal-title
Custom notification events
.modal-body
.container-fluid
=
form_for
@notification_setting
,
url:
namespace_project_notification_setting_path
(
@project
.
namespace
.
becomes
(
Namespace
),
@project
),
method: :patch
,
html:
{
class:
"custom-notifications-form"
}
do
|
f
|
.row
.col-lg-3
%h4
.prepend-top-0
Notification events
.col-lg-9
-
NotificationSetting
::
EMAIL_EVENTS
.
each
do
|
event
,
index
|
=
index
.form-group
.checkbox
{
class:
(
"prepend-top-0"
if
index
==
0
)
}
%label
{
for:
"events_#{event}"
}
=
check_box
(
"notification_setting"
,
event
,
{
id:
"events_
#{
event
}
"
,
class:
"js-custom-notification-event"
})
%strong
=
event
.
to_s
.
humanize
=
icon
(
"spinner spin"
,
class:
"custom-notification-event-loading"
)
app/views/shared/projects/_notification_dropdown.html.haml
0 → 100644
View file @
89a2c873
%ul
.dropdown-menu.dropdown-menu-no-wrap.dropdown-menu-align-right.dropdown-menu-selectable.dropdown-menu-large
{
role:
"menu"
}
-
NotificationSetting
.
levels
.
each
do
|
level
|
-
if
level
.
first
!=
"custom"
=
notification_list_item
(
level
.
first
,
@notification_setting
)
-
unless
@notification_setting
.
custom?
%li
.divider
%li
%a
.update-notification
{
href:
"#"
,
role:
"button"
,
data:
{
toggle:
"modal"
,
target:
"#custom-notifications-modal"
,
notification_level:
"custom"
,
notification_title:
"Custom"
}
}
Custom
db/migrate/20160614301627_add_events_to_notification_settings.rb
0 → 100644
View file @
89a2c873
class
AddEventsToNotificationSettings
<
ActiveRecord
::
Migration
include
Gitlab
::
Database
::
MigrationHelpers
def
change
add_column
:notification_settings
,
:events
,
:text
end
end
doc/workflow/notifications.md
View file @
89a2c873
...
@@ -4,7 +4,7 @@ GitLab has a notification system in place to notify a user of events that are im
...
@@ -4,7 +4,7 @@ GitLab has a notification system in place to notify a user of events that are im
## Notification settings
## Notification settings
Under user profile page you can find the notification settings
.
You can find notification settings under the user profile
.
![
notification settings
](
notifications/settings.png
)
![
notification settings
](
notifications/settings.png
)
...
@@ -20,6 +20,7 @@ Each of these settings have levels of notification:
...
@@ -20,6 +20,7 @@ Each of these settings have levels of notification:
*
Participating - receive notifications from related resources
*
Participating - receive notifications from related resources
*
Watch - receive notifications from projects or groups user is a member of
*
Watch - receive notifications from projects or groups user is a member of
*
Global - notifications as set at the global settings
*
Global - notifications as set at the global settings
*
Custom - Notification is set based on events selected by the user.(Available only in project level)
#### Global Settings
#### Global Settings
...
@@ -55,7 +56,7 @@ Below is the table of events users can be notified of:
...
@@ -55,7 +56,7 @@ Below is the table of events users can be notified of:
| User added to project | User | Sent when user is added to project |
| User added to project | User | Sent when user is added to project |
| Project access level changed | User | Sent when user project access level is changed |
| Project access level changed | User | Sent when user project access level is changed |
| User added to group | User | Sent when user is added to group |
| User added to group | User | Sent when user is added to group |
| Group access level changed | User | Sent when user group access level is changed |
| Group access level changed | User | Sent when user group access level is changed |
| Project moved | Project members [1] | [1] not disabled |
| Project moved | Project members [1] | [1] not disabled |
### Issue / Merge Request events
### Issue / Merge Request events
...
@@ -71,6 +72,7 @@ In all of the below cases, the notification will be sent to:
...
@@ -71,6 +72,7 @@ In all of the below cases, the notification will be sent to:
-
Watchers: users with notification level "Watch"
-
Watchers: users with notification level "Watch"
-
Subscribers: anyone who manually subscribed to the issue/merge request
-
Subscribers: anyone who manually subscribed to the issue/merge request
-
Custom: Users with notification level "custom" who turned on notifications for any of the events present in the table below
| Event | Sent to |
| Event | Sent to |
|------------------------|---------|
|------------------------|---------|
...
...
doc/workflow/notifications/settings.png
View replaced file @
8bfbafbb
View file @
89a2c873
112 KB
|
W:
|
H:
86.1 KB
|
W:
|
H:
2-up
Swipe
Onion skin
features/steps/project/project.rb
View file @
89a2c873
...
@@ -126,7 +126,7 @@ class Spinach::Features::Project < Spinach::FeatureSteps
...
@@ -126,7 +126,7 @@ class Spinach::Features::Project < Spinach::FeatureSteps
end
end
step
'I click notifications drop down button'
do
step
'I click notifications drop down button'
do
fi
nd
(
'#notifications-butto
n'
).
click
fi
rst
(
'.notifications-bt
n'
).
click
end
end
step
'I choose Mention setting'
do
step
'I choose Mention setting'
do
...
...
spec/controllers/projects/notification_settings_controller_spec.rb
View file @
89a2c873
...
@@ -33,6 +33,25 @@ describe Projects::NotificationSettingsController do
...
@@ -33,6 +33,25 @@ describe Projects::NotificationSettingsController do
expect
(
response
.
status
).
to
eq
200
expect
(
response
.
status
).
to
eq
200
end
end
context
'and setting custom notification setting'
do
let
(
:custom_events
)
do
events
=
{}
NotificationSetting
::
EMAIL_EVENTS
.
each
do
|
event
|
events
[
event
]
=
"true"
end
end
it
'returns success'
do
put
:update
,
namespace_id:
project
.
namespace
.
to_param
,
project_id:
project
.
to_param
,
notification_setting:
{
level: :participating
,
events:
custom_events
}
expect
(
response
.
status
).
to
eq
200
end
end
end
end
context
'not authorized'
do
context
'not authorized'
do
...
...
spec/models/notification_setting_spec.rb
View file @
89a2c873
...
@@ -12,5 +12,30 @@ RSpec.describe NotificationSetting, type: :model do
...
@@ -12,5 +12,30 @@ RSpec.describe NotificationSetting, type: :model do
it
{
is_expected
.
to
validate_presence_of
(
:user
)
}
it
{
is_expected
.
to
validate_presence_of
(
:user
)
}
it
{
is_expected
.
to
validate_presence_of
(
:level
)
}
it
{
is_expected
.
to
validate_presence_of
(
:level
)
}
it
{
is_expected
.
to
validate_uniqueness_of
(
:user_id
).
scoped_to
([
:source_id
,
:source_type
]).
with_message
(
/already exists in source/
)
}
it
{
is_expected
.
to
validate_uniqueness_of
(
:user_id
).
scoped_to
([
:source_id
,
:source_type
]).
with_message
(
/already exists in source/
)
}
context
"events"
do
let
(
:user
)
{
create
(
:user
)
}
let
(
:notification_setting
)
{
NotificationSetting
.
new
(
source_id:
1
,
source_type:
'Project'
,
user_id:
user
.
id
)
}
before
do
notification_setting
.
level
=
"custom"
notification_setting
.
new_note
=
"true"
notification_setting
.
new_issue
=
1
notification_setting
.
close_issue
=
"1"
notification_setting
.
merge_merge_request
=
"t"
notification_setting
.
close_merge_request
=
"nil"
notification_setting
.
reopen_merge_request
=
"false"
notification_setting
.
save
end
it
"parses boolean before saving"
do
expect
(
notification_setting
.
new_note
).
to
eq
(
true
)
expect
(
notification_setting
.
new_issue
).
to
eq
(
true
)
expect
(
notification_setting
.
close_issue
).
to
eq
(
true
)
expect
(
notification_setting
.
merge_merge_request
).
to
eq
(
true
)
expect
(
notification_setting
.
close_merge_request
).
to
eq
(
false
)
expect
(
notification_setting
.
reopen_merge_request
).
to
eq
(
false
)
end
end
end
end
end
end
spec/services/notification_service_spec.rb
View file @
89a2c873
...
@@ -46,6 +46,7 @@ describe NotificationService, services: true do
...
@@ -46,6 +46,7 @@ describe NotificationService, services: true do
project
.
team
<<
[
issue
.
assignee
,
:master
]
project
.
team
<<
[
issue
.
assignee
,
:master
]
project
.
team
<<
[
note
.
author
,
:master
]
project
.
team
<<
[
note
.
author
,
:master
]
create
(
:note_on_issue
,
noteable:
issue
,
project_id:
issue
.
project_id
,
note:
'@subscribed_participant cc this guy'
)
create
(
:note_on_issue
,
noteable:
issue
,
project_id:
issue
.
project_id
,
note:
'@subscribed_participant cc this guy'
)
update_custom_notification
(
:new_note
)
end
end
describe
:new_note
do
describe
:new_note
do
...
@@ -66,6 +67,7 @@ describe NotificationService, services: true do
...
@@ -66,6 +67,7 @@ describe NotificationService, services: true do
should_email
(
@subscriber
)
should_email
(
@subscriber
)
should_email
(
@watcher_and_subscriber
)
should_email
(
@watcher_and_subscriber
)
should_email
(
@subscribed_participant
)
should_email
(
@subscribed_participant
)
should_not_email
(
@u_guest_custom
)
should_not_email
(
@u_guest_watcher
)
should_not_email
(
@u_guest_watcher
)
should_not_email
(
note
.
author
)
should_not_email
(
note
.
author
)
should_not_email
(
@u_participating
)
should_not_email
(
@u_participating
)
...
@@ -116,6 +118,7 @@ describe NotificationService, services: true do
...
@@ -116,6 +118,7 @@ describe NotificationService, services: true do
should_email
(
note
.
noteable
.
author
)
should_email
(
note
.
noteable
.
author
)
should_email
(
note
.
noteable
.
assignee
)
should_email
(
note
.
noteable
.
assignee
)
should_email
(
@u_mentioned
)
should_email
(
@u_mentioned
)
should_not_email
(
@u_guest_custom
)
should_not_email
(
@u_guest_watcher
)
should_not_email
(
@u_guest_watcher
)
should_not_email
(
@u_watcher
)
should_not_email
(
@u_watcher
)
should_not_email
(
note
.
author
)
should_not_email
(
note
.
author
)
...
@@ -241,13 +244,14 @@ describe NotificationService, services: true do
...
@@ -241,13 +244,14 @@ describe NotificationService, services: true do
build_team
(
note
.
project
)
build_team
(
note
.
project
)
ActionMailer
::
Base
.
deliveries
.
clear
ActionMailer
::
Base
.
deliveries
.
clear
allow_any_instance_of
(
Commit
).
to
receive
(
:author
).
and_return
(
@u_committer
)
allow_any_instance_of
(
Commit
).
to
receive
(
:author
).
and_return
(
@u_committer
)
update_custom_notification
(
:new_note
)
end
end
describe
'#new_note, #perform_enqueued_jobs'
do
describe
'#new_note, #perform_enqueued_jobs'
do
it
do
it
do
notification
.
new_note
(
note
)
notification
.
new_note
(
note
)
should_email
(
@u_guest_watcher
)
should_email
(
@u_guest_watcher
)
should_email
(
@u_guest_custom
)
should_email
(
@u_committer
)
should_email
(
@u_committer
)
should_email
(
@u_watcher
)
should_email
(
@u_watcher
)
should_not_email
(
@u_mentioned
)
should_not_email
(
@u_mentioned
)
...
@@ -288,6 +292,7 @@ describe NotificationService, services: true do
...
@@ -288,6 +292,7 @@ describe NotificationService, services: true do
build_team
(
issue
.
project
)
build_team
(
issue
.
project
)
add_users_with_subscription
(
issue
.
project
,
issue
)
add_users_with_subscription
(
issue
.
project
,
issue
)
ActionMailer
::
Base
.
deliveries
.
clear
ActionMailer
::
Base
.
deliveries
.
clear
update_custom_notification
(
:new_issue
)
end
end
describe
'#new_issue'
do
describe
'#new_issue'
do
...
@@ -297,6 +302,7 @@ describe NotificationService, services: true do
...
@@ -297,6 +302,7 @@ describe NotificationService, services: true do
should_email
(
issue
.
assignee
)
should_email
(
issue
.
assignee
)
should_email
(
@u_watcher
)
should_email
(
@u_watcher
)
should_email
(
@u_guest_watcher
)
should_email
(
@u_guest_watcher
)
should_email
(
@u_guest_custom
)
should_email
(
@u_participant_mentioned
)
should_email
(
@u_participant_mentioned
)
should_not_email
(
@u_mentioned
)
should_not_email
(
@u_mentioned
)
should_not_email
(
@u_participating
)
should_not_email
(
@u_participating
)
...
@@ -356,12 +362,15 @@ describe NotificationService, services: true do
...
@@ -356,12 +362,15 @@ describe NotificationService, services: true do
end
end
describe
'#reassigned_issue'
do
describe
'#reassigned_issue'
do
before
{
update_custom_notification
(
:reassign_issue
)
}
it
'emails new assignee'
do
it
'emails new assignee'
do
notification
.
reassigned_issue
(
issue
,
@u_disabled
)
notification
.
reassigned_issue
(
issue
,
@u_disabled
)
should_email
(
issue
.
assignee
)
should_email
(
issue
.
assignee
)
should_email
(
@u_watcher
)
should_email
(
@u_watcher
)
should_email
(
@u_guest_watcher
)
should_email
(
@u_guest_watcher
)
should_email
(
@u_guest_custom
)
should_email
(
@u_participant_mentioned
)
should_email
(
@u_participant_mentioned
)
should_email
(
@subscriber
)
should_email
(
@subscriber
)
should_not_email
(
@unsubscriber
)
should_not_email
(
@unsubscriber
)
...
@@ -378,6 +387,7 @@ describe NotificationService, services: true do
...
@@ -378,6 +387,7 @@ describe NotificationService, services: true do
should_email
(
@u_mentioned
)
should_email
(
@u_mentioned
)
should_email
(
@u_watcher
)
should_email
(
@u_watcher
)
should_email
(
@u_guest_watcher
)
should_email
(
@u_guest_watcher
)
should_email
(
@u_guest_custom
)
should_email
(
@u_participant_mentioned
)
should_email
(
@u_participant_mentioned
)
should_email
(
@subscriber
)
should_email
(
@subscriber
)
should_not_email
(
@unsubscriber
)
should_not_email
(
@unsubscriber
)
...
@@ -394,6 +404,7 @@ describe NotificationService, services: true do
...
@@ -394,6 +404,7 @@ describe NotificationService, services: true do
should_email
(
issue
.
assignee
)
should_email
(
issue
.
assignee
)
should_email
(
@u_watcher
)
should_email
(
@u_watcher
)
should_email
(
@u_guest_watcher
)
should_email
(
@u_guest_watcher
)
should_email
(
@u_guest_custom
)
should_email
(
@u_participant_mentioned
)
should_email
(
@u_participant_mentioned
)
should_email
(
@subscriber
)
should_email
(
@subscriber
)
should_not_email
(
@unsubscriber
)
should_not_email
(
@unsubscriber
)
...
@@ -410,6 +421,7 @@ describe NotificationService, services: true do
...
@@ -410,6 +421,7 @@ describe NotificationService, services: true do
should_email
(
issue
.
assignee
)
should_email
(
issue
.
assignee
)
should_email
(
@u_watcher
)
should_email
(
@u_watcher
)
should_email
(
@u_guest_watcher
)
should_email
(
@u_guest_watcher
)
should_email
(
@u_guest_custom
)
should_email
(
@u_participant_mentioned
)
should_email
(
@u_participant_mentioned
)
should_email
(
@subscriber
)
should_email
(
@subscriber
)
should_not_email
(
@unsubscriber
)
should_not_email
(
@unsubscriber
)
...
@@ -425,6 +437,7 @@ describe NotificationService, services: true do
...
@@ -425,6 +437,7 @@ describe NotificationService, services: true do
expect
(
issue
.
assignee
).
to
be
@u_mentioned
expect
(
issue
.
assignee
).
to
be
@u_mentioned
should_email
(
@u_watcher
)
should_email
(
@u_watcher
)
should_email
(
@u_guest_watcher
)
should_email
(
@u_guest_watcher
)
should_email
(
@u_guest_custom
)
should_email
(
@u_participant_mentioned
)
should_email
(
@u_participant_mentioned
)
should_email
(
@subscriber
)
should_email
(
@subscriber
)
should_not_email
(
issue
.
assignee
)
should_not_email
(
issue
.
assignee
)
...
@@ -529,6 +542,8 @@ describe NotificationService, services: true do
...
@@ -529,6 +542,8 @@ describe NotificationService, services: true do
end
end
describe
'#close_issue'
do
describe
'#close_issue'
do
before
{
update_custom_notification
(
:close_issue
)
}
it
'should sent email to issue assignee and issue author'
do
it
'should sent email to issue assignee and issue author'
do
notification
.
close_issue
(
issue
,
@u_disabled
)
notification
.
close_issue
(
issue
,
@u_disabled
)
...
@@ -536,6 +551,7 @@ describe NotificationService, services: true do
...
@@ -536,6 +551,7 @@ describe NotificationService, services: true do
should_email
(
issue
.
author
)
should_email
(
issue
.
author
)
should_email
(
@u_watcher
)
should_email
(
@u_watcher
)
should_email
(
@u_guest_watcher
)
should_email
(
@u_guest_watcher
)
should_email
(
@u_guest_custom
)
should_email
(
@u_participant_mentioned
)
should_email
(
@u_participant_mentioned
)
should_email
(
@subscriber
)
should_email
(
@subscriber
)
should_email
(
@watcher_and_subscriber
)
should_email
(
@watcher_and_subscriber
)
...
@@ -575,6 +591,8 @@ describe NotificationService, services: true do
...
@@ -575,6 +591,8 @@ describe NotificationService, services: true do
end
end
describe
'#reopen_issue'
do
describe
'#reopen_issue'
do
before
{
update_custom_notification
(
:reopen_issue
)
}
it
'should send email to issue assignee and issue author'
do
it
'should send email to issue assignee and issue author'
do
notification
.
reopen_issue
(
issue
,
@u_disabled
)
notification
.
reopen_issue
(
issue
,
@u_disabled
)
...
@@ -582,6 +600,7 @@ describe NotificationService, services: true do
...
@@ -582,6 +600,7 @@ describe NotificationService, services: true do
should_email
(
issue
.
author
)
should_email
(
issue
.
author
)
should_email
(
@u_watcher
)
should_email
(
@u_watcher
)
should_email
(
@u_guest_watcher
)
should_email
(
@u_guest_watcher
)
should_email
(
@u_guest_custom
)
should_email
(
@u_participant_mentioned
)
should_email
(
@u_participant_mentioned
)
should_email
(
@subscriber
)
should_email
(
@subscriber
)
should_email
(
@watcher_and_subscriber
)
should_email
(
@watcher_and_subscriber
)
...
@@ -631,6 +650,8 @@ describe NotificationService, services: true do
...
@@ -631,6 +650,8 @@ describe NotificationService, services: true do
end
end
describe
'#new_merge_request'
do
describe
'#new_merge_request'
do
before
{
update_custom_notification
(
:new_merge_request
)
}
it
do
it
do
notification
.
new_merge_request
(
merge_request
,
@u_disabled
)
notification
.
new_merge_request
(
merge_request
,
@u_disabled
)
...
@@ -639,6 +660,7 @@ describe NotificationService, services: true do
...
@@ -639,6 +660,7 @@ describe NotificationService, services: true do
should_email
(
@watcher_and_subscriber
)
should_email
(
@watcher_and_subscriber
)
should_email
(
@u_participant_mentioned
)
should_email
(
@u_participant_mentioned
)
should_email
(
@u_guest_watcher
)
should_email
(
@u_guest_watcher
)
should_email
(
@u_guest_custom
)
should_not_email
(
@u_participating
)
should_not_email
(
@u_participating
)
should_not_email
(
@u_disabled
)
should_not_email
(
@u_disabled
)
should_not_email
(
@u_lazy_participant
)
should_not_email
(
@u_lazy_participant
)
...
@@ -685,6 +707,8 @@ describe NotificationService, services: true do
...
@@ -685,6 +707,8 @@ describe NotificationService, services: true do
end
end
describe
'#reassigned_merge_request'
do
describe
'#reassigned_merge_request'
do
before
{
update_custom_notification
(
:reassign_merge_request
)
}
it
do
it
do
notification
.
reassigned_merge_request
(
merge_request
,
merge_request
.
author
)
notification
.
reassigned_merge_request
(
merge_request
,
merge_request
.
author
)
...
@@ -694,6 +718,7 @@ describe NotificationService, services: true do
...
@@ -694,6 +718,7 @@ describe NotificationService, services: true do
should_email
(
@subscriber
)
should_email
(
@subscriber
)
should_email
(
@watcher_and_subscriber
)
should_email
(
@watcher_and_subscriber
)
should_email
(
@u_guest_watcher
)
should_email
(
@u_guest_watcher
)
should_email
(
@u_guest_custom
)
should_not_email
(
@unsubscriber
)
should_not_email
(
@unsubscriber
)
should_not_email
(
@u_participating
)
should_not_email
(
@u_participating
)
should_not_email
(
@u_disabled
)
should_not_email
(
@u_disabled
)
...
@@ -761,12 +786,15 @@ describe NotificationService, services: true do
...
@@ -761,12 +786,15 @@ describe NotificationService, services: true do
end
end
describe
'#closed_merge_request'
do
describe
'#closed_merge_request'
do
before
{
update_custom_notification
(
:close_merge_request
)
}
it
do
it
do
notification
.
close_mr
(
merge_request
,
@u_disabled
)
notification
.
close_mr
(
merge_request
,
@u_disabled
)
should_email
(
merge_request
.
assignee
)
should_email
(
merge_request
.
assignee
)
should_email
(
@u_watcher
)
should_email
(
@u_watcher
)
should_email
(
@u_guest_watcher
)
should_email
(
@u_guest_watcher
)
should_email
(
@u_guest_custom
)
should_email
(
@u_participant_mentioned
)
should_email
(
@u_participant_mentioned
)
should_email
(
@subscriber
)
should_email
(
@subscriber
)
should_email
(
@watcher_and_subscriber
)
should_email
(
@watcher_and_subscriber
)
...
@@ -807,6 +835,8 @@ describe NotificationService, services: true do
...
@@ -807,6 +835,8 @@ describe NotificationService, services: true do
end
end
describe
'#merged_merge_request'
do
describe
'#merged_merge_request'
do
before
{
update_custom_notification
(
:merge_merge_request
)
}
it
do
it
do
notification
.
merge_mr
(
merge_request
,
@u_disabled
)
notification
.
merge_mr
(
merge_request
,
@u_disabled
)
...
@@ -816,6 +846,7 @@ describe NotificationService, services: true do
...
@@ -816,6 +846,7 @@ describe NotificationService, services: true do
should_email
(
@subscriber
)
should_email
(
@subscriber
)
should_email
(
@watcher_and_subscriber
)
should_email
(
@watcher_and_subscriber
)
should_email
(
@u_guest_watcher
)
should_email
(
@u_guest_watcher
)
should_email
(
@u_guest_custom
)
should_not_email
(
@unsubscriber
)
should_not_email
(
@unsubscriber
)
should_not_email
(
@u_participating
)
should_not_email
(
@u_participating
)
should_not_email
(
@u_disabled
)
should_not_email
(
@u_disabled
)
...
@@ -853,6 +884,8 @@ describe NotificationService, services: true do
...
@@ -853,6 +884,8 @@ describe NotificationService, services: true do
end
end
describe
'#reopen_merge_request'
do
describe
'#reopen_merge_request'
do
before
{
update_custom_notification
(
:reopen_merge_request
)
}
it
do
it
do
notification
.
reopen_mr
(
merge_request
,
@u_disabled
)
notification
.
reopen_mr
(
merge_request
,
@u_disabled
)
...
@@ -862,6 +895,7 @@ describe NotificationService, services: true do
...
@@ -862,6 +895,7 @@ describe NotificationService, services: true do
should_email
(
@subscriber
)
should_email
(
@subscriber
)
should_email
(
@watcher_and_subscriber
)
should_email
(
@watcher_and_subscriber
)
should_email
(
@u_guest_watcher
)
should_email
(
@u_guest_watcher
)
should_email
(
@u_guest_custom
)
should_not_email
(
@unsubscriber
)
should_not_email
(
@unsubscriber
)
should_not_email
(
@u_participating
)
should_not_email
(
@u_participating
)
should_not_email
(
@u_disabled
)
should_not_email
(
@u_disabled
)
...
@@ -915,6 +949,7 @@ describe NotificationService, services: true do
...
@@ -915,6 +949,7 @@ describe NotificationService, services: true do
should_email
(
@u_participating
)
should_email
(
@u_participating
)
should_email
(
@u_lazy_participant
)
should_email
(
@u_lazy_participant
)
should_not_email
(
@u_guest_watcher
)
should_not_email
(
@u_guest_watcher
)
should_not_email
(
@u_guest_custom
)
should_not_email
(
@u_disabled
)
should_not_email
(
@u_disabled
)
end
end
end
end
...
@@ -935,7 +970,8 @@ describe NotificationService, services: true do
...
@@ -935,7 +970,8 @@ describe NotificationService, services: true do
# It should be treated with a :participating notification_level
# It should be treated with a :participating notification_level
@u_lazy_participant
=
create
(
:user
,
username:
'lazy-participant'
)
@u_lazy_participant
=
create
(
:user
,
username:
'lazy-participant'
)
create_guest_watcher
@u_guest_watcher
=
create_user_with_notification
(
:watch
,
'guest_watching'
)
@u_guest_custom
=
create_user_with_notification
(
:custom
,
'guest_custom'
)
project
.
team
<<
[
@u_watcher
,
:master
]
project
.
team
<<
[
@u_watcher
,
:master
]
project
.
team
<<
[
@u_participating
,
:master
]
project
.
team
<<
[
@u_participating
,
:master
]
...
@@ -955,10 +991,18 @@ describe NotificationService, services: true do
...
@@ -955,10 +991,18 @@ describe NotificationService, services: true do
user
user
end
end
def
create_guest_watcher
def
create_user_with_notification
(
level
,
username
)
@u_guest_watcher
=
create
(
:user
,
username:
'guest_watching'
)
user
=
create
(
:user
,
username:
username
)
setting
=
@u_guest_watcher
.
notification_settings_for
(
project
)
setting
=
user
.
notification_settings_for
(
project
)
setting
.
level
=
:watch
setting
.
level
=
level
setting
.
save
user
end
def
update_custom_notification
(
event
)
setting
=
@u_guest_custom
.
notification_settings_for
(
project
)
setting
.
events
[
event
]
=
true
setting
.
save
setting
.
save
end
end
...
...
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