Commit 1ca9d9fd authored by Sean McGivern's avatar Sean McGivern

Merge branch 'fix-group-transfer' into 'master'

Fix transfering groups to root for EE

See merge request gitlab-org/gitlab!21915
parents 855bceb3 7a6d820a
---
title: Fix transferring groups to root when EE features are enabled
merge_request: 21915
author:
type: fixed
...@@ -17,7 +17,7 @@ module EE ...@@ -17,7 +17,7 @@ module EE
return unless group.packages_feature_available? return unless group.packages_feature_available?
npm_packages = Packages::GroupPackagesFinder.new(current_user, group, package_type: :npm).execute npm_packages = Packages::GroupPackagesFinder.new(current_user, group, package_type: :npm).execute
if !new_parent_group_has_same_root_ancestor? && npm_packages.exists? if different_root_ancestor? && npm_packages.exists?
raise_ee_transfer_error(:group_contains_npm_packages) raise_ee_transfer_error(:group_contains_npm_packages)
end end
end end
...@@ -44,8 +44,8 @@ module EE ...@@ -44,8 +44,8 @@ module EE
raise ::Groups::TransferService::TransferError, EE_ERROR_MESSAGES[message] raise ::Groups::TransferService::TransferError, EE_ERROR_MESSAGES[message]
end end
def new_parent_group_has_same_root_ancestor? def different_root_ancestor?
group.root_ancestor == new_parent_group.root_ancestor group.root_ancestor != new_parent_group&.root_ancestor
end end
end end
end end
......
...@@ -12,7 +12,7 @@ describe Groups::TransferService, '#execute' do ...@@ -12,7 +12,7 @@ describe Groups::TransferService, '#execute' do
before do before do
stub_licensed_features(packages: true) stub_licensed_features(packages: true)
group.add_owner(user) group.add_owner(user)
new_group.add_owner(user) new_group&.add_owner(user)
end end
context 'with an npm package' do context 'with an npm package' do
...@@ -50,6 +50,25 @@ describe Groups::TransferService, '#execute' do ...@@ -50,6 +50,25 @@ describe Groups::TransferService, '#execute' do
expect(group.parent).to eq(new_group) expect(group.parent).to eq(new_group)
end end
end end
context 'when transferring a group into a root group' do
let(:new_group) { nil }
it_behaves_like 'transfer not allowed'
end
end
end
context 'without an npm package' do
context 'when transferring a group into a root group' do
let(:group) { create(:group, parent: create(:group)) }
it 'allows transfer' do
transfer_service.execute(nil)
expect(transfer_service.error).not_to be
expect(group.parent).to be_nil
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