diff options
author | Felipe Artur <felipefac@gmail.com> | 2016-06-14 15:36:36 -0300 |
---|---|---|
committer | Felipe Artur <felipefac@gmail.com> | 2016-06-16 23:34:21 -0300 |
commit | f82ab42d0534950c1ceb458e0152f329df80ae9d (patch) | |
tree | fbb3d51a8d2c899eb5037176ff3c247b09b68793 /app/controllers/notification_settings_controller.rb | |
parent | 5c45d5933faa0cc27e1b465322067bd2861b3e47 (diff) | |
download | gitlab-ce-f82ab42d0534950c1ceb458e0152f329df80ae9d.tar.gz |
Re-use notifications dropdown on user profile
Diffstat (limited to 'app/controllers/notification_settings_controller.rb')
-rw-r--r-- | app/controllers/notification_settings_controller.rb | 34 |
1 files changed, 34 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..5d425ad8420 --- /dev/null +++ b/app/controllers/notification_settings_controller.rb @@ -0,0 +1,34 @@ +class NotificationSettingsController < ApplicationController + before_action :authenticate_user! + + def create + project = current_user.projects.find(params[:project][:id]) + + @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("notifications/buttons/_notifications", 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 |