BigW Consortium Gitlab

notifications_controller.rb 1.05 KB
Newer Older
1
class Profiles::NotificationsController < Profiles::ApplicationController
2
  def show
3 4 5 6
    @user                        = current_user
    @group_notifications         = current_user.notification_settings.for_groups
    @project_notifications       = current_user.notification_settings.for_projects
    @global_notification_setting = current_user.global_notification_setting
7 8 9
  end

  def update
10
    if current_user.update_attributes(user_params) && update_notification_settings
11 12 13
      flash[:notice] = "Notification settings saved"
    else
      flash[:alert] = "Failed to save new settings"
14
    end
15 16

    redirect_back_or_default(default: profile_notifications_path)
17 18 19
  end

  def user_params
20
    params.require(:user).permit(:notification_email)
21
  end
22

23 24
  def global_notification_setting_params
    params.require(:global_notification_setting).permit(:level)
25 26 27 28 29
  end

  private

  def update_notification_settings
30
    return true unless global_notification_setting_params
31

32
    current_user.global_notification_setting.update_attributes(global_notification_setting_params)
33
  end
34
end