Commit 5d34d5af authored by Sean McGivern's avatar Sean McGivern

Strip trailing slash when finding performance bar group

This treats `gitlab` and `gitlab/` as the same group for the purposes of
setting the allowed performance bar group.
parent 08809e06
......@@ -20,7 +20,7 @@ module ApplicationSettings
add_to_outbound_local_requests_whitelist(@params.delete(:add_to_outbound_local_requests_whitelist))
if params.key?(:performance_bar_allowed_group_path)
group_id = performance_bar_allowed_group_id
group_id = process_performance_bar_allowed_group_id
return false if application_setting.errors.any?
......@@ -69,22 +69,20 @@ module ApplicationSettings
@application_setting.reset_memoized_terms
end
def performance_bar_allowed_group_id
def process_performance_bar_allowed_group_id
group_full_path = params.delete(:performance_bar_allowed_group_path)
enable_param_set = params.key?(:performance_bar_enabled)
enable_param_on = Gitlab::Utils.to_boolean(params.delete(:performance_bar_enabled))
performance_bar_disabled_by_user = enable_param_set && !enable_param_on
performance_bar_enabled = !enable_param_set || enable_param_on
performance_bar_enabled = enable_param_on.nil? || enable_param_on # Default to true
return if group_full_path.blank?
return if performance_bar_disabled_by_user
return if enable_param_on == false # Explicitly disabling
unless performance_bar_enabled
application_setting.errors.add(:performance_bar_allowed_group_id, 'not allowed when performance bar is disabled')
return
end
group = Group.find_by_full_path(group_full_path)
group = Group.find_by_full_path(group_full_path.chomp('/'))
unless group
application_setting.errors.add(:performance_bar_allowed_group_id, 'not found')
......
......@@ -159,6 +159,7 @@ describe ApplicationSettings::UpdateService do
true | 'foo' | 42_000_000 | 42_000_000 | false
true | 'group_a' | nil | 42_000_000 | true
true | 'group_b' | 42_000_000 | 43_000_000 | true
true | 'group_b/' | 42_000_000 | 43_000_000 | true
true | 'group_a' | 42_000_000 | 42_000_000 | true
false | '' | nil | nil | true
false | '' | 42_000_000 | nil | true
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment