Commit 4c9e47f6e054649eefd453089d1658b9508c16fc

Authored by Dmitriy Zaporozhets
1 parent 3208dad1

Fix notifications for group projects

Showing 1 changed file with 8 additions and 8 deletions   Show diff stats
app/services/notification_service.rb
... ... @@ -147,17 +147,17 @@ class NotificationService
147 147  
148 148 # Get project users with WATCH notification level
149 149 def project_watchers(project)
  150 + project_watchers = []
  151 + member_methods = { project => :users_projects }
  152 + member_methods.merge!(project.group => :users_groups) if project.group
150 153  
151   - member_methods = [:users_projects]
152   - member_methods << :users_groups if project.group
153   -
154   - member_methods.each do |member_method|
  154 + member_methods.each do |object, member_method|
155 155 # Get project notification settings since it has higher priority
156   - user_ids = project.send(member_method).where(notification_level: Notification::N_WATCH).pluck(:user_id)
157   - project_watchers = User.where(id: user_ids)
  156 + user_ids = object.send(member_method).where(notification_level: Notification::N_WATCH).pluck(:user_id)
  157 + project_watchers += User.where(id: user_ids)
158 158  
159 159 # next collect users who use global settings with watch state
160   - user_ids = project.send(member_method).where(notification_level: Notification::N_GLOBAL).pluck(:user_id)
  160 + user_ids = object.send(member_method).where(notification_level: Notification::N_GLOBAL).pluck(:user_id)
161 161 project_watchers += User.where(id: user_ids, notification_level: Notification::N_WATCH)
162 162 end
163 163  
... ... @@ -175,7 +175,7 @@ class NotificationService
175 175 tm = project.users_projects.find_by_user_id(user.id)
176 176  
177 177 if !tm && project.group
178   - tm = project.users_groups.find_by_user_id(user.id)
  178 + tm = project.group.users_groups.find_by_user_id(user.id)
179 179 end
180 180  
181 181 # reject users who globally disabled notification and has no membership
... ...