2016-06-14 14:36:36 -04:00
|
|
|
class NotificationSettingsController < ApplicationController
|
|
|
|
before_action :authenticate_user!
|
|
|
|
|
|
|
|
def create
|
2016-06-17 11:26:32 -04:00
|
|
|
project = Project.find(params[:project][:id])
|
2016-06-14 14:36:36 -04:00
|
|
|
|
2016-06-17 11:26:32 -04:00
|
|
|
if can?(current_user, :read_project, project)
|
|
|
|
@notification_setting = current_user.notification_settings_for(project)
|
|
|
|
@saved = @notification_setting.update_attributes(notification_setting_params)
|
2016-06-14 14:36:36 -04:00
|
|
|
|
2016-06-17 11:26:32 -04:00
|
|
|
render_response
|
|
|
|
else
|
|
|
|
render_404
|
|
|
|
end
|
2016-06-14 14:36:36 -04:00
|
|
|
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: {
|
2016-06-17 11:26:32 -04:00
|
|
|
html: view_to_html_string("shared/notifications/buttons/_button", notification_setting: @notification_setting),
|
2016-06-14 14:36:36 -04:00
|
|
|
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
|