debian-mirror-gitlab/app/controllers/profiles/preferences_controller.rb

59 lines
1.4 KiB
Ruby
Raw Normal View History

2018-12-05 23:21:45 +05:30
# frozen_string_literal: true
2015-09-11 14:41:01 +05:30
class Profiles::PreferencesController < Profiles::ApplicationController
before_action :user
2021-01-03 14:25:43 +05:30
feature_category :users
2015-09-11 14:41:01 +05:30
def show
end
def update
2021-03-11 19:13:27 +05:30
result = Users::UpdateService.new(current_user, preferences_params.merge(user: user)).execute
if result[:status] == :success
message = _('Preferences saved.')
2015-09-11 14:41:01 +05:30
2021-03-11 19:13:27 +05:30
render json: { type: :notice, message: message }
else
render status: :bad_request, json: { type: :alert, message: _('Failed to save preferences.') }
2015-09-11 14:41:01 +05:30
end
2021-03-11 19:13:27 +05:30
rescue ArgumentError => e
# Raised when `dashboard` is given an invalid value.
message = _("Failed to save preferences (%{error_message}).") % { error_message: e.message }
render status: :bad_request, json: { type: :alert, message: message }
2015-09-11 14:41:01 +05:30
end
private
def user
@user = current_user
end
def preferences_params
2019-03-02 22:35:43 +05:30
params.require(:user).permit(preferences_param_names)
end
def preferences_param_names
2019-07-07 11:18:12 +05:30
[
:color_scheme_id,
:layout,
:dashboard,
:project_view,
:theme_id,
:first_day_of_week,
2019-07-31 22:56:46 +05:30
:preferred_language,
:time_display_relative,
2019-12-04 20:38:33 +05:30
:time_format_in_24h,
2019-12-26 22:10:19 +05:30
:show_whitespace_in_diffs,
2020-07-28 23:09:34 +05:30
:view_diffs_file_by_file,
2020-03-13 15:44:24 +05:30
:tab_width,
:sourcegraph_enabled,
2020-11-24 15:15:51 +05:30
:gitpod_enabled,
2021-04-17 20:07:23 +05:30
:render_whitespace_in_code,
:markdown_surround_selection
2019-07-07 11:18:12 +05:30
]
2015-09-11 14:41:01 +05:30
end
end
2019-12-04 20:38:33 +05:30
2021-06-08 01:23:25 +05:30
Profiles::PreferencesController.prepend_mod_with('Profiles::PreferencesController')