From f82ab42d0534950c1ceb458e0152f329df80ae9d Mon Sep 17 00:00:00 2001 From: Felipe Artur Date: Tue, 14 Jun 2016 15:36:36 -0300 Subject: Re-use notifications dropdown on user profile --- .../notification_settings_controller.rb | 34 ++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 app/controllers/notification_settings_controller.rb (limited to 'app/controllers/notification_settings_controller.rb') 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 -- cgit v1.2.1 From ab236c76247d83c190b148acbffa48f244414553 Mon Sep 17 00:00:00 2001 From: Felipe Artur Date: Fri, 17 Jun 2016 12:26:32 -0300 Subject: Allow users to set custom notifications in projects they don't own and several fixes to code --- app/controllers/notification_settings_controller.rb | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) (limited to 'app/controllers/notification_settings_controller.rb') diff --git a/app/controllers/notification_settings_controller.rb b/app/controllers/notification_settings_controller.rb index 5d425ad8420..acda174c229 100644 --- a/app/controllers/notification_settings_controller.rb +++ b/app/controllers/notification_settings_controller.rb @@ -2,12 +2,16 @@ class NotificationSettingsController < ApplicationController before_action :authenticate_user! def create - project = current_user.projects.find(params[:project][:id]) + project = Project.find(params[:project][:id]) - @notification_setting = current_user.notification_settings_for(project) - @saved = @notification_setting.update_attributes(notification_setting_params) + if can?(current_user, :read_project, project) + @notification_setting = current_user.notification_settings_for(project) + @saved = @notification_setting.update_attributes(notification_setting_params) - render_response + render_response + else + render_404 + end end def update @@ -21,7 +25,7 @@ class NotificationSettingsController < ApplicationController def render_response render json: { - html: view_to_html_string("notifications/buttons/_notifications", notification_setting: @notification_setting), + html: view_to_html_string("shared/notifications/buttons/_button", notification_setting: @notification_setting), saved: @saved } end -- cgit v1.2.1