Commit 7a6d820a authored by Jarka Košanová's avatar Jarka Košanová

Fix transfering groups to root for EE

parent 7a8057fd
---
title: Fix transferring groups to root when EE features are enabled
merge_request: 21915
author:
type: fixed
......@@ -17,7 +17,7 @@ module EE
return unless group.packages_feature_available?
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)
end
end
......@@ -44,8 +44,8 @@ module EE
raise ::Groups::TransferService::TransferError, EE_ERROR_MESSAGES[message]
end
def new_parent_group_has_same_root_ancestor?
group.root_ancestor == new_parent_group.root_ancestor
def different_root_ancestor?
group.root_ancestor != new_parent_group&.root_ancestor
end
end
end
......
......@@ -12,7 +12,7 @@ describe Groups::TransferService, '#execute' do
before do
stub_licensed_features(packages: true)
group.add_owner(user)
new_group.add_owner(user)
new_group&.add_owner(user)
end
context 'with an npm package' do
......@@ -50,6 +50,25 @@ describe Groups::TransferService, '#execute' do
expect(group.parent).to eq(new_group)
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
......
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