Commit 170f9948 authored by Bob Van Landuyt's avatar Bob Van Landuyt

Hide `repository_mirrors` attributes from API

When the feature is not available
parent 40353620
......@@ -745,7 +745,10 @@ module API
class ApplicationSetting < Grape::Entity
expose :id
expose(*::ApplicationSettingsHelper.visible_attributes)
expose(*ApplicationSettingsHelper.visible_attributes)
expose(*EE::ApplicationSettingsHelper.repository_mirror_attributes, if: lambda do |_instance, _options|
::License.feature_available?(:repository_mirrors)
end)
expose(:restricted_visibility_levels) do |setting, _options|
setting.restricted_visibility_levels.map { |level| Gitlab::VisibilityLevel.string_level(level) }
end
......
......@@ -137,11 +137,17 @@ module API
optional :repository_storages, type: Array[String], desc: 'A list of names of enabled storage paths, taken from `gitlab.yml`. New projects will be created in one of these stores, chosen at random.'
optional :repository_size_limit, type: Integer, desc: 'Size limit per repository (MB)'
at_least_one_of(*::ApplicationSettingsHelper.visible_attributes)
all_attributes = ::EE::ApplicationSettingsHelper.repository_mirror_attributes + ApplicationSettingsHelper.visible_attributes
optional(*all_attributes)
at_least_one_of(*all_attributes)
end
put "application/settings" do
attrs = declared_params(include_missing: false)
unless ::License.feature_available?(:repository_mirrors)
attrs = attrs.except(*::EE::ApplicationSettingsHelper.repository_mirror_attributes)
end
if attrs.has_key?(:signin_enabled)
attrs[:password_authentication_enabled] = attrs.delete(:signin_enabled)
end
......
require 'spec_helper'
describe API::Settings, 'EE Settings' do # rubocop:disable RSpec/FilePath
include StubENV
let(:user) { create(:user) }
let(:admin) { create(:admin) }
before do
stub_env('IN_MEMORY_APPLICATION_SETTINGS', 'false')
end
describe "PUT /application/settings" do
it 'sets EE specific settings' do
put api("/application/settings", admin), help_text: 'Help text'
......@@ -12,4 +18,42 @@ describe API::Settings, 'EE Settings' do # rubocop:disable RSpec/FilePath
expect(json_response['help_text']).to eq('Help text')
end
end
context 'when the repository mirrors feature is not available' do
before do
stub_licensed_features(repository_mirrors: false)
get api("/application/settings", admin)
end
it 'hides repository mirror attributes when the feature is available' do
get api("/application/settings", admin)
expect(response).to have_http_status(200)
expect(json_response.keys).not_to include('mirror_max_capacity')
end
it 'does not update repository mirror attributes' do
expect { put api("/application/settings", admin), mirror_max_capacity: 15 }
.not_to change(ApplicationSetting.current.reload, :mirror_max_capacity)
end
end
context 'when the repository mirrors feature is available' do
before do
stub_licensed_features(repository_mirrors: true)
end
it 'has repository mirror attributes when the feature is available' do
get api("/application/settings", admin)
expect(response).to have_http_status(200)
expect(json_response.keys).to include('mirror_max_capacity')
end
it 'updates repository mirror attributes' do
put api("/application/settings", admin), mirror_max_capacity: 15
expect(ApplicationSetting.current.reload.mirror_max_capacity).to eq(15)
end
end
end
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