2018-09-14 01:42:05 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2015-01-08 03:22:50 -05:00
|
|
|
class Admin::ApplicationSettingsController < Admin::ApplicationController
|
2018-09-19 06:57:14 -04:00
|
|
|
include InternalRedirect
|
2019-06-12 11:59:16 -04:00
|
|
|
|
2015-04-16 08:03:37 -04:00
|
|
|
before_action :set_application_setting
|
2019-06-12 11:59:16 -04:00
|
|
|
before_action :whitelist_query_limiting, only: [:usage_data]
|
2015-01-08 03:22:50 -05:00
|
|
|
|
2019-10-07 17:07:54 -04:00
|
|
|
VALID_SETTING_PANELS = %w(general integrations repository
|
2019-02-20 11:56:19 -05:00
|
|
|
ci_cd reporting metrics_and_profiling
|
2019-10-07 17:07:54 -04:00
|
|
|
network preferences).freeze
|
2018-09-19 06:57:14 -04:00
|
|
|
|
2019-09-16 17:06:30 -04:00
|
|
|
VALID_SETTING_PANELS.each do |action|
|
|
|
|
define_method(action) { perform_update if submitted? }
|
2018-09-19 06:57:14 -04:00
|
|
|
end
|
|
|
|
|
2019-09-16 17:06:30 -04:00
|
|
|
def show
|
|
|
|
render :general
|
2018-09-19 06:57:14 -04:00
|
|
|
end
|
|
|
|
|
2015-01-08 03:22:50 -05:00
|
|
|
def update
|
2019-02-20 11:56:19 -05:00
|
|
|
perform_update
|
2015-01-08 03:22:50 -05:00
|
|
|
end
|
|
|
|
|
2017-04-05 08:29:48 -04:00
|
|
|
def usage_data
|
|
|
|
respond_to do |format|
|
2017-03-30 11:48:33 -04:00
|
|
|
format.html do
|
2017-08-17 17:50:29 -04:00
|
|
|
usage_data_json = JSON.pretty_generate(Gitlab::UsageData.data)
|
2017-03-30 11:48:33 -04:00
|
|
|
|
2018-09-06 00:34:25 -04:00
|
|
|
render html: Gitlab::Highlight.highlight('payload.json', usage_data_json, language: 'json')
|
2017-03-30 11:48:33 -04:00
|
|
|
end
|
2017-04-05 08:29:48 -04:00
|
|
|
format.json { render json: Gitlab::UsageData.to_json }
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2018-09-10 17:57:03 -04:00
|
|
|
def reset_registration_token
|
2015-12-11 04:22:05 -05:00
|
|
|
@application_setting.reset_runners_registration_token!
|
2018-09-10 17:57:03 -04:00
|
|
|
|
2019-03-21 09:31:05 -04:00
|
|
|
flash[:notice] = _('New runners registration token has been generated!')
|
2015-12-14 08:03:58 -05:00
|
|
|
redirect_to admin_runners_path
|
2015-12-11 04:22:05 -05:00
|
|
|
end
|
|
|
|
|
2016-05-09 19:21:22 -04:00
|
|
|
def reset_health_check_token
|
|
|
|
@application_setting.reset_health_check_access_token!
|
2019-03-21 09:31:05 -04:00
|
|
|
flash[:notice] = _('New health check access token has been generated!')
|
2018-12-17 12:36:09 -05:00
|
|
|
redirect_back_or_default
|
2016-05-09 19:21:22 -04:00
|
|
|
end
|
|
|
|
|
2016-04-12 11:32:58 -04:00
|
|
|
def clear_repository_check_states
|
2016-04-13 09:56:05 -04:00
|
|
|
RepositoryCheck::ClearWorker.perform_async
|
2016-04-12 11:32:58 -04:00
|
|
|
|
|
|
|
redirect_to(
|
|
|
|
admin_application_settings_path,
|
2019-03-21 09:31:05 -04:00
|
|
|
notice: _('Started asynchronous removal of all repository check states.')
|
2016-04-12 11:32:58 -04:00
|
|
|
)
|
|
|
|
end
|
|
|
|
|
2019-05-16 05:32:25 -04:00
|
|
|
# Getting ToS url requires `directory` api call to Let's Encrypt
|
|
|
|
# which could result in 500 error/slow rendering on settings page
|
|
|
|
# Because of that we use separate controller action
|
|
|
|
def lets_encrypt_terms_of_service
|
|
|
|
redirect_to ::Gitlab::LetsEncrypt.terms_of_service_url
|
|
|
|
end
|
|
|
|
|
2015-01-08 03:22:50 -05:00
|
|
|
private
|
|
|
|
|
|
|
|
def set_application_setting
|
2019-07-01 19:44:54 -04:00
|
|
|
@application_setting = ApplicationSetting.current_without_cache
|
2015-01-08 03:22:50 -05:00
|
|
|
end
|
|
|
|
|
2019-06-12 11:59:16 -04:00
|
|
|
def whitelist_query_limiting
|
2019-09-18 10:02:45 -04:00
|
|
|
Gitlab::QueryLimiting.whitelist('https://gitlab.com/gitlab-org/gitlab-foss/issues/63107')
|
2019-06-12 11:59:16 -04:00
|
|
|
end
|
|
|
|
|
2015-01-08 03:22:50 -05:00
|
|
|
def application_setting_params
|
2018-04-10 21:33:11 -04:00
|
|
|
params[:application_setting] ||= {}
|
2015-08-12 02:13:20 -04:00
|
|
|
|
2018-04-13 11:54:08 -04:00
|
|
|
if params[:application_setting].key?(:enabled_oauth_sign_in_sources)
|
|
|
|
enabled_oauth_sign_in_sources = params[:application_setting].delete(:enabled_oauth_sign_in_sources)
|
|
|
|
enabled_oauth_sign_in_sources&.delete("")
|
2016-05-10 04:29:19 -04:00
|
|
|
|
2018-04-13 11:54:08 -04:00
|
|
|
params[:application_setting][:disabled_oauth_sign_in_sources] =
|
|
|
|
AuthHelper.button_based_providers.map(&:to_s) -
|
|
|
|
Array(enabled_oauth_sign_in_sources)
|
|
|
|
end
|
2017-07-05 06:45:58 -04:00
|
|
|
|
2018-04-13 07:52:54 -04:00
|
|
|
params[:application_setting][:import_sources]&.delete("")
|
2017-07-05 06:45:58 -04:00
|
|
|
params[:application_setting][:restricted_visibility_levels]&.delete("")
|
2019-11-26 12:02:31 -05:00
|
|
|
params[:application_setting].delete(:elasticsearch_aws_secret_access_key) if params[:application_setting][:elasticsearch_aws_secret_access_key].blank?
|
2019-09-18 10:02:45 -04:00
|
|
|
# TODO Remove domain_blacklist_raw in APIv5 (See https://gitlab.com/gitlab-org/gitlab-foss/issues/67204)
|
2016-07-14 14:19:40 -04:00
|
|
|
params.delete(:domain_blacklist_raw) if params[:domain_blacklist_file]
|
2019-07-25 09:09:04 -04:00
|
|
|
params.delete(:domain_blacklist_raw) if params[:domain_blacklist]
|
|
|
|
params.delete(:domain_whitelist_raw) if params[:domain_whitelist]
|
2016-05-10 04:29:19 -04:00
|
|
|
|
2015-01-08 03:22:50 -05:00
|
|
|
params.require(:application_setting).permit(
|
2017-07-13 12:03:52 -04:00
|
|
|
visible_application_setting_attributes
|
2017-01-10 08:40:08 -05:00
|
|
|
)
|
|
|
|
end
|
|
|
|
|
2018-09-07 10:32:28 -04:00
|
|
|
def recheck_user_consent?
|
|
|
|
return false unless session[:ask_for_usage_stats_consent]
|
|
|
|
return false unless params[:application_setting]
|
|
|
|
|
|
|
|
params[:application_setting].key?(:usage_ping_enabled) || params[:application_setting].key?(:version_check_enabled)
|
|
|
|
end
|
|
|
|
|
2017-07-13 12:03:52 -04:00
|
|
|
def visible_application_setting_attributes
|
2019-04-09 11:38:58 -04:00
|
|
|
[
|
|
|
|
*::ApplicationSettingsHelper.visible_attributes,
|
|
|
|
*::ApplicationSettingsHelper.external_authorization_service_attributes,
|
2019-07-12 12:53:44 -04:00
|
|
|
:lets_encrypt_notification_email,
|
|
|
|
:lets_encrypt_terms_of_service_accepted,
|
2016-07-19 18:08:40 -04:00
|
|
|
:domain_blacklist_file,
|
2019-07-24 15:49:31 -04:00
|
|
|
:raw_blob_request_limit,
|
2017-01-10 08:40:08 -05:00
|
|
|
disabled_oauth_sign_in_sources: [],
|
|
|
|
import_sources: [],
|
2016-11-03 10:12:20 -04:00
|
|
|
repository_storages: [],
|
2018-09-14 10:27:31 -04:00
|
|
|
restricted_visibility_levels: []
|
2017-01-10 08:40:08 -05:00
|
|
|
]
|
2015-01-08 03:22:50 -05:00
|
|
|
end
|
2019-04-27 00:38:01 -04:00
|
|
|
|
2019-02-20 11:56:19 -05:00
|
|
|
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
|
2019-10-07 17:07:54 -04:00
|
|
|
action = valid_setting_panels.include?(action_name) ? action_name : :general
|
2019-02-20 11:56:19 -05:00
|
|
|
|
|
|
|
render action
|
|
|
|
end
|
2019-10-07 17:07:54 -04:00
|
|
|
|
|
|
|
# overridden in EE
|
|
|
|
def valid_setting_panels
|
|
|
|
VALID_SETTING_PANELS
|
|
|
|
end
|
2015-01-08 03:22:50 -05:00
|
|
|
end
|
2019-09-13 09:26:31 -04:00
|
|
|
|
|
|
|
Admin::ApplicationSettingsController.prepend_if_ee('EE::Admin::ApplicationSettingsController')
|