diff options
author | Brett Walker <bwalker@gitlab.com> | 2019-02-20 10:56:19 -0600 |
---|---|---|
committer | Brett Walker <bwalker@gitlab.com> | 2019-06-19 12:29:10 -0500 |
commit | 6b4f93c0349e9d54cb48f1d5cf025c5e5ce77aee (patch) | |
tree | 422fdbc63f17d7836fe2cff92586b59a5febd3d0 /app/controllers/admin | |
parent | e999e1de7baadc34e7fccf76e76991a7adf31b0e (diff) | |
download | gitlab-ce-6b4f93c0349e9d54cb48f1d5cf025c5e5ce77aee.tar.gz |
Update application settings using correct action
Updating multiple application settings panels through
a single action causes the incorrect action to be shown
when there are errors. Instead, make each panel action
handle both updating and display.
Diffstat (limited to 'app/controllers/admin')
-rw-r--r-- | app/controllers/admin/application_settings_controller.rb | 83 |
1 files changed, 39 insertions, 44 deletions
diff --git a/app/controllers/admin/application_settings_controller.rb b/app/controllers/admin/application_settings_controller.rb index 57b976b9121..42634bf611e 100644 --- a/app/controllers/admin/application_settings_controller.rb +++ b/app/controllers/admin/application_settings_controller.rb @@ -6,56 +6,19 @@ class Admin::ApplicationSettingsController < Admin::ApplicationController before_action :set_application_setting before_action :whitelist_query_limiting, only: [:usage_data] - def show - end - - def integrations - end - - def repository - end - - def templates - end - - def ci_cd - end - - def reporting - end - - def metrics_and_profiling - end - - def network - end + VALID_SETTING_PANELS = %w(show integrations repository templates + ci_cd reporting metrics_and_profiling + network geo preferences).freeze - def geo + def show end - def preferences + (VALID_SETTING_PANELS - %w(show)).each do |action| + define_method(action) { perform_update if submitted? } end def update - successful = ApplicationSettings::UpdateService - .new(@application_setting, current_user, application_setting_params) - .execute - - if recheck_user_consent? - session[:ask_for_usage_stats_consent] = current_user.requires_usage_stats_consent? - end - - redirect_path = referer_path(request) || admin_application_settings_path - - respond_to do |format| - if successful - format.json { head :ok } - format.html { redirect_to redirect_path, notice: _('Application settings saved successfully') } - else - format.json { head :bad_request } - format.html { render :show } - end - end + perform_update end def usage_data @@ -149,6 +112,38 @@ class Admin::ApplicationSettingsController < Admin::ApplicationController ] end + def submitted? + request.patch? + end + + def perform_update + successful = ApplicationSettings::UpdateService + .new(@application_setting, current_user, application_setting_params) + .execute + + if recheck_user_consent? + session[:ask_for_usage_stats_consent] = current_user.requires_usage_stats_consent? + end + + redirect_path = referer_path(request) || admin_application_settings_path + + respond_to do |format| + if successful + format.json { head :ok } + format.html { redirect_to redirect_path, notice: _('Application settings saved successfully') } + else + format.json { head :bad_request } + format.html { render_update_error } + end + end + end + + def render_update_error + action = VALID_SETTING_PANELS.include?(action_name) ? action_name : :show + + render action + end + def lets_encrypt_visible_attributes return [] unless Feature.enabled?(:pages_auto_ssl) |