Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarin Jankovski <marin@gitlab.com>2014-03-28 19:43:28 +0400
committerMarin Jankovski <marin@gitlab.com>2014-03-28 20:51:13 +0400
commitc34186f88258aadd03c7e692606ff2499d221d2b (patch)
tree6221bdbb24c12d5b8d25ce4e37a2e294f811f90c /app/services
parente6fbf79bc51c6a466d7fa880adb598cded41707a (diff)
Refactor project watchers collecting.
Diffstat (limited to 'app/services')
-rw-r--r--app/services/notification_service.rb46
1 files changed, 33 insertions, 13 deletions
diff --git a/app/services/notification_service.rb b/app/services/notification_service.rb
index 6fda9868aa5..d85398809c2 100644
--- a/app/services/notification_service.rb
+++ b/app/services/notification_service.rb
@@ -178,21 +178,41 @@ class NotificationService
# Get project users with WATCH notification level
def project_watchers(project)
- project_watchers = []
- member_methods = { project => :users_projects }
- member_methods.merge!(project.group => :users_groups) if project.group
-
- member_methods.each do |object, member_method|
- # Get project notification settings since it has higher priority
- user_ids = object.send(member_method).where(notification_level: Notification::N_WATCH).pluck(:user_id)
- project_watchers += User.where(id: user_ids)
-
- # next collect users who use global settings with watch state
- user_ids = object.send(member_method).where(notification_level: Notification::N_GLOBAL).pluck(:user_id)
- project_watchers += User.where(id: user_ids, notification_level: Notification::N_WATCH)
+ # Gather all user ids that have WATCH notification setting for project
+ project_notification_uids = project_notification_list(project, Notification::N_WATCH)
+
+ # Gather all user ids that have WATCH notification setting for group
+ group_notification_uids = group_notification_list(project, Notification::N_WATCH)
+
+ # Gather all user ids that have GLOBAL setting
+ global_notification_uids = global_notification_list(project)
+
+ project_and_group_uids = [project_notification_uids, group_notification_uids].flatten.uniq
+ 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
+
+ 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
- project_watchers.uniq
+ def global_notification_list(project)
+ [
+ project_notification_list(project, Notification::N_GLOBAL),
+ group_notification_list(project, Notification::N_GLOBAL)
+ ].flatten
end
# Remove users with disabled notifications from array