Commit f5a2c1c3 authored by Bob Van Landuyt's avatar Bob Van Landuyt

Merge branch '342058-dp-setting-model' into 'master'

Build Dependency Proxy group setting on query

See merge request gitlab-org/gitlab!77553
parents a5e75990 b45f6426
...@@ -145,8 +145,7 @@ class Groups::DependencyProxyForContainersController < ::Groups::DependencyProxy ...@@ -145,8 +145,7 @@ class Groups::DependencyProxyForContainersController < ::Groups::DependencyProxy
end end
def dependency_proxy def dependency_proxy
@dependency_proxy ||= @dependency_proxy ||= group.dependency_proxy_setting
group.dependency_proxy_setting || group.create_dependency_proxy_setting
end end
def ensure_group def ensure_group
......
...@@ -776,6 +776,10 @@ class Group < Namespace ...@@ -776,6 +776,10 @@ class Group < Namespace
super || build_dependency_proxy_image_ttl_policy super || build_dependency_proxy_image_ttl_policy
end end
def dependency_proxy_setting
super || build_dependency_proxy_setting
end
def crm_enabled? def crm_enabled?
crm_settings&.enabled? crm_settings&.enabled?
end end
......
...@@ -178,10 +178,6 @@ RSpec.describe Groups::DependencyProxyForContainersController do ...@@ -178,10 +178,6 @@ RSpec.describe Groups::DependencyProxyForContainersController do
subject { get_manifest(tag) } subject { get_manifest(tag) }
context 'feature enabled' do context 'feature enabled' do
before do
enable_dependency_proxy
end
it_behaves_like 'without a token' it_behaves_like 'without a token'
it_behaves_like 'without permission' it_behaves_like 'without permission'
it_behaves_like 'feature flag disabled with private group' it_behaves_like 'feature flag disabled with private group'
...@@ -270,7 +266,6 @@ RSpec.describe Groups::DependencyProxyForContainersController do ...@@ -270,7 +266,6 @@ RSpec.describe Groups::DependencyProxyForContainersController do
let_it_be_with_reload(:group) { create(:group, parent: parent_group) } let_it_be_with_reload(:group) { create(:group, parent: parent_group) }
before do before do
parent_group.create_dependency_proxy_setting!(enabled: true)
group_deploy_token.update_column(:group_id, parent_group.id) group_deploy_token.update_column(:group_id, parent_group.id)
end end
...@@ -294,10 +289,6 @@ RSpec.describe Groups::DependencyProxyForContainersController do ...@@ -294,10 +289,6 @@ RSpec.describe Groups::DependencyProxyForContainersController do
subject { get_blob } subject { get_blob }
context 'feature enabled' do context 'feature enabled' do
before do
enable_dependency_proxy
end
it_behaves_like 'without a token' it_behaves_like 'without a token'
it_behaves_like 'without permission' it_behaves_like 'without permission'
it_behaves_like 'feature flag disabled with private group' it_behaves_like 'feature flag disabled with private group'
...@@ -341,7 +332,6 @@ RSpec.describe Groups::DependencyProxyForContainersController do ...@@ -341,7 +332,6 @@ RSpec.describe Groups::DependencyProxyForContainersController do
let_it_be_with_reload(:group) { create(:group, parent: parent_group) } let_it_be_with_reload(:group) { create(:group, parent: parent_group) }
before do before do
parent_group.create_dependency_proxy_setting!(enabled: true)
group_deploy_token.update_column(:group_id, parent_group.id) group_deploy_token.update_column(:group_id, parent_group.id)
end end
...@@ -474,10 +464,6 @@ RSpec.describe Groups::DependencyProxyForContainersController do ...@@ -474,10 +464,6 @@ RSpec.describe Groups::DependencyProxyForContainersController do
end end
end end
def enable_dependency_proxy
group.create_dependency_proxy_setting!(enabled: true)
end
def disable_dependency_proxy def disable_dependency_proxy
group.create_dependency_proxy_setting!(enabled: false) group.create_dependency_proxy_setting!(enabled: false)
end end
......
...@@ -2823,6 +2823,26 @@ RSpec.describe Group do ...@@ -2823,6 +2823,26 @@ RSpec.describe Group do
end end
end end
describe '#dependency_proxy_setting' do
subject(:setting) { group.dependency_proxy_setting }
it 'builds a new policy if one does not exist', :aggregate_failures do
expect(setting.enabled).to eq(true)
expect(setting).not_to be_persisted
end
context 'with existing policy' do
before do
group.dependency_proxy_setting.update!(enabled: false)
end
it 'returns the policy if it already exists', :aggregate_failures do
expect(setting.enabled).to eq(false)
expect(setting).to be_persisted
end
end
end
describe '#crm_enabled?' do describe '#crm_enabled?' do
it 'returns false where no crm_settings exist' do it 'returns false where no crm_settings exist' do
expect(group.crm_enabled?).to be_falsey expect(group.crm_enabled?).to be_falsey
......
...@@ -909,7 +909,6 @@ RSpec.describe GroupPolicy do ...@@ -909,7 +909,6 @@ RSpec.describe GroupPolicy do
context 'feature enabled' do context 'feature enabled' do
before do before do
stub_config(dependency_proxy: { enabled: true }) stub_config(dependency_proxy: { enabled: true })
group.create_dependency_proxy_setting!(enabled: true)
end end
context 'reporter' do context 'reporter' do
...@@ -955,7 +954,6 @@ RSpec.describe GroupPolicy do ...@@ -955,7 +954,6 @@ RSpec.describe GroupPolicy do
before do before do
stub_config(dependency_proxy: { enabled: true }) stub_config(dependency_proxy: { enabled: true })
group.create_dependency_proxy_setting!(enabled: true)
end end
it { is_expected.to be_allowed(:read_dependency_proxy) } it { is_expected.to be_allowed(:read_dependency_proxy) }
......
...@@ -499,9 +499,7 @@ RSpec.describe 'Rack Attack global throttles', :use_clean_rails_memory_store_cac ...@@ -499,9 +499,7 @@ RSpec.describe 'Rack Attack global throttles', :use_clean_rails_memory_store_cac
before do before do
group.add_owner(user) group.add_owner(user)
group.create_dependency_proxy_setting!(enabled: true)
other_group.add_owner(other_user) other_group.add_owner(other_user)
other_group.create_dependency_proxy_setting!(enabled: true)
allow(Gitlab.config.dependency_proxy) allow(Gitlab.config.dependency_proxy)
.to receive(:enabled).and_return(true) .to receive(:enabled).and_return(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