2018-12-05 23:21:45 +05:30
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2015-04-26 12:48:37 +05:30
|
|
|
class Admin::ApplicationSettingsController < Admin::ApplicationController
|
2018-12-05 23:21:45 +05:30
|
|
|
include InternalRedirect
|
2021-01-03 14:25:43 +05:30
|
|
|
include ServicesHelper
|
2019-09-04 21:01:54 +05:30
|
|
|
|
2020-03-13 15:44:24 +05:30
|
|
|
# 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-24 23:13:21 +05:30
|
|
|
# ApplicationSetting model uses Gitlab::ProcessMemoryCache for caching and the
|
2020-03-13 15:44:24 +05:30
|
|
|
# cache might be stale immediately after an update.
|
|
|
|
# https://gitlab.com/gitlab-org/gitlab-foss/-/merge_requests/30233
|
2020-04-22 19:07:51 +05:30
|
|
|
before_action :set_application_setting, except: :integrations
|
2020-03-13 15:44:24 +05:30
|
|
|
|
2019-09-04 21:01:54 +05:30
|
|
|
before_action :whitelist_query_limiting, only: [:usage_data]
|
2015-04-26 12:48:37 +05:30
|
|
|
|
2020-06-23 00:09:42 +05:30
|
|
|
before_action only: [:ci_cd] do
|
|
|
|
push_frontend_feature_flag(:ci_instance_variables_ui, default_enabled: true)
|
|
|
|
end
|
|
|
|
|
2021-01-03 14:25:43 +05:30
|
|
|
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]
|
|
|
|
feature_category :collection, [:usage_data]
|
|
|
|
feature_category :integrations, [:integrations]
|
|
|
|
feature_category :pages, [:lets_encrypt_terms_of_service]
|
|
|
|
|
2020-10-24 23:57:45 +05:30
|
|
|
VALID_SETTING_PANELS = %w(general repository
|
2019-09-30 21:07:59 +05:30
|
|
|
ci_cd reporting metrics_and_profiling
|
2019-12-21 20:55:43 +05:30
|
|
|
network preferences).freeze
|
2018-12-05 23:21:45 +05:30
|
|
|
|
2020-03-13 15:44:24 +05:30
|
|
|
# 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-12-04 20:38:33 +05:30
|
|
|
VALID_SETTING_PANELS.each do |action|
|
|
|
|
define_method(action) { perform_update if submitted? }
|
2018-12-05 23:21:45 +05:30
|
|
|
end
|
|
|
|
|
2020-04-22 19:07:51 +05:30
|
|
|
def integrations
|
2021-01-03 14:25:43 +05:30
|
|
|
return not_found unless instance_level_integrations?
|
|
|
|
|
2021-01-29 00:20:46 +05:30
|
|
|
@integrations = Service.find_or_initialize_all_non_project_specific(Service.for_instance).sort_by(&:title)
|
2020-04-22 19:07:51 +05:30
|
|
|
end
|
|
|
|
|
2015-04-26 12:48:37 +05:30
|
|
|
def update
|
2019-09-30 21:07:59 +05:30
|
|
|
perform_update
|
2015-04-26 12:48:37 +05:30
|
|
|
end
|
|
|
|
|
2017-08-17 22:00:37 +05:30
|
|
|
def usage_data
|
|
|
|
respond_to do |format|
|
|
|
|
format.html do
|
2020-05-24 23:13:21 +05:30
|
|
|
usage_data_json = Gitlab::Json.pretty_generate(Gitlab::UsageData.data)
|
2017-08-17 22:00:37 +05:30
|
|
|
|
2018-12-13 13:39:08 +05:30
|
|
|
render html: Gitlab::Highlight.highlight('payload.json', usage_data_json, language: 'json')
|
2017-08-17 22:00:37 +05:30
|
|
|
end
|
|
|
|
format.json { render json: Gitlab::UsageData.to_json }
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2018-12-05 23:21:45 +05:30
|
|
|
def reset_registration_token
|
2015-12-23 02:04:40 +05:30
|
|
|
@application_setting.reset_runners_registration_token!
|
2018-12-05 23:21:45 +05:30
|
|
|
|
2019-07-07 11:18:12 +05:30
|
|
|
flash[:notice] = _('New runners registration token has been generated!')
|
2015-12-23 02:04:40 +05:30
|
|
|
redirect_to admin_runners_path
|
|
|
|
end
|
|
|
|
|
2016-06-02 11:05:42 +05:30
|
|
|
def reset_health_check_token
|
|
|
|
@application_setting.reset_health_check_access_token!
|
2019-07-07 11:18:12 +05:30
|
|
|
flash[:notice] = _('New health check access token has been generated!')
|
2019-02-15 15:39:39 +05:30
|
|
|
redirect_back_or_default
|
2016-06-02 11:05:42 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
def clear_repository_check_states
|
2020-03-13 15:44:24 +05:30
|
|
|
RepositoryCheck::ClearWorker.perform_async # rubocop:disable CodeReuse/Worker
|
2016-06-02 11:05:42 +05:30
|
|
|
|
|
|
|
redirect_to(
|
2020-03-13 15:44:24 +05:30
|
|
|
general_admin_application_settings_path,
|
2019-07-07 11:18:12 +05:30
|
|
|
notice: _('Started asynchronous removal of all repository check states.')
|
2016-06-02 11:05:42 +05:30
|
|
|
)
|
|
|
|
end
|
|
|
|
|
2019-09-04 21:01:54 +05:30
|
|
|
# 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-03-13 15:44:24 +05:30
|
|
|
# Specs are in spec/requests/self_monitoring_project_spec.rb
|
|
|
|
def create_self_monitoring_project
|
|
|
|
job_id = SelfMonitoringProjectCreateWorker.perform_async # rubocop:disable CodeReuse/Worker
|
|
|
|
|
|
|
|
render status: :accepted, json: {
|
|
|
|
job_id: job_id,
|
|
|
|
monitor_status: status_create_self_monitoring_project_admin_application_settings_path
|
|
|
|
}
|
|
|
|
end
|
|
|
|
|
|
|
|
# Specs are in spec/requests/self_monitoring_project_spec.rb
|
|
|
|
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
|
|
|
|
|
|
|
|
if SelfMonitoringProjectCreateWorker.in_progress?(job_id) # rubocop:disable CodeReuse/Worker
|
|
|
|
::Gitlab::PollingInterval.set_header(response, interval: 3_000)
|
|
|
|
|
|
|
|
return render status: :accepted, json: {
|
|
|
|
message: _('Job to create self-monitoring project is in progress')
|
|
|
|
}
|
|
|
|
end
|
|
|
|
|
|
|
|
if @application_setting.self_monitoring_project_id.present?
|
|
|
|
return render status: :ok, json: self_monitoring_data
|
|
|
|
end
|
|
|
|
|
|
|
|
render status: :bad_request, json: {
|
|
|
|
message: _('Self-monitoring project does not exist. Please check logs ' \
|
|
|
|
'for any error messages')
|
|
|
|
}
|
|
|
|
end
|
|
|
|
|
|
|
|
# Specs are in spec/requests/self_monitoring_project_spec.rb
|
|
|
|
def delete_self_monitoring_project
|
|
|
|
job_id = SelfMonitoringProjectDeleteWorker.perform_async # rubocop:disable CodeReuse/Worker
|
|
|
|
|
|
|
|
render status: :accepted, json: {
|
|
|
|
job_id: job_id,
|
|
|
|
monitor_status: status_delete_self_monitoring_project_admin_application_settings_path
|
|
|
|
}
|
|
|
|
end
|
|
|
|
|
|
|
|
# Specs are in spec/requests/self_monitoring_project_spec.rb
|
|
|
|
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
|
|
|
|
|
|
|
|
if SelfMonitoringProjectDeleteWorker.in_progress?(job_id) # rubocop:disable CodeReuse/Worker
|
|
|
|
::Gitlab::PollingInterval.set_header(response, interval: 3_000)
|
|
|
|
|
|
|
|
return render status: :accepted, json: {
|
|
|
|
message: _('Job to delete self-monitoring project is in progress')
|
|
|
|
}
|
|
|
|
end
|
|
|
|
|
|
|
|
if @application_setting.self_monitoring_project_id.nil?
|
|
|
|
return render status: :ok, json: {
|
|
|
|
message: _('Self-monitoring project has been successfully deleted')
|
|
|
|
}
|
|
|
|
end
|
|
|
|
|
|
|
|
render status: :bad_request, json: {
|
|
|
|
message: _('Self-monitoring project was not deleted. Please check logs ' \
|
|
|
|
'for any error messages')
|
|
|
|
}
|
|
|
|
end
|
|
|
|
|
2015-04-26 12:48:37 +05:30
|
|
|
private
|
|
|
|
|
2020-03-13 15:44:24 +05:30
|
|
|
def self_monitoring_data
|
|
|
|
{
|
|
|
|
project_id: @application_setting.self_monitoring_project_id,
|
|
|
|
project_full_path: @application_setting.self_monitoring_project&.full_path
|
|
|
|
}
|
|
|
|
end
|
|
|
|
|
2015-04-26 12:48:37 +05:30
|
|
|
def set_application_setting
|
2019-09-30 21:07:59 +05:30
|
|
|
@application_setting = ApplicationSetting.current_without_cache
|
2020-11-24 15:15:51 +05:30
|
|
|
@plans = Plan.all
|
2015-04-26 12:48:37 +05:30
|
|
|
end
|
|
|
|
|
2019-09-04 21:01:54 +05:30
|
|
|
def whitelist_query_limiting
|
2019-12-04 20:38:33 +05:30
|
|
|
Gitlab::QueryLimiting.whitelist('https://gitlab.com/gitlab-org/gitlab-foss/issues/63107')
|
2019-09-04 21:01:54 +05:30
|
|
|
end
|
|
|
|
|
2015-04-26 12:48:37 +05:30
|
|
|
def application_setting_params
|
2018-05-09 12:01:36 +05:30
|
|
|
params[:application_setting] ||= {}
|
2015-09-25 12:07:36 +05:30
|
|
|
|
2018-05-09 12:01:36 +05:30
|
|
|
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-06-02 11:05:42 +05:30
|
|
|
|
2018-05-09 12:01:36 +05:30
|
|
|
params[:application_setting][:disabled_oauth_sign_in_sources] =
|
|
|
|
AuthHelper.button_based_providers.map(&:to_s) -
|
|
|
|
Array(enabled_oauth_sign_in_sources)
|
|
|
|
end
|
2017-09-10 17:25:29 +05:30
|
|
|
|
2018-05-09 12:01:36 +05:30
|
|
|
params[:application_setting][:import_sources]&.delete("")
|
2017-09-10 17:25:29 +05:30
|
|
|
params[:application_setting][:restricted_visibility_levels]&.delete("")
|
2020-04-22 19:07:51 +05:30
|
|
|
params[:application_setting][:required_instance_ci_template] = nil if params[:application_setting][:required_instance_ci_template].blank?
|
2020-05-30 21:06:31 +05:30
|
|
|
|
|
|
|
remove_blank_params_for!(:elasticsearch_aws_secret_access_key, :eks_secret_access_key)
|
|
|
|
|
2021-01-29 00:20:46 +05:30
|
|
|
# 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]
|
|
|
|
params.delete(:domain_denylist_raw) if params[:domain_denylist]
|
|
|
|
params.delete(:domain_allowlist_raw) if params[:domain_allowlist]
|
2016-06-02 11:05:42 +05:30
|
|
|
|
2015-04-26 12:48:37 +05:30
|
|
|
params.require(:application_setting).permit(
|
2017-09-10 17:25:29 +05:30
|
|
|
visible_application_setting_attributes
|
2017-08-17 22:00:37 +05:30
|
|
|
)
|
|
|
|
end
|
|
|
|
|
2018-11-20 20:47:30 +05:30
|
|
|
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-09-10 17:25:29 +05:30
|
|
|
def visible_application_setting_attributes
|
2019-07-07 11:18:12 +05:30
|
|
|
[
|
|
|
|
*::ApplicationSettingsHelper.visible_attributes,
|
|
|
|
*::ApplicationSettingsHelper.external_authorization_service_attributes,
|
2020-06-23 00:09:42 +05:30
|
|
|
*ApplicationSetting.repository_storages_weighted_attributes,
|
2019-09-30 21:07:59 +05:30
|
|
|
:lets_encrypt_notification_email,
|
|
|
|
:lets_encrypt_terms_of_service_accepted,
|
2021-01-29 00:20:46 +05:30
|
|
|
:domain_denylist_file,
|
2019-10-12 21:52:04 +05:30
|
|
|
:raw_blob_request_limit,
|
2020-04-22 19:07:51 +05:30
|
|
|
:issues_create_limit,
|
2020-07-28 23:09:34 +05:30
|
|
|
:default_branch_name,
|
2017-08-17 22:00:37 +05:30
|
|
|
disabled_oauth_sign_in_sources: [],
|
|
|
|
import_sources: [],
|
2016-11-24 13:41:30 +05:30
|
|
|
repository_storages: [],
|
2018-12-05 23:21:45 +05:30
|
|
|
restricted_visibility_levels: []
|
2017-08-17 22:00:37 +05:30
|
|
|
]
|
2015-04-26 12:48:37 +05:30
|
|
|
end
|
2019-07-31 22:56:46 +05:30
|
|
|
|
2019-09-30 21:07:59 +05:30
|
|
|
def submitted?
|
|
|
|
request.patch?
|
|
|
|
end
|
2019-07-31 22:56:46 +05:30
|
|
|
|
2019-09-30 21:07:59 +05:30
|
|
|
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
|
|
|
|
|
2020-03-13 15:44:24 +05:30
|
|
|
redirect_path = referer_path(request) || general_admin_application_settings_path
|
2019-09-30 21:07:59 +05:30
|
|
|
|
|
|
|
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-12-21 20:55:43 +05:30
|
|
|
action = valid_setting_panels.include?(action_name) ? action_name : :general
|
2019-09-30 21:07:59 +05:30
|
|
|
|
2020-04-08 14:13:33 +05:30
|
|
|
flash[:alert] = _('Application settings update failed')
|
|
|
|
|
2019-09-30 21:07:59 +05:30
|
|
|
render action
|
2019-07-31 22:56:46 +05:30
|
|
|
end
|
2019-12-21 20:55:43 +05:30
|
|
|
|
2020-05-30 21:06:31 +05:30
|
|
|
def remove_blank_params_for!(*keys)
|
|
|
|
params[:application_setting].delete_if { |setting, value| setting.to_sym.in?(keys) && value.blank? }
|
|
|
|
end
|
|
|
|
|
2019-12-21 20:55:43 +05:30
|
|
|
# overridden in EE
|
|
|
|
def valid_setting_panels
|
|
|
|
VALID_SETTING_PANELS
|
|
|
|
end
|
2015-04-26 12:48:37 +05:30
|
|
|
end
|
2019-12-04 20:38:33 +05:30
|
|
|
|
|
|
|
Admin::ApplicationSettingsController.prepend_if_ee('EE::Admin::ApplicationSettingsController')
|