diff options
Diffstat (limited to 'app/services/groups')
-rw-r--r-- | app/services/groups/transfer_service.rb | 16 | ||||
-rw-r--r-- | app/services/groups/update_service.rb | 16 |
2 files changed, 31 insertions, 1 deletions
diff --git a/app/services/groups/transfer_service.rb b/app/services/groups/transfer_service.rb index f2fb494500d..2bd571f60af 100644 --- a/app/services/groups/transfer_service.rb +++ b/app/services/groups/transfer_service.rb @@ -47,6 +47,19 @@ module Groups raise_transfer_error(:namespace_with_same_path) if namespace_with_same_path? raise_transfer_error(:group_contains_images) if group_projects_contain_registry_images? raise_transfer_error(:cannot_transfer_to_subgroup) if transfer_to_subgroup? + raise_transfer_error(:group_contains_npm_packages) if group_with_npm_packages? + end + + def group_with_npm_packages? + return false unless group.packages_feature_enabled? + + npm_packages = ::Packages::GroupPackagesFinder.new(current_user, group, package_type: :npm).execute + + different_root_ancestor? && npm_packages.exists? + end + + def different_root_ancestor? + group.root_ancestor != new_parent_group&.root_ancestor end def group_is_already_root? @@ -144,7 +157,8 @@ module Groups same_parent_as_current: s_('TransferGroup|Group is already associated to the parent group.'), invalid_policies: s_("TransferGroup|You don't have enough permissions."), group_contains_images: s_('TransferGroup|Cannot update the path because there are projects under this group that contain Docker images in their Container Registry. Please remove the images from your projects first and try again.'), - cannot_transfer_to_subgroup: s_('TransferGroup|Cannot transfer group to one of its subgroup.') + cannot_transfer_to_subgroup: s_('TransferGroup|Cannot transfer group to one of its subgroup.'), + group_contains_npm_packages: s_('TransferGroup|Group contains projects with NPM packages.') }.freeze end end diff --git a/app/services/groups/update_service.rb b/app/services/groups/update_service.rb index 948540619ae..81393681dc0 100644 --- a/app/services/groups/update_service.rb +++ b/app/services/groups/update_service.rb @@ -17,6 +17,8 @@ module Groups return false unless valid_share_with_group_lock_change? + return false unless valid_path_change_with_npm_packages? + before_assignment_hook(group, params) group.assign_attributes(params) @@ -36,6 +38,20 @@ module Groups private + def valid_path_change_with_npm_packages? + return true unless group.packages_feature_enabled? + return true if params[:path].blank? + return true if !group.has_parent? && group.path == params[:path] + + npm_packages = ::Packages::GroupPackagesFinder.new(current_user, group, package_type: :npm).execute + if npm_packages.exists? + group.errors.add(:path, s_('GroupSettings|cannot change when group contains projects with NPM packages')) + return + end + + true + end + def before_assignment_hook(group, params) # overridden in EE end |