summaryrefslogtreecommitdiff
path: root/app/controllers/notification_settings_controller.rb
diff options
context:
space:
mode:
authorKamil Trzcinski <ayufan@ayufan.eu>2016-06-21 10:11:14 +0200
committerKamil Trzcinski <ayufan@ayufan.eu>2016-06-21 10:11:14 +0200
commit2f545a15c041fe878268dbcbe287e95dcf693e01 (patch)
tree8c4c580538ca7385f05bae872fcdf42601f698ca /app/controllers/notification_settings_controller.rb
parent95a10f4533fdb708c61ffda95099bddd94800f02 (diff)
parent44b8b77e02423ce97f9abe80e0335f4f4c453c83 (diff)
downloadgitlab-ce-2f545a15c041fe878268dbcbe287e95dcf693e01.tar.gz
Merge remote-tracking branch 'origin/master' into ci-lfs-fetch
Diffstat (limited to 'app/controllers/notification_settings_controller.rb')
-rw-r--r--app/controllers/notification_settings_controller.rb36
1 files changed, 36 insertions, 0 deletions
diff --git a/app/controllers/notification_settings_controller.rb b/app/controllers/notification_settings_controller.rb
new file mode 100644
index 00000000000..eddd03cc229
--- /dev/null
+++ b/app/controllers/notification_settings_controller.rb
@@ -0,0 +1,36 @@
+class NotificationSettingsController < ApplicationController
+ before_action :authenticate_user!
+
+ def create
+ project = Project.find(params[:project][:id])
+
+ return render_404 unless can?(current_user, :read_project, project)
+
+ @notification_setting = current_user.notification_settings_for(project)
+ @saved = @notification_setting.update_attributes(notification_setting_params)
+
+ render_response
+ end
+
+ def update
+ @notification_setting = current_user.notification_settings.find(params[:id])
+ @saved = @notification_setting.update_attributes(notification_setting_params)
+
+ render_response
+ end
+
+ private
+
+ def render_response
+ render json: {
+ html: view_to_html_string("shared/notifications/_button", notification_setting: @notification_setting),
+ saved: @saved
+ }
+ end
+
+ def notification_setting_params
+ allowed_fields = NotificationSetting::EMAIL_EVENTS.dup
+ allowed_fields << :level
+ params.require(:notification_setting).permit(allowed_fields)
+ end
+end