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
Tatuya Kamada
gitlab-ce
Commits
528a641e
Commit
528a641e
authored
Apr 01, 2014
by
Marin Jankovski
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Use group notification settings while honoring project settings.
parent
ce30a56f
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
41 additions
and
32 deletions
+41
-32
app/services/notification_service.rb
app/services/notification_service.rb
+41
-32
No files found.
app/services/notification_service.rb
View file @
528a641e
...
@@ -178,28 +178,28 @@ class NotificationService
...
@@ -178,28 +178,28 @@ 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 that have WATCH notification setting for project and group
project_members
=
project_notification_list
(
project
)
project_uids
,
group_uids
=
project_and_group_watchers
(
project
,
Notification
::
N_WATCH
)
# Gather all user that have WATCH as their GLOBAL setting
project_global
=
project_notification_list
(
project
,
Notification
::
N_GLOBAL
)
global_setting_project
,
global_setting_group
=
project_and_group_watchers
(
project
,
Notification
::
N_GLOBAL
)
group_global
=
group_notification_list
(
project
,
Notification
::
N_GLOBAL
)
global_uids
=
[
global_setting_project
,
global_setting_group
].
flatten
.
uniq
global_watch
=
User
.
where
(
global_watchers_ids
=
User
.
where
(
id:
global_uids
,
notification_level:
Notification
::
N_WATCH
).
pluck
(
:id
)
id:
[
project_global
,
group_global
].
flatten
.
uniq
,
notification_level:
Notification
::
N_WATCH
).
pluck
(
:id
)
# Select watchers based on what the project setting is
project_watch
=
watch_project
(
project
,
project_global
,
global_watch
)
project_watchers
,
user_ids
=
select_watchers
(
global_watchers_ids
,
global_setting_project
,
project_uids
)
group_watch
=
watch_group
(
project
,
project_members
,
group_global
,
global_watch
)
# Select watchers based on what the group setting is
User
.
where
(
id:
project_watch
.
concat
(
group_watch
).
uniq
).
to_a
group_watchers
,
ids
=
select_watchers
(
user_ids
,
global_setting_group
,
group_uids
)
project_watchers
.
concat
(
group_watchers
.
concat
(
ids
)).
uniq
watchers
=
User
.
where
(
id:
project_watchers
)
watchers
.
to_a
end
end
def
project_notification_list
(
project
,
notification_level
)
def
project_notification_list
(
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
group_notification_list
(
project
,
notification_level
)
...
@@ -210,25 +210,34 @@ class NotificationService
...
@@ -210,25 +210,34 @@ class NotificationService
end
end
end
end
def
select_watchers
(
user_ids
,
global_setting
,
setting
)
def
watch_project
(
project
,
global_setting
,
watch_global
)
watchers
=
[]
uids
=
project_notification_list
(
project
,
Notification
::
N_WATCH
)
user_ids
.
each
do
|
i
|
if
setting
.
include?
(
i
)
global_setting
.
each
do
|
i
|
watchers
<<
i
if
watch_global
.
include?
(
i
)
elsif
global_setting
.
include?
(
i
)
uids
<<
i
watchers
<<
i
else
user_ids
.
delete
(
i
)
end
end
end
end
[
watchers
,
user_ids
]
uids
.
uniq
end
def
watch_group
(
project
,
project_members
,
global_setting
,
watch_global
)
uids
=
group_notification_list
(
project
,
Notification
::
N_WATCH
)
# Group setting is watch, add to watchers list user is not project member
watch
=
[]
uids
.
each
do
|
i
|
if
project_members
.
exclude?
(
i
)
watch
<<
i
end
end
global_setting
.
each
do
|
i
|
if
project_members
.
exclude?
(
i
)
&&
watch_global
.
include?
(
i
)
watch
<<
i
end
end
end
def
project_and_group_watchers
(
project
,
notification_level
)
watch
.
uniq
[
project_notification_list
(
project
,
notification_level
),
group_notification_list
(
project
,
notification_level
)
]
end
end
# Remove users with disabled notifications from array
# Remove users with disabled notifications from array
...
...
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