BigW Consortium Gitlab

notifications_controller.rb 1.23 KB
Newer Older
1
class Profiles::NotificationsController < Profiles::ApplicationController
2
  def show
3
    @user = current_user
4
    @notification = current_user.notification
5 6
    @project_members = current_user.project_members
    @group_members = current_user.group_members
7 8 9
  end

  def update
10 11 12
    type = params[:notification_type]

    @saved = if type == 'global'
13
               current_user.update_attributes(user_params)
14
             elsif type == 'group'
15 16 17
               group_member = current_user.group_members.find(params[:notification_id])
               group_member.notification_level = params[:notification_level]
               group_member.save
18
             else
19 20 21
               project_member = current_user.project_members.find(params[:notification_id])
               project_member.notification_level = params[:notification_level]
               project_member.save
22
             end
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40

    respond_to do |format|
      format.html do
        if @saved
          flash[:notice] = "Notification settings saved"
        else
          flash[:alert] = "Failed to save new settings"
        end

        redirect_to :back
      end

      format.js
    end
  end

  def user_params
    params.require(:user).permit(:notification_email, :notification_level)
41 42
  end
end