2018-09-14 05:42:05 +00:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2015-01-08 08:22:50 +00:00
|
|
|
class Admin::ApplicationSettingsController < Admin::ApplicationController
|
2018-09-19 10:57:14 +00:00
|
|
|
include InternalRedirect
|
2019-06-12 15:59:16 +00:00
|
|
|
|
2015-04-16 12:03:37 +00:00
|
|
|
before_action :set_application_setting
|
2019-06-12 15:59:16 +00:00
|
|
|
before_action :whitelist_query_limiting, only: [:usage_data]
|
2015-01-08 08:22:50 +00:00
|
|
|
|
2019-09-16 21:06:30 +00:00
|
|
|
VALID_SETTING_PANELS = %w(general integrations repository templates
|
2019-02-20 16:56:19 +00:00
|
|
|
ci_cd reporting metrics_and_profiling
|
|
|
|
network geo preferences).freeze
|
2018-09-19 10:57:14 +00:00
|
|
|
|
2019-09-16 21:06:30 +00:00
|
|
|
VALID_SETTING_PANELS.each do |action|
|
|
|
|
define_method(action) { perform_update if submitted? }
|
2018-09-19 10:57:14 +00:00
|
|
|
end
|
|
|
|
|
2019-09-16 21:06:30 +00:00
|
|
|
def show
|
|
|
|
render :general
|
2018-09-19 10:57:14 +00:00
|
|
|
end
|
|
|
|
|
2015-01-08 08:22:50 +00:00
|
|
|
def update
|
2019-02-20 16:56:19 +00:00
|
|
|
perform_update
|
2015-01-08 08:22:50 +00:00
|
|
|
end
|
|
|
|
|
2017-04-05 12:29:48 +00:00
|
|
|
def usage_data
|
|
|
|
respond_to do |format|
|
2017-03-30 15:48:33 +00:00
|
|
|
format.html do
|
2017-08-17 21:50:29 +00:00
|
|
|
usage_data_json = JSON.pretty_generate(Gitlab::UsageData.data)
|
2017-03-30 15:48:33 +00:00
|
|
|
|
2018-09-06 04:34:25 +00:00
|
|
|
render html: Gitlab::Highlight.highlight('payload.json', usage_data_json, language: 'json')
|
2017-03-30 15:48:33 +00:00
|
|
|
end
|
2017-04-05 12:29:48 +00:00
|
|
|
format.json { render json: Gitlab::UsageData.to_json }
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2018-09-10 21:57:03 +00:00
|
|
|
def reset_registration_token
|
2015-12-11 09:22:05 +00:00
|
|
|
@application_setting.reset_runners_registration_token!
|
2018-09-10 21:57:03 +00:00
|
|
|
|
2019-03-21 13:31:05 +00:00
|
|
|
flash[:notice] = _('New runners registration token has been generated!')
|
2015-12-14 13:03:58 +00:00
|
|
|
redirect_to admin_runners_path
|
2015-12-11 09:22:05 +00:00
|
|
|
end
|
|
|
|
|
2016-05-09 23:21:22 +00:00
|
|
|
def reset_health_check_token
|
|
|
|
@application_setting.reset_health_check_access_token!
|
2019-03-21 13:31:05 +00:00
|
|
|
flash[:notice] = _('New health check access token has been generated!')
|
2018-12-17 17:36:09 +00:00
|
|
|
redirect_back_or_default
|
2016-05-09 23:21:22 +00:00
|
|
|
end
|
|
|
|
|
2016-04-12 15:32:58 +00:00
|
|
|
def clear_repository_check_states
|
2016-04-13 13:56:05 +00:00
|
|
|
RepositoryCheck::ClearWorker.perform_async
|
2016-04-12 15:32:58 +00:00
|
|
|
|
|
|
|
redirect_to(
|
|
|
|
admin_application_settings_path,
|
2019-03-21 13:31:05 +00:00
|
|
|
notice: _('Started asynchronous removal of all repository check states.')
|
2016-04-12 15:32:58 +00:00
|
|
|
)
|
|
|
|
end
|
|
|
|
|
2019-05-16 09:32:25 +00: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 08:22:50 +00:00
|
|
|
private
|
|
|
|
|
|
|
|
def set_application_setting
|
2019-07-01 23:44:54 +00:00
|
|
|
@application_setting = ApplicationSetting.current_without_cache
|
2015-01-08 08:22:50 +00:00
|
|
|
end
|
|
|
|
|
2019-06-12 15:59:16 +00:00
|
|
|
def whitelist_query_limiting
|
2019-09-18 14:02:45 +00:00
|
|
|
Gitlab::QueryLimiting.whitelist('https://gitlab.com/gitlab-org/gitlab-foss/issues/63107')
|
2019-06-12 15:59:16 +00:00
|
|
|
end
|
|
|
|
|
2015-01-08 08:22:50 +00:00
|
|
|
def application_setting_params
|
2018-04-11 01:33:11 +00:00
|
|
|
params[:application_setting] ||= {}
|
2015-08-12 06:13:20 +00:00
|
|
|
|
2018-04-13 15:54:08 +00: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 08:29:19 +00:00
|
|
|
|
2018-04-13 15:54:08 +00: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 10:45:58 +00:00
|
|
|
|
2018-04-13 11:52:54 +00:00
|
|
|
params[:application_setting][:import_sources]&.delete("")
|
2017-07-05 10:45:58 +00:00
|
|
|
params[:application_setting][:restricted_visibility_levels]&.delete("")
|
2019-09-18 14:02:45 +00:00
|
|
|
# TODO Remove domain_blacklist_raw in APIv5 (See https://gitlab.com/gitlab-org/gitlab-foss/issues/67204)
|
2016-07-14 18:19:40 +00:00
|
|
|
params.delete(:domain_blacklist_raw) if params[:domain_blacklist_file]
|
2019-07-25 13:09:04 +00:00
|
|
|
params.delete(:domain_blacklist_raw) if params[:domain_blacklist]
|
|
|
|
params.delete(:domain_whitelist_raw) if params[:domain_whitelist]
|
2016-05-10 08:29:19 +00:00
|
|
|
|
2015-01-08 08:22:50 +00:00
|
|
|
params.require(:application_setting).permit(
|
2017-07-13 16:03:52 +00:00
|
|
|
visible_application_setting_attributes
|
2017-01-10 13:40:08 +00:00
|
|
|
)
|
|
|
|
end
|
|
|
|
|
2018-09-07 14:32:28 +00: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 16:03:52 +00:00
|
|
|
def visible_application_setting_attributes
|
2019-04-09 15:38:58 +00:00
|
|
|
[
|
|
|
|
*::ApplicationSettingsHelper.visible_attributes,
|
|
|
|
*::ApplicationSettingsHelper.external_authorization_service_attributes,
|
2019-07-12 16:53:44 +00:00
|
|
|
:lets_encrypt_notification_email,
|
|
|
|
:lets_encrypt_terms_of_service_accepted,
|
2016-07-19 22:08:40 +00:00
|
|
|
:domain_blacklist_file,
|
2019-07-24 19:49:31 +00:00
|
|
|
:raw_blob_request_limit,
|
2017-01-10 13:40:08 +00:00
|
|
|
disabled_oauth_sign_in_sources: [],
|
|
|
|
import_sources: [],
|
2016-11-03 14:12:20 +00:00
|
|
|
repository_storages: [],
|
2018-09-14 14:27:31 +00:00
|
|
|
restricted_visibility_levels: []
|
2017-01-10 13:40:08 +00:00
|
|
|
]
|
2015-01-08 08:22:50 +00:00
|
|
|
end
|
2019-04-27 04:38:01 +00:00
|
|
|
|
2019-02-20 16:56:19 +00: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-09-16 21:06:30 +00:00
|
|
|
action = VALID_SETTING_PANELS.include?(action_name) ? action_name : :general
|
2019-02-20 16:56:19 +00:00
|
|
|
|
|
|
|
render action
|
|
|
|
end
|
2015-01-08 08:22:50 +00:00
|
|
|
end
|
2019-09-13 13:26:31 +00:00
|
|
|
|
|
|
|
Admin::ApplicationSettingsController.prepend_if_ee('EE::Admin::ApplicationSettingsController')
|