Commit c3b1cb71 authored by Toon Claes's avatar Toon Claes

Override setters so it also accepts string visibility levels

Override the `ApplicationSetting` default visibility_level setters so
they accept strings & integers for the levels.
parent a3fdd6ac
......@@ -278,6 +278,22 @@ class ApplicationSetting < ActiveRecord::Base
self.repository_storages = [value]
end
def default_project_visibility=(level)
super(Gitlab::VisibilityLevel.level_value(level))
end
def default_snippet_visibility=(level)
super(Gitlab::VisibilityLevel.level_value(level))
end
def default_group_visibility=(level)
super(Gitlab::VisibilityLevel.level_value(level))
end
def restricted_visibility_levels=(levels)
super(levels.map { |level| Gitlab::VisibilityLevel.level_value(level) })
end
# Choose one of the available repository storage options. Currently all have
# equal weighting.
def pick_repository_storage
......
......@@ -7,20 +7,6 @@ module API
@current_setting ||=
(ApplicationSetting.current || ApplicationSetting.create_from_defaults)
end
def map_setting_visibility_levels(attrs)
[:default_project_visibility, :default_snippet_visibility, :default_group_visibility].each do |param|
visibility = attrs.delete(param)
if visibility
attrs[param] = Gitlab::VisibilityLevel.string_options[visibility]
end
end
restricted_levels = attrs.delete(:restricted_visibility_levels)
if restricted_levels
attrs[:restricted_visibility_levels] = Gitlab::VisibilityLevel.string_options.values_at(*restricted_levels)
end
attrs
end
end
desc 'Get the current application settings' do
......@@ -142,7 +128,7 @@ module API
:housekeeping_enabled, :terminal_max_session_time
end
put "application/settings" do
attrs = map_setting_visibility_levels(declared_params(include_missing: false))
attrs = declared_params(include_missing: false)
if current_settings.update_attributes(attrs)
present current_settings, with: Entities::ApplicationSetting
......
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