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

59 lines
1.3 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
def show
end
def update
begin
2018-03-17 18:26:18 +05:30
result = Users::UpdateService.new(current_user, preferences_params.merge(user: user)).execute
2017-09-10 17:25:29 +05:30
if result[:status] == :success
2019-07-31 22:56:46 +05:30
flash[:notice] = _('Preferences saved.')
2015-09-11 14:41:01 +05:30
else
2019-07-31 22:56:46 +05:30
flash[:alert] = _('Failed to save preferences.')
2015-09-11 14:41:01 +05:30
end
rescue ArgumentError => e
# Raised when `dashboard` is given an invalid value.
2019-07-31 22:56:46 +05:30
flash[:alert] = _("Failed to save preferences (%{error_message}).") % { error_message: e.message }
2015-09-11 14:41:01 +05:30
end
respond_to do |format|
format.html { redirect_to profile_preferences_path }
format.js
end
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-03-09 13:42:32 +05:30
:tab_width,
:sourcegraph_enabled,
:render_whitespace_in_code
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
Profiles::PreferencesController.prepend_if_ee('::EE::Profiles::PreferencesController')