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
iv
gitlab-ce
Commits
c34186f8
Commit
c34186f8
authored
Mar 28, 2014
by
Marin Jankovski
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Refactor project watchers collecting.
parent
e6fbf79b
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
33 additions
and
13 deletions
+33
-13
app/services/notification_service.rb
app/services/notification_service.rb
+33
-13
No files found.
app/services/notification_service.rb
View file @
c34186f8
...
@@ -178,21 +178,41 @@ class NotificationService
...
@@ -178,21 +178,41 @@ class NotificationService
# Get project users with WATCH notification level
# Get project users with WATCH notification level
def
project_watchers
(
project
)
def
project_watchers
(
project
)
project_watchers
=
[]
# Gather all user ids that have WATCH notification setting for project
member_methods
=
{
project
=>
:users_projects
}
project_notification_uids
=
project_notification_list
(
project
,
Notification
::
N_WATCH
)
member_methods
.
merge!
(
project
.
group
=>
:users_groups
)
if
project
.
group
# Gather all user ids that have WATCH notification setting for group
member_methods
.
each
do
|
object
,
member_method
|
group_notification_uids
=
group_notification_list
(
project
,
Notification
::
N_WATCH
)
# Get project notification settings since it has higher priority
user_ids
=
object
.
send
(
member_method
).
where
(
notification_level:
Notification
::
N_WATCH
).
pluck
(
:user_id
)
# Gather all user ids that have GLOBAL setting
project_watchers
+=
User
.
where
(
id:
user_ids
)
global_notification_uids
=
global_notification_list
(
project
)
# next collect users who use global settings with watch state
project_and_group_uids
=
[
project_notification_uids
,
group_notification_uids
].
flatten
.
uniq
user_ids
=
object
.
send
(
member_method
).
where
(
notification_level:
Notification
::
N_GLOBAL
).
pluck
(
:user_id
)
group_and_project_watchers
=
User
.
where
(
id:
project_and_group_uids
)
project_watchers
+=
User
.
where
(
id:
user_ids
,
notification_level:
Notification
::
N_WATCH
)
# 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
def
project_notification_list
(
project
,
notification_level
)
project
.
users_projects
.
where
(
notification_level:
notification_level
).
pluck
(
:user_id
)
end
def
group_notification_list
(
project
,
notification_level
)
if
project
.
group
project
.
group
.
users_groups
.
where
(
notification_level:
notification_level
).
pluck
(
:user_id
)
else
[]
end
end
end
project_watchers
.
uniq
def
global_notification_list
(
project
)
[
project_notification_list
(
project
,
Notification
::
N_GLOBAL
),
group_notification_list
(
project
,
Notification
::
N_GLOBAL
)
].
flatten
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