summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDouglas Barbosa Alexandre <dbalexandre@gmail.com>2016-04-11 18:23:12 -0300
committerDouglas Barbosa Alexandre <dbalexandre@gmail.com>2016-04-11 20:50:26 -0300
commit93a10f17e0c84074580eaf1b101af2a0fffd19ed (patch)
treecf601b69b92f4db61a0b41daf6e7a0742a0a0070
parent9a44d6977ad27a443538b2b6c34b3fdd722e9bd6 (diff)
downloadgitlab-ce-93a10f17e0c84074580eaf1b101af2a0fffd19ed.tar.gz
Reuse `User#notification_settings_for` when it's possible
-rw-r--r--app/controllers/groups/notification_settings_controller.rb2
-rw-r--r--app/controllers/projects/notification_settings_controller.rb7
-rw-r--r--app/models/member.rb2
-rw-r--r--app/services/notification_service.rb4
-rw-r--r--spec/services/notification_service_spec.rb4
5 files changed, 9 insertions, 10 deletions
diff --git a/app/controllers/groups/notification_settings_controller.rb b/app/controllers/groups/notification_settings_controller.rb
index 20405a05190..1b46f26a378 100644
--- a/app/controllers/groups/notification_settings_controller.rb
+++ b/app/controllers/groups/notification_settings_controller.rb
@@ -1,6 +1,6 @@
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 }
diff --git a/app/controllers/projects/notification_settings_controller.rb b/app/controllers/projects/notification_settings_controller.rb
index da9034380af..90d294a4624 100644
--- a/app/controllers/projects/notification_settings_controller.rb
+++ b/app/controllers/projects/notification_settings_controller.rb
@@ -1,14 +1,13 @@
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 }
diff --git a/app/models/member.rb b/app/models/member.rb
index 7d5af1d5c8a..60efafef211 100644
--- a/app/models/member.rb
+++ b/app/models/member.rb
@@ -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
diff --git a/app/services/notification_service.rb b/app/services/notification_service.rb
index 0928dda349e..42ec1ac9e1a 100644
--- a/app/services/notification_service.rb
+++ b/app/services/notification_service.rb
@@ -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
diff --git a/spec/services/notification_service_spec.rb b/spec/services/notification_service_spec.rb
index c4d52584a4b..d7c72dc0811 100644
--- a/spec/services/notification_service_spec.rb
+++ b/spec/services/notification_service_spec.rb
@@ -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