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
|
2019-09-04 21:01:54 +05:30
|
|
|
|
2015-09-11 14:41:01 +05:30
|
|
|
before_action :set_application_setting
|
2019-09-04 21:01:54 +05:30
|
|
|
before_action :whitelist_query_limiting, only: [:usage_data]
|
2015-04-26 12:48:37 +05:30
|
|
|
|
|
|
|
def show
|
|
|
|
end
|
|
|
|
|
2018-12-05 23:21:45 +05:30
|
|
|
def integrations
|
|
|
|
end
|
|
|
|
|
|
|
|
def repository
|
|
|
|
end
|
|
|
|
|
|
|
|
def templates
|
|
|
|
end
|
|
|
|
|
|
|
|
def ci_cd
|
|
|
|
end
|
|
|
|
|
|
|
|
def reporting
|
|
|
|
end
|
|
|
|
|
|
|
|
def metrics_and_profiling
|
|
|
|
end
|
|
|
|
|
|
|
|
def network
|
|
|
|
end
|
|
|
|
|
|
|
|
def geo
|
|
|
|
end
|
|
|
|
|
|
|
|
def preferences
|
|
|
|
end
|
|
|
|
|
2015-04-26 12:48:37 +05:30
|
|
|
def update
|
2017-08-17 22:00:37 +05:30
|
|
|
successful = ApplicationSettings::UpdateService
|
|
|
|
.new(@application_setting, current_user, application_setting_params)
|
|
|
|
.execute
|
|
|
|
|
2018-11-20 20:47:30 +05:30
|
|
|
if recheck_user_consent?
|
|
|
|
session[:ask_for_usage_stats_consent] = current_user.requires_usage_stats_consent?
|
|
|
|
end
|
|
|
|
|
2018-12-05 23:21:45 +05:30
|
|
|
redirect_path = referer_path(request) || admin_application_settings_path
|
|
|
|
|
2018-11-20 20:47:30 +05:30
|
|
|
respond_to do |format|
|
|
|
|
if successful
|
|
|
|
format.json { head :ok }
|
2019-07-07 11:18:12 +05:30
|
|
|
format.html { redirect_to redirect_path, notice: _('Application settings saved successfully') }
|
2018-11-20 20:47:30 +05:30
|
|
|
else
|
|
|
|
format.json { head :bad_request }
|
|
|
|
format.html { render :show }
|
|
|
|
end
|
2015-04-26 12:48:37 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2017-08-17 22:00:37 +05:30
|
|
|
def usage_data
|
|
|
|
respond_to do |format|
|
|
|
|
format.html do
|
2018-03-17 18:26:18 +05:30
|
|
|
usage_data_json = 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
|
|
|
|
RepositoryCheck::ClearWorker.perform_async
|
|
|
|
|
|
|
|
redirect_to(
|
|
|
|
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
|
|
|
|
|
2015-04-26 12:48:37 +05:30
|
|
|
private
|
|
|
|
|
|
|
|
def set_application_setting
|
2018-11-08 19:23:39 +05:30
|
|
|
@application_setting = Gitlab::CurrentSettings.current_application_settings
|
2015-04-26 12:48:37 +05:30
|
|
|
end
|
|
|
|
|
2019-09-04 21:01:54 +05:30
|
|
|
def whitelist_query_limiting
|
|
|
|
Gitlab::QueryLimiting.whitelist('https://gitlab.com/gitlab-org/gitlab-ce/issues/63107')
|
|
|
|
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("")
|
2016-08-24 12:49:21 +05:30
|
|
|
params.delete(:domain_blacklist_raw) if params[:domain_blacklist_file]
|
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,
|
2019-07-31 22:56:46 +05:30
|
|
|
*lets_encrypt_visible_attributes,
|
2016-08-24 12:49:21 +05:30
|
|
|
:domain_blacklist_file,
|
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
|
|
|
|
|
|
|
def lets_encrypt_visible_attributes
|
|
|
|
return [] unless Feature.enabled?(:pages_auto_ssl)
|
|
|
|
|
|
|
|
[
|
|
|
|
:lets_encrypt_notification_email,
|
|
|
|
:lets_encrypt_terms_of_service_accepted
|
|
|
|
]
|
|
|
|
end
|
2015-04-26 12:48:37 +05:30
|
|
|
end
|