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
109ab1a5
Commit
109ab1a5
authored
Apr 01, 2014
by
Marin Jankovski
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add comments, fix style, better names for notification methods.
parent
528a641e
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
40 additions
and
29 deletions
+40
-29
app/services/notification_service.rb
app/services/notification_service.rb
+40
-29
No files found.
app/services/notification_service.rb
View file @
109ab1a5
...
@@ -178,23 +178,21 @@ class NotificationService
...
@@ -178,23 +178,21 @@ 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_members
=
project_notification_list
(
project
)
project_members
=
users_project_notification
(
project
)
project_global
=
project_notification_list
(
project
,
Notification
::
N_GLOBAL
)
users_with_project_level_global
=
users_project_notification
(
project
,
Notification
::
N_GLOBAL
)
group_global
=
group_notification_list
(
project
,
Notification
::
N_GLOBAL
)
users_with_group_level_global
=
users_group_notification
(
project
,
Notification
::
N_GLOBAL
)
global_watch
=
User
.
where
(
users
=
users_with_global_level_watch
([
users_with_project_level_global
,
users_with_group_level_global
].
flatten
.
uniq
)
id:
[
project_global
,
group_global
].
flatten
.
uniq
,
notification_level:
Notification
::
N_WATCH
).
pluck
(
:id
)
project_watch
=
watch_project
(
project
,
project_global
,
global_watch
)
users_with_project_setting
=
select_users_project_setting
(
project
,
users_with_project_level_global
,
users
)
group_watch
=
watch_group
(
project
,
project_members
,
group_global
,
global_watch
)
users_with_group_setting
=
select_users_group_setting
(
project
,
project_members
,
users_with_group_level_global
,
users
)
User
.
where
(
id:
project_watch
.
concat
(
group_watch
).
uniq
).
to_a
User
.
where
(
id:
users_with_project_setting
.
concat
(
users_with_group_setting
).
uniq
).
to_a
end
end
def
project_notification_list
(
project
,
notification_level
=
nil
)
def
users_project_notification
(
project
,
notification_level
=
nil
)
project_members
=
project
.
users_projects
project_members
=
project
.
users_projects
if
notification_level
if
notification_level
project_members
.
where
(
notification_level:
notification_level
).
pluck
(
:user_id
)
project_members
.
where
(
notification_level:
notification_level
).
pluck
(
:user_id
)
else
else
...
@@ -202,7 +200,7 @@ class NotificationService
...
@@ -202,7 +200,7 @@ class NotificationService
end
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
...
@@ -210,34 +208,47 @@ class NotificationService
...
@@ -210,34 +208,47 @@ class NotificationService
end
end
end
end
def
watch_project
(
project
,
global_setting
,
watch_global
)
def
users_with_global_level_watch
(
ids
)
uids
=
project_notification_list
(
project
,
Notification
::
N_WATCH
)
User
.
where
(
id:
ids
,
notification_level:
Notification
::
N_WATCH
).
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
)
global_setting
.
each
do
|
i
|
# If project setting is global, add to watch list if global setting is watch
if
watch_global
.
include?
(
i
)
global_setting
.
each
do
|
user_id
|
uids
<<
i
if
users_global_level_watch
.
include?
(
user_id
)
users
<<
user_id
end
end
end
end
uids
.
uniq
users
end
end
def
watch_group
(
project
,
project_members
,
global_setting
,
watch_global
)
# Build a list of users based on group notifcation settings
uids
=
group_notification_list
(
project
,
Notification
::
N_WATCH
)
def
select_users_group_setting
(
project
,
project_members
,
global_setting
,
users_global_level_watch
)
# Group setting is watch, add to watchers list user is not project member
uids
=
users_group_notification
(
project
,
Notification
::
N_WATCH
)
watch
=
[]
uids
.
each
do
|
i
|
# Group setting is watch, add to users list if user is not project member
if
project_members
.
exclude?
(
i
)
users
=
[]
watch
<<
i
uids
.
each
do
|
user_id
|
if
project_members
.
exclude?
(
user_id
)
users
<<
user_id
end
end
end
end
global_setting
.
each
do
|
i
|
# Group setting is global, add to users list if global setting is watch
if
project_members
.
exclude?
(
i
)
&&
watch_global
.
include?
(
i
)
global_setting
.
each
do
|
user_id
|
watch
<<
i
if
project_members
.
exclude?
(
user_id
)
&&
users_global_level_watch
.
include?
(
user_id
)
users
<<
user_id
end
end
end
end
watch
.
uniq
users
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