diff options
author | Felipe Artur <felipefac@gmail.com> | 2016-06-21 22:50:13 +0300 |
---|---|---|
committer | Felipe Artur <felipefac@gmail.com> | 2016-06-22 16:44:20 +0300 |
commit | 8447c6b180297840d835a609d95808834f498d87 (patch) | |
tree | 4b8e34797e92c3dd5649218243d94c5278b61848 /app/controllers/notification_settings_controller.rb | |
parent | f82ab42d0534950c1ceb458e0152f329df80ae9d (diff) |
Insert notification settings dropdown into groups
Diffstat (limited to 'app/controllers/notification_settings_controller.rb')
-rw-r--r-- | app/controllers/notification_settings_controller.rb | 22 |
1 files changed, 20 insertions, 2 deletions
diff --git a/app/controllers/notification_settings_controller.rb b/app/controllers/notification_settings_controller.rb index 5d425ad8420..735e562a497 100644 --- a/app/controllers/notification_settings_controller.rb +++ b/app/controllers/notification_settings_controller.rb @@ -2,9 +2,11 @@ class NotificationSettingsController < ApplicationController before_action :authenticate_user! def create - project = current_user.projects.find(params[:project][:id]) + resource = find_resource - @notification_setting = current_user.notification_settings_for(project) + return render_404 unless can_read?(resource) + + @notification_setting = current_user.notification_settings_for(resource) @saved = @notification_setting.update_attributes(notification_setting_params) render_response @@ -19,6 +21,22 @@ class NotificationSettingsController < ApplicationController private + def find_resource + resource = + if params[:project].present? + Project.find(params[:project][:id]) + elsif params[:namespace].present? + Group.find(params[:namespace][:id]) + end + end + + def can_read?(resource) + ability_name = resource.class.name.downcase + ability_name = "read_#{ability_name}".to_sym + + can?(current_user, ability_name, resource) + end + def render_response render json: { html: view_to_html_string("notifications/buttons/_notifications", notification_setting: @notification_setting), |