2018-07-16 12:31:01 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2017-01-20 10:00:19 -05:00
|
|
|
module ApplicationSettings
|
|
|
|
class UpdateService < ApplicationSettings::BaseService
|
2018-06-04 15:37:43 -04:00
|
|
|
attr_reader :params, :application_setting
|
|
|
|
|
2017-01-20 10:00:19 -05:00
|
|
|
def execute
|
2018-04-24 12:28:04 -04:00
|
|
|
update_terms(@params.delete(:terms))
|
|
|
|
|
2018-05-25 12:44:15 -04:00
|
|
|
if params.key?(:performance_bar_allowed_group_path)
|
|
|
|
params[:performance_bar_allowed_group_id] = performance_bar_allowed_group_id
|
|
|
|
end
|
|
|
|
|
2018-09-07 10:32:28 -04:00
|
|
|
if usage_stats_updated? && !params.delete(:skip_usage_stats_user)
|
|
|
|
params[:usage_stats_set_by_user_id] = current_user.id
|
|
|
|
end
|
|
|
|
|
2017-01-20 10:00:19 -05:00
|
|
|
@application_setting.update(@params)
|
|
|
|
end
|
2018-04-24 12:28:04 -04:00
|
|
|
|
|
|
|
private
|
|
|
|
|
2018-09-07 10:32:28 -04:00
|
|
|
def usage_stats_updated?
|
|
|
|
params.key?(:usage_ping_enabled) || params.key?(:version_check_enabled)
|
|
|
|
end
|
|
|
|
|
2018-04-24 12:28:04 -04:00
|
|
|
def update_terms(terms)
|
|
|
|
return unless terms.present?
|
|
|
|
|
|
|
|
# Avoid creating a new terms record if the text is exactly the same.
|
|
|
|
terms = terms.strip
|
|
|
|
return if terms == @application_setting.terms
|
|
|
|
|
|
|
|
ApplicationSetting::Term.create(terms: terms)
|
|
|
|
@application_setting.reset_memoized_terms
|
|
|
|
end
|
2018-05-25 12:44:15 -04:00
|
|
|
|
|
|
|
def performance_bar_allowed_group_id
|
|
|
|
performance_bar_enabled = !params.key?(:performance_bar_enabled) || params.delete(:performance_bar_enabled)
|
|
|
|
group_full_path = params.delete(:performance_bar_allowed_group_path)
|
|
|
|
return nil unless Gitlab::Utils.to_boolean(performance_bar_enabled)
|
|
|
|
|
|
|
|
Group.find_by_full_path(group_full_path)&.id if group_full_path.present?
|
|
|
|
end
|
2017-01-20 10:00:19 -05:00
|
|
|
end
|
|
|
|
end
|