diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2022-04-20 13:00:54 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2022-04-20 13:00:54 +0300 |
commit | 3cccd102ba543e02725d247893729e5c73b38295 (patch) | |
tree | f36a04ec38517f5deaaacb5acc7d949688d1e187 /app/services/groups/transfer_service.rb | |
parent | 205943281328046ef7b4528031b90fbda70c75ac (diff) |
Add latest changes from gitlab-org/gitlab@14-10-stable-eev14.10.0-rc42
Diffstat (limited to 'app/services/groups/transfer_service.rb')
-rw-r--r-- | app/services/groups/transfer_service.rb | 33 |
1 files changed, 32 insertions, 1 deletions
diff --git a/app/services/groups/transfer_service.rb b/app/services/groups/transfer_service.rb index 10ff4961faf..f2e959396bc 100644 --- a/app/services/groups/transfer_service.rb +++ b/app/services/groups/transfer_service.rb @@ -25,10 +25,15 @@ module Groups private def proceed_to_transfer + old_root_ancestor_id = @group.root_ancestor.id + was_root_group = @group.root? + Group.transaction do update_group_attributes ensure_ownership update_integrations + remove_issue_contacts(old_root_ancestor_id, was_root_group) + update_crm_objects(was_root_group) end post_update_hooks(@updated_project_ids) @@ -53,6 +58,17 @@ module Groups 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? + raise_transfer_error(:no_permissions_to_migrate_crm) if no_permissions_to_migrate_crm? + end + + def no_permissions_to_migrate_crm? + return false unless group && @new_parent_group + return false if group.root_ancestor == @new_parent_group.root_ancestor + + return true if group.contacts.exists? && !current_user.can?(:admin_crm_contact, @new_parent_group.root_ancestor) + return true if group.organizations.exists? && !current_user.can?(:admin_crm_organization, @new_parent_group.root_ancestor) + + false end def group_with_npm_packages? @@ -202,7 +218,8 @@ module Groups 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.'), - group_contains_npm_packages: s_('TransferGroup|Group contains projects with NPM packages.') + group_contains_npm_packages: s_('TransferGroup|Group contains projects with NPM packages.'), + no_permissions_to_migrate_crm: s_("TransferGroup|Group contains contacts/organizations and you don't have enough permissions to move them to the new root group.") }.freeze end @@ -238,6 +255,20 @@ module Groups namespace_id: group.id } end + + def update_crm_objects(was_root_group) + return unless was_root_group + + CustomerRelations::Contact.move_to_root_group(group) + CustomerRelations::Organization.move_to_root_group(group) + end + + def remove_issue_contacts(old_root_ancestor_id, was_root_group) + return if was_root_group + return if old_root_ancestor_id == @group.root_ancestor.id + + CustomerRelations::IssueContact.delete_for_group(@group) + end end end |