Reuse `User#notification_settings_for` when it's possible

parent 9a44d697
class Groups::NotificationSettingsController < Groups::ApplicationController
def update
notification_setting = group.notification_settings.find_by(user_id: current_user)
notification_setting = current_user.notification_settings_for(group)
saved = notification_setting.update_attributes(notification_setting_params)
render json: { saved: saved }
......
class Projects::NotificationSettingsController < Projects::ApplicationController
def create
notification_setting = project.notification_settings.new(notification_setting_params)
notification_setting.user = current_user
saved = notification_setting.save
notification_setting = current_user.notification_settings_for(project)
saved = notification_setting.update_attributes(notification_setting_params)
render json: { saved: saved }
end
def update
notification_setting = project.notification_settings.find_by(user_id: current_user)
notification_setting = current_user.notification_settings_for(project)
saved = notification_setting.update_attributes(notification_setting_params)
render json: { saved: saved }
......
......@@ -167,7 +167,7 @@ class Member < ActiveRecord::Base
end
def notification_setting
@notification_setting ||= user.notification_settings.find_by(source: source)
@notification_setting ||= user.notification_settings_for(source)
end
private
......
......@@ -355,10 +355,10 @@ class NotificationService
users.reject do |user|
next user.notification_level == level unless project
setting = user.notification_settings.find_by(source: project)
setting = user.notification_settings_for(project)
if !setting && project.group
setting = user.notification_settings.find_by(source: project.group)
setting = user.notification_settings_for(project.group)
end
# reject users who globally set mention notification and has no setting per project/group
......
......@@ -89,8 +89,8 @@ describe NotificationService, services: true do
note.project.group.add_user(@u_watcher, GroupMember::MASTER)
note.project.save
@u_watcher.notification_settings.find_by(source: note.project).participating!
@u_watcher.notification_settings.find_by(source: note.project.group).global!
@u_watcher.notification_settings_for(note.project).participating!
@u_watcher.notification_settings_for(note.project.group).global!
ActionMailer::Base.deliveries.clear
end
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment