Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Boxiang Sun
gitlab-ce
Commits
f8b54295
Commit
f8b54295
authored
Apr 01, 2014
by
Dmitriy Zaporozhets
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'honor_notification_level' into 'master'
Honor notification levels Fixes #1093
parents
a37f8fc6
109ab1a5
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
88 additions
and
25 deletions
+88
-25
app/services/notification_service.rb
app/services/notification_service.rb
+57
-21
spec/services/notification_service_spec.rb
spec/services/notification_service_spec.rb
+31
-4
No files found.
app/services/notification_service.rb
View file @
f8b54295
...
@@ -178,29 +178,29 @@ class NotificationService
...
@@ -178,29 +178,29 @@ class NotificationService
# Get project users with WATCH notification level
# Get project users with WATCH notification level
def
project_watchers
(
project
)
def
project_watchers
(
project
)
# Gather all user ids that have WATCH notification setting for project
project_members
=
users_project_notification
(
project
)
project_notification_uids
=
project_notification_list
(
project
,
Notification
::
N_WATCH
)
# Gather all user ids that have WATCH notification setting for group
users_with_project_level_global
=
users_project_notification
(
project
,
Notification
::
N_GLOBAL
)
group_notification_uids
=
group_notification_list
(
project
,
Notification
::
N_WATCH
)
users_with_group_level_global
=
users_group_notification
(
project
,
Notification
::
N_GLOBAL
)
users
=
users_with_global_level_watch
([
users_with_project_level_global
,
users_with_group_level_global
].
flatten
.
uniq
)
# Gather all user ids that have GLOBAL setting
users_with_project_setting
=
select_users_project_setting
(
project
,
users_with_project_level_global
,
users
)
global_notification_uids
=
global_notification_list
(
project
)
users_with_group_setting
=
select_users_group_setting
(
project
,
project_members
,
users_with_group_level_global
,
users
)
project_and_group_uids
=
[
project_notification_uids
,
group_notification_uids
].
flatten
.
uniq
User
.
where
(
id:
users_with_project_setting
.
concat
(
users_with_group_setting
).
uniq
).
to_a
group_and_project_watchers
=
User
.
where
(
id:
project_and_group_uids
)
# Find all users that have WATCH as their GLOBAL setting
global_watchers
=
User
.
where
(
id:
global_notification_uids
,
notification_level:
Notification
::
N_WATCH
)
[
group_and_project_watchers
,
global_watchers
].
flatten
.
uniq
end
end
def
project_notification_list
(
project
,
notification_level
)
def
users_project_notification
(
project
,
notification_level
=
nil
)
project
.
users_projects
.
where
(
notification_level:
notification_level
).
pluck
(
:user_id
)
project_members
=
project
.
users_projects
if
notification_level
project_members
.
where
(
notification_level:
notification_level
).
pluck
(
:user_id
)
else
project_members
.
pluck
(
:user_id
)
end
end
end
def
group_notification_list
(
project
,
notification_level
)
def
users_group_notification
(
project
,
notification_level
)
if
project
.
group
if
project
.
group
project
.
group
.
users_groups
.
where
(
notification_level:
notification_level
).
pluck
(
:user_id
)
project
.
group
.
users_groups
.
where
(
notification_level:
notification_level
).
pluck
(
:user_id
)
else
else
...
@@ -208,11 +208,47 @@ class NotificationService
...
@@ -208,11 +208,47 @@ class NotificationService
end
end
end
end
def
global_notification_list
(
project
)
def
users_with_global_level_watch
(
ids
)
[
User
.
where
(
project_notification_list
(
project
,
Notification
::
N_GLOBAL
),
id:
ids
,
group_notification_list
(
project
,
Notification
::
N_GLOBAL
)
notification_level:
Notification
::
N_WATCH
].
flatten
).
pluck
(
:id
)
end
# Build a list of users based on project notifcation settings
def
select_users_project_setting
(
project
,
global_setting
,
users_global_level_watch
)
users
=
users_project_notification
(
project
,
Notification
::
N_WATCH
)
# If project setting is global, add to watch list if global setting is watch
global_setting
.
each
do
|
user_id
|
if
users_global_level_watch
.
include?
(
user_id
)
users
<<
user_id
end
end
users
end
# Build a list of users based on group notifcation settings
def
select_users_group_setting
(
project
,
project_members
,
global_setting
,
users_global_level_watch
)
uids
=
users_group_notification
(
project
,
Notification
::
N_WATCH
)
# Group setting is watch, add to users list if user is not project member
users
=
[]
uids
.
each
do
|
user_id
|
if
project_members
.
exclude?
(
user_id
)
users
<<
user_id
end
end
# Group setting is global, add to users list if global setting is watch
global_setting
.
each
do
|
user_id
|
if
project_members
.
exclude?
(
user_id
)
&&
users_global_level_watch
.
include?
(
user_id
)
users
<<
user_id
end
end
users
end
end
# Remove users with disabled notifications from array
# Remove users with disabled notifications from array
...
...
spec/services/notification_service_spec.rb
View file @
f8b54295
...
@@ -57,15 +57,42 @@ describe NotificationService do
...
@@ -57,15 +57,42 @@ describe NotificationService do
Notify
.
should_not_receive
(
:note_issue_email
)
Notify
.
should_not_receive
(
:note_issue_email
)
notification
.
new_note
(
mentioned_note
)
notification
.
new_note
(
mentioned_note
)
end
end
end
def
should_email
(
user_id
)
describe
'new note on issue in project that belongs to a group'
do
Notify
.
should_receive
(
:note_issue_email
).
with
(
user_id
,
note
.
id
)
let
(
:group
)
{
create
(
:group
)
}
before
do
note
.
project
.
namespace_id
=
group
.
id
note
.
project
.
group
.
add_user
(
@u_watcher
,
UsersGroup
::
MASTER
)
note
.
project
.
save
user_project
=
note
.
project
.
users_projects
.
find_by_user_id
(
@u_watcher
.
id
)
user_project
.
notification_level
=
Notification
::
N_PARTICIPATING
user_project
.
save
user_group
=
note
.
project
.
group
.
users_groups
.
find_by_user_id
(
@u_watcher
.
id
)
user_group
.
notification_level
=
Notification
::
N_GLOBAL
user_group
.
save
end
end
def
should_not_email
(
user_id
)
it
do
Notify
.
should_not_receive
(
:note_issue_email
).
with
(
user_id
,
note
.
id
)
should_email
(
note
.
noteable
.
author_id
)
should_email
(
note
.
noteable
.
assignee_id
)
should_email
(
@u_mentioned
.
id
)
should_not_email
(
@u_watcher
.
id
)
should_not_email
(
note
.
author_id
)
should_not_email
(
@u_participating
.
id
)
should_not_email
(
@u_disabled
.
id
)
notification
.
new_note
(
note
)
end
end
end
end
def
should_email
(
user_id
)
Notify
.
should_receive
(
:note_issue_email
).
with
(
user_id
,
note
.
id
)
end
def
should_not_email
(
user_id
)
Notify
.
should_not_receive
(
:note_issue_email
).
with
(
user_id
,
note
.
id
)
end
end
end
context
'commit note'
do
context
'commit note'
do
...
...
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