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
Jérome Perrin
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
Expand all
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
This diff is collapsed.
Click to expand it.
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