mirror of
https://github.com/scinote-eln/scinote-web.git
synced 2024-11-18 15:13:21 +08:00
7dcc774414
* Remove redundant use of respond_to in controlller actions with just one responder format [SCI-8811] * Remove redundant begin block and replace 303 status code with :see_other [SCI-8811]
66 lines
1.7 KiB
Ruby
66 lines
1.7 KiB
Ruby
module Users
|
|
module Settings
|
|
module Account
|
|
class PreferencesController < ApplicationController
|
|
before_action :load_user, only: [
|
|
:index,
|
|
:update,
|
|
:update_togglable_settings
|
|
]
|
|
layout 'fluid'
|
|
|
|
def index
|
|
end
|
|
|
|
def update
|
|
if @user.update(update_params)
|
|
render json: { status: :ok }
|
|
else
|
|
render json: @user.errors, status: :unprocessable_entity
|
|
end
|
|
end
|
|
|
|
def update_togglable_settings
|
|
read_from_params(:assignments_notification) do |val|
|
|
@user.assignments_notification = val
|
|
end
|
|
read_from_params(:recent_notification) do |val|
|
|
@user.recent_notification = val
|
|
end
|
|
read_from_params(:recent_notification_email) do |val|
|
|
@user.recent_email_notification = val
|
|
end
|
|
read_from_params(:assignments_notification_email) do |val|
|
|
@user.assignments_email_notification = val
|
|
end
|
|
read_from_params(:system_message_notification_email) do |val|
|
|
@user.system_message_email_notification = val
|
|
end
|
|
if @user.save
|
|
render json: {
|
|
status: :ok
|
|
}
|
|
else
|
|
render json: {
|
|
status: :unprocessable_entity
|
|
}
|
|
end
|
|
end
|
|
|
|
private
|
|
|
|
def load_user
|
|
@user = current_user
|
|
end
|
|
|
|
def update_params
|
|
params.require(:user).permit(:time_zone, :date_format)
|
|
end
|
|
|
|
def read_from_params(name)
|
|
yield(params.include?(name) ? true : false)
|
|
end
|
|
end
|
|
end
|
|
end
|
|
end
|