debian-mirror-gitlab/app/controllers/admin/application_settings_controller.rb

136 lines
3.4 KiB
Ruby
Raw Normal View History

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
2015-09-11 14:41:01 +05:30
before_action :set_application_setting
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 }
2018-12-05 23:21:45 +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
2015-12-23 02:04:40 +05:30
flash[:notice] = 'New runners registration token has been generated!'
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!
flash[:notice] = 'New health check access token has been generated!'
redirect_to :back
end
def clear_repository_check_states
RepositoryCheck::ClearWorker.perform_async
redirect_to(
admin_application_settings_path,
notice: 'Started asynchronous removal of all repository check states.'
)
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
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
ApplicationSettingsHelper.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
end