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
|
|
|
|
|
2023-04-23 21:23:45 +05:30
|
|
|
feature_category :user_profile
|
2021-01-03 14:25:43 +05:30
|
|
|
|
2022-07-16 23:28:13 +05:30
|
|
|
urgency :low, [:show]
|
|
|
|
urgency :medium, [:update]
|
|
|
|
|
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
|
2023-07-09 08:55:56 +05:30
|
|
|
preferences_param_names = [
|
2019-07-07 11:18:12 +05:30
|
|
|
:color_scheme_id,
|
2022-06-21 17:19:12 +05:30
|
|
|
:diffs_deletion_color,
|
|
|
|
:diffs_addition_color,
|
2019-07-07 11:18:12 +05:30
|
|
|
: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-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,
|
2022-11-25 23:54:43 +05:30
|
|
|
:markdown_surround_selection,
|
|
|
|
:markdown_automatic_lists,
|
2023-03-04 22:38:38 +05:30
|
|
|
:use_new_navigation
|
2019-07-07 11:18:12 +05:30
|
|
|
]
|
2023-07-09 08:55:56 +05:30
|
|
|
preferences_param_names << :enabled_following if ::Feature.enabled?(:disable_follow_users, user)
|
|
|
|
preferences_param_names
|
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')
|