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
|
2021-06-24 11:07:28 -04:00
|
|
|
include IntegrationsHelper
|
2019-06-12 11:59:16 -04:00
|
|
|
|
2020-01-29 07:09:08 -05:00
|
|
|
# NOTE: Use @application_setting in this controller when you need to access
|
|
|
|
# application_settings after it has been modified. This is because the
|
2020-05-06 17:10:00 -04:00
|
|
|
# ApplicationSetting model uses Gitlab::ProcessMemoryCache for caching and the
|
2020-01-29 07:09:08 -05:00
|
|
|
# cache might be stale immediately after an update.
|
|
|
|
# https://gitlab.com/gitlab-org/gitlab-foss/-/merge_requests/30233
|
2020-03-27 14:07:48 -04:00
|
|
|
before_action :set_application_setting, except: :integrations
|
2020-01-29 07:09:08 -05:00
|
|
|
|
2021-03-16 14:11:53 -04:00
|
|
|
before_action :disable_query_limiting, only: [:usage_data]
|
2020-01-08 04:07:53 -05:00
|
|
|
|
2020-10-05 17:08:47 -04:00
|
|
|
feature_category :not_owned, [
|
|
|
|
:general, :reporting, :metrics_and_profiling, :network,
|
|
|
|
:preferences, :update, :reset_health_check_token
|
|
|
|
]
|
|
|
|
|
|
|
|
feature_category :metrics, [
|
|
|
|
:create_self_monitoring_project,
|
|
|
|
:status_create_self_monitoring_project,
|
|
|
|
:delete_self_monitoring_project,
|
|
|
|
:status_delete_self_monitoring_project
|
|
|
|
]
|
|
|
|
|
|
|
|
feature_category :source_code_management, [:repository, :clear_repository_check_states]
|
|
|
|
feature_category :continuous_integration, [:ci_cd, :reset_registration_token]
|
2020-12-31 10:10:32 -05:00
|
|
|
feature_category :usage_ping, [:usage_data]
|
2020-10-05 17:08:47 -04:00
|
|
|
feature_category :integrations, [:integrations]
|
|
|
|
feature_category :pages, [:lets_encrypt_terms_of_service]
|
|
|
|
|
2020-08-17 02:10:12 -04:00
|
|
|
VALID_SETTING_PANELS = %w(general 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
|
|
|
|
2020-01-08 04:07:53 -05:00
|
|
|
# The current size of a sidekiq job's jid is 24 characters. The size of the
|
|
|
|
# jid is an internal detail of Sidekiq, and they do not guarantee that it'll
|
|
|
|
# stay the same. We chose 50 to give us room in case the size of the jid
|
|
|
|
# increases. The jid is alphanumeric, so 50 is very generous. There is a spec
|
|
|
|
# that ensures that the constant value is more than the size of an actual jid.
|
|
|
|
PARAM_JOB_ID_MAX_SIZE = 50
|
|
|
|
|
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
|
|
|
|
|
2020-03-24 11:08:44 -04:00
|
|
|
def integrations
|
2020-09-25 17:09:51 -04:00
|
|
|
return not_found unless instance_level_integrations?
|
|
|
|
|
2021-05-12 08:10:24 -04:00
|
|
|
@integrations = Integration.find_or_initialize_all_non_project_specific(Integration.for_instance).sort_by(&:title)
|
2020-03-24 11:08:44 -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
|
2020-04-30 14:09:38 -04:00
|
|
|
usage_data_json = Gitlab::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
|
2020-02-14 16:09:08 -05:00
|
|
|
RepositoryCheck::ClearWorker.perform_async # rubocop:disable CodeReuse/Worker
|
2016-04-12 11:32:58 -04:00
|
|
|
|
|
|
|
redirect_to(
|
2020-02-10 07:08:59 -05:00
|
|
|
general_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
|
|
|
|
|
2020-01-29 07:09:08 -05:00
|
|
|
# Specs are in spec/requests/self_monitoring_project_spec.rb
|
2020-01-08 04:07:53 -05:00
|
|
|
def create_self_monitoring_project
|
2020-02-14 16:09:08 -05:00
|
|
|
job_id = SelfMonitoringProjectCreateWorker.perform_async # rubocop:disable CodeReuse/Worker
|
2020-01-08 04:07:53 -05:00
|
|
|
|
|
|
|
render status: :accepted, json: {
|
|
|
|
job_id: job_id,
|
|
|
|
monitor_status: status_create_self_monitoring_project_admin_application_settings_path
|
|
|
|
}
|
|
|
|
end
|
|
|
|
|
2020-01-29 07:09:08 -05:00
|
|
|
# Specs are in spec/requests/self_monitoring_project_spec.rb
|
2020-01-08 04:07:53 -05:00
|
|
|
def status_create_self_monitoring_project
|
|
|
|
job_id = params[:job_id].to_s
|
|
|
|
|
|
|
|
unless job_id.length <= PARAM_JOB_ID_MAX_SIZE
|
|
|
|
return render status: :bad_request, json: {
|
|
|
|
message: _('Parameter "job_id" cannot exceed length of %{job_id_max_size}' %
|
|
|
|
{ job_id_max_size: PARAM_JOB_ID_MAX_SIZE })
|
|
|
|
}
|
|
|
|
end
|
|
|
|
|
2020-02-14 16:09:08 -05:00
|
|
|
if SelfMonitoringProjectCreateWorker.in_progress?(job_id) # rubocop:disable CodeReuse/Worker
|
2020-01-08 04:07:53 -05:00
|
|
|
::Gitlab::PollingInterval.set_header(response, interval: 3_000)
|
|
|
|
|
2020-01-13 10:07:53 -05:00
|
|
|
return render status: :accepted, json: {
|
|
|
|
message: _('Job to create self-monitoring project is in progress')
|
|
|
|
}
|
|
|
|
end
|
|
|
|
|
2020-01-29 07:09:08 -05:00
|
|
|
if @application_setting.self_monitoring_project_id.present?
|
|
|
|
return render status: :ok, json: self_monitoring_data
|
|
|
|
end
|
|
|
|
|
2020-01-13 10:07:53 -05:00
|
|
|
render status: :bad_request, json: {
|
|
|
|
message: _('Self-monitoring project does not exist. Please check logs ' \
|
|
|
|
'for any error messages')
|
|
|
|
}
|
|
|
|
end
|
|
|
|
|
2020-01-29 07:09:08 -05:00
|
|
|
# Specs are in spec/requests/self_monitoring_project_spec.rb
|
2020-01-13 10:07:53 -05:00
|
|
|
def delete_self_monitoring_project
|
2020-02-14 16:09:08 -05:00
|
|
|
job_id = SelfMonitoringProjectDeleteWorker.perform_async # rubocop:disable CodeReuse/Worker
|
2020-01-13 10:07:53 -05:00
|
|
|
|
|
|
|
render status: :accepted, json: {
|
|
|
|
job_id: job_id,
|
|
|
|
monitor_status: status_delete_self_monitoring_project_admin_application_settings_path
|
|
|
|
}
|
|
|
|
end
|
|
|
|
|
2020-01-29 07:09:08 -05:00
|
|
|
# Specs are in spec/requests/self_monitoring_project_spec.rb
|
2020-01-13 10:07:53 -05:00
|
|
|
def status_delete_self_monitoring_project
|
|
|
|
job_id = params[:job_id].to_s
|
|
|
|
|
|
|
|
unless job_id.length <= PARAM_JOB_ID_MAX_SIZE
|
|
|
|
return render status: :bad_request, json: {
|
|
|
|
message: _('Parameter "job_id" cannot exceed length of %{job_id_max_size}' %
|
|
|
|
{ job_id_max_size: PARAM_JOB_ID_MAX_SIZE })
|
|
|
|
}
|
|
|
|
end
|
2020-01-08 04:07:53 -05:00
|
|
|
|
2020-02-14 16:09:08 -05:00
|
|
|
if SelfMonitoringProjectDeleteWorker.in_progress?(job_id) # rubocop:disable CodeReuse/Worker
|
2020-01-13 10:07:53 -05:00
|
|
|
::Gitlab::PollingInterval.set_header(response, interval: 3_000)
|
|
|
|
|
|
|
|
return render status: :accepted, json: {
|
|
|
|
message: _('Job to delete self-monitoring project is in progress')
|
2020-01-08 04:07:53 -05:00
|
|
|
}
|
|
|
|
end
|
2020-01-13 10:07:53 -05:00
|
|
|
|
2020-01-29 07:09:08 -05:00
|
|
|
if @application_setting.self_monitoring_project_id.nil?
|
|
|
|
return render status: :ok, json: {
|
|
|
|
message: _('Self-monitoring project has been successfully deleted')
|
|
|
|
}
|
|
|
|
end
|
|
|
|
|
2020-01-13 10:07:53 -05:00
|
|
|
render status: :bad_request, json: {
|
|
|
|
message: _('Self-monitoring project was not deleted. Please check logs ' \
|
|
|
|
'for any error messages')
|
|
|
|
}
|
2020-01-08 04:07:53 -05:00
|
|
|
end
|
|
|
|
|
2015-01-08 03:22:50 -05:00
|
|
|
private
|
|
|
|
|
2020-01-08 04:07:53 -05:00
|
|
|
def self_monitoring_data
|
|
|
|
{
|
2020-01-29 07:09:08 -05:00
|
|
|
project_id: @application_setting.self_monitoring_project_id,
|
|
|
|
project_full_path: @application_setting.self_monitoring_project&.full_path
|
2020-01-08 04:07:53 -05:00
|
|
|
}
|
|
|
|
end
|
|
|
|
|
2015-01-08 03:22:50 -05:00
|
|
|
def set_application_setting
|
2019-07-01 19:44:54 -04:00
|
|
|
@application_setting = ApplicationSetting.current_without_cache
|
2020-09-18 05:09:32 -04:00
|
|
|
@plans = Plan.all
|
2015-01-08 03:22:50 -05:00
|
|
|
end
|
|
|
|
|
2021-03-16 14:11:53 -04:00
|
|
|
def disable_query_limiting
|
2021-03-24 23:09:35 -04:00
|
|
|
Gitlab::QueryLimiting.disable!('https://gitlab.com/gitlab-org/gitlab/-/issues/29418')
|
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("")
|
2021-06-21 17:08:33 -04:00
|
|
|
params[:application_setting][:valid_runner_registrars]&.delete("")
|
2017-07-05 06:45:58 -04:00
|
|
|
params[:application_setting][:restricted_visibility_levels]&.delete("")
|
2021-06-16 20:10:17 -04:00
|
|
|
|
|
|
|
if params[:application_setting].key?(:required_instance_ci_template)
|
|
|
|
params[:application_setting][:required_instance_ci_template] = nil if params[:application_setting][:required_instance_ci_template].empty?
|
|
|
|
end
|
2020-05-27 17:08:05 -04:00
|
|
|
|
|
|
|
remove_blank_params_for!(:elasticsearch_aws_secret_access_key, :eks_secret_access_key)
|
|
|
|
|
2020-10-29 02:08:45 -04:00
|
|
|
# TODO Remove domain_denylist_raw in APIv5 (See https://gitlab.com/gitlab-org/gitlab-foss/issues/67204)
|
|
|
|
params.delete(:domain_denylist_raw) if params[:domain_denylist_file]
|
2020-11-10 07:08:57 -05:00
|
|
|
params.delete(:domain_denylist_raw) if params[:domain_denylist]
|
|
|
|
params.delete(:domain_allowlist_raw) if params[:domain_allowlist]
|
2016-05-10 04:29:19 -04:00
|
|
|
|
2021-06-16 20:10:17 -04:00
|
|
|
params[:application_setting].permit(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,
|
2021-02-16 22:08:59 -05:00
|
|
|
*ApplicationSetting.kroki_formats_attributes.keys.map { |key| "kroki_formats_#{key}".to_sym },
|
2019-07-12 12:53:44 -04:00
|
|
|
:lets_encrypt_notification_email,
|
|
|
|
:lets_encrypt_terms_of_service_accepted,
|
2020-10-29 02:08:45 -04:00
|
|
|
:domain_denylist_file,
|
2019-07-24 15:49:31 -04:00
|
|
|
:raw_blob_request_limit,
|
2020-04-14 11:09:44 -04:00
|
|
|
:issues_create_limit,
|
2021-02-09 16:09:19 -05:00
|
|
|
:notes_create_limit,
|
2020-07-01 17:08:51 -04:00
|
|
|
:default_branch_name,
|
2017-01-10 08:40:08 -05:00
|
|
|
disabled_oauth_sign_in_sources: [],
|
|
|
|
import_sources: [],
|
2021-03-11 10:09:10 -05:00
|
|
|
restricted_visibility_levels: [],
|
2021-06-21 17:08:33 -04:00
|
|
|
repository_storages_weighted: {},
|
|
|
|
valid_runner_registrars: []
|
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
|
2021-06-15 11:10:04 -04:00
|
|
|
successful = ::ApplicationSettings::UpdateService
|
2019-02-20 11:56:19 -05:00
|
|
|
.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
|
|
|
|
|
2020-02-10 07:08:59 -05:00
|
|
|
redirect_path = referer_path(request) || general_admin_application_settings_path
|
2019-02-20 11:56:19 -05:00
|
|
|
|
|
|
|
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
|
|
|
|
2020-03-02 10:08:01 -05:00
|
|
|
flash[:alert] = _('Application settings update failed')
|
|
|
|
|
2019-02-20 11:56:19 -05:00
|
|
|
render action
|
|
|
|
end
|
2019-10-07 17:07:54 -04:00
|
|
|
|
2020-05-27 17:08:05 -04:00
|
|
|
def remove_blank_params_for!(*keys)
|
|
|
|
params[:application_setting].delete_if { |setting, value| setting.to_sym.in?(keys) && value.blank? }
|
|
|
|
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
|
|
|
|
2021-05-11 17:10:21 -04:00
|
|
|
Admin::ApplicationSettingsController.prepend_mod_with('Admin::ApplicationSettingsController')
|