Commit 0f2adf6b authored by Vitali Tatarintev's avatar Vitali Tatarintev

Merge branch 'remove-pipeline-subscriptions-when-migrating-project-to-a-free-group' into 'master'

Delete pipeline subscriptions when migrating project to a free group

See merge request gitlab-org/gitlab!66695
parents 4ffbed29 67223c66
...@@ -49,6 +49,7 @@ module EE ...@@ -49,6 +49,7 @@ module EE
override :remove_paid_features override :remove_paid_features
def remove_paid_features def remove_paid_features
revoke_project_access_tokens revoke_project_access_tokens
delete_pipeline_subscriptions
end end
def revoke_project_access_tokens def revoke_project_access_tokens
...@@ -59,6 +60,12 @@ module EE ...@@ -59,6 +60,12 @@ module EE
.execute .execute
.update_all(revoked: true) .update_all(revoked: true)
end end
def delete_pipeline_subscriptions
return if new_namespace.licensed_feature_available?(:ci_project_subscriptions)
project.upstream_project_subscriptions.destroy_all # rubocop: disable Cop/DestroyAll
end
end end
end end
end end
...@@ -127,49 +127,80 @@ RSpec.describe Projects::TransferService do ...@@ -127,49 +127,80 @@ RSpec.describe Projects::TransferService do
end end
end end
describe 'project access tokens' do describe 'updating paid features' do
let_it_be(:premium_group) { create(:group_with_plan, plan: :premium_plan) } let_it_be(:premium_group) { create(:group_with_plan, plan: :premium_plan) }
let_it_be(:free_group) { create(:group) } let_it_be(:free_group) { create(:group) }
before do before do
premium_group.add_owner(user) premium_group.add_owner(user)
free_group.add_owner(user) free_group.add_owner(user)
ResourceAccessTokens::CreateService.new(user, project).execute
end
def revoked_tokens
PersonalAccessToken.without_impersonation.for_users(project.bots).revoked
end end
context 'with a self managed instance' do describe 'project access tokens' do
before do before do
stub_ee_application_setting(should_check_namespace_plan: false) ResourceAccessTokens::CreateService.new(user, project).execute
end end
it 'does not revoke PATs' do def revoked_tokens
subject.execute(group) PersonalAccessToken.without_impersonation.for_users(project.bots).revoked
end
context 'with a self managed instance' do
before do
stub_ee_application_setting(should_check_namespace_plan: false)
end
it 'does not revoke PATs' do
subject.execute(group)
expect { subject.execute(group) }.not_to change { revoked_tokens.count } expect { subject.execute(group) }.not_to change { revoked_tokens.count }
end
end
context 'with GL.com' do
before do
stub_ee_application_setting(should_check_namespace_plan: true)
end
context 'when target namespace has a premium plan' do
it 'does not revoke PATs' do
subject.execute(premium_group)
expect { subject.execute(group) }.not_to change { revoked_tokens.count }
end
end
context 'when target namespace has a free plan' do
it 'revoke PATs' do
expect { subject.execute(free_group) }.to change { revoked_tokens.count }.from(0).to(1)
end
end
end end
end end
context 'with GL.com' do describe 'pipeline subscriptions' do
let_it_be(:project_2) { create(:project, :public) }
before do before do
project.upstream_project_subscriptions.create!(upstream_project: project_2)
stub_ee_application_setting(should_check_namespace_plan: true) stub_ee_application_setting(should_check_namespace_plan: true)
end end
context 'when target namespace has a premium plan' do context 'when target namespace has a premium plan' do
it 'does not revoke PATs' do it 'does not delete the pipeline subscriptions' do
subject.execute(premium_group) subject.execute(premium_group)
expect { subject.execute(group) }.not_to change { revoked_tokens.count } expect { subject.execute(premium_group) }.not_to change { project.upstream_project_subscriptions.count }
end end
end end
context 'when target namespace has a free plan' do context 'when target namespace has a free plan' do
it 'revoke PATs' do it 'deletes the upstream subscriptions' do
expect { subject.execute(free_group) }.to change { revoked_tokens.count }.from(0).to(1) expect { subject.execute(free_group) }.to change { project.upstream_project_subscriptions.count }.from(1).to(0)
end
it 'deletes the downstream subscriptions' do
expect { subject.execute(free_group) }.to change { project_2.downstream_project_subscriptions.count }.from(1).to(0)
end end
end 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