diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2020-06-18 14:18:50 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2020-06-18 14:18:50 +0300 |
commit | 8c7f4e9d5f36cff46365a7f8c4b9c21578c1e781 (patch) | |
tree | a77e7fe7a93de11213032ed4ab1f33a3db51b738 /app/services/groups | |
parent | 00b35af3db1abfe813a778f643dad221aad51fca (diff) |
Add latest changes from gitlab-org/gitlab@13-1-stable-ee
Diffstat (limited to 'app/services/groups')
-rw-r--r-- | app/services/groups/destroy_service.rb | 2 | ||||
-rw-r--r-- | app/services/groups/group_links/create_service.rb | 2 | ||||
-rw-r--r-- | app/services/groups/group_links/destroy_service.rb | 6 | ||||
-rw-r--r-- | app/services/groups/import_export/export_service.rb | 29 | ||||
-rw-r--r-- | app/services/groups/import_export/import_service.rb | 23 | ||||
-rw-r--r-- | app/services/groups/transfer_service.rb | 10 |
6 files changed, 52 insertions, 20 deletions
diff --git a/app/services/groups/destroy_service.rb b/app/services/groups/destroy_service.rb index 9437eb9eede..1bff70e6c2e 100644 --- a/app/services/groups/destroy_service.rb +++ b/app/services/groups/destroy_service.rb @@ -6,7 +6,7 @@ module Groups def async_execute job_id = GroupDestroyWorker.perform_async(group.id, current_user.id) - Rails.logger.info("User #{current_user.id} scheduled a deletion of group ID #{group.id} with job ID #{job_id}") # rubocop:disable Gitlab/RailsLogger + Gitlab::AppLogger.info("User #{current_user.id} scheduled a deletion of group ID #{group.id} with job ID #{job_id}") end # rubocop: disable CodeReuse/ActiveRecord diff --git a/app/services/groups/group_links/create_service.rb b/app/services/groups/group_links/create_service.rb index 2ce53fcfe4a..589ac7ccde7 100644 --- a/app/services/groups/group_links/create_service.rb +++ b/app/services/groups/group_links/create_service.rb @@ -5,7 +5,7 @@ module Groups class CreateService < BaseService def execute(shared_group) unless group && shared_group && - can?(current_user, :admin_group, shared_group) && + can?(current_user, :admin_group_member, shared_group) && can?(current_user, :read_group, group) return error('Not Found', 404) end diff --git a/app/services/groups/group_links/destroy_service.rb b/app/services/groups/group_links/destroy_service.rb index 6835b6c4637..b0d496ae78c 100644 --- a/app/services/groups/group_links/destroy_service.rb +++ b/app/services/groups/group_links/destroy_service.rb @@ -3,7 +3,11 @@ module Groups module GroupLinks class DestroyService < BaseService - def execute(one_or_more_links) + def execute(one_or_more_links, skip_authorization: false) + unless skip_authorization || group && can?(current_user, :admin_group_member, group) + return error('Not Found', 404) + end + links = Array(one_or_more_links) if GroupGroupLink.delete(links) diff --git a/app/services/groups/import_export/export_service.rb b/app/services/groups/import_export/export_service.rb index 0f2e3bb65f9..abac0ffc5d9 100644 --- a/app/services/groups/import_export/export_service.rb +++ b/app/services/groups/import_export/export_service.rb @@ -4,10 +4,11 @@ module Groups module ImportExport class ExportService def initialize(group:, user:, params: {}) - @group = group + @group = group @current_user = user - @params = params - @shared = @params[:shared] || Gitlab::ImportExport::Shared.new(@group) + @params = params + @shared = @params[:shared] || Gitlab::ImportExport::Shared.new(@group) + @logger = Gitlab::Export::Logger.build end def async_execute @@ -21,7 +22,7 @@ module Groups save! ensure - cleanup + remove_base_tmp_dir end private @@ -80,8 +81,8 @@ module Groups Gitlab::ImportExport::Saver.new(exportable: @group, shared: @shared) end - def cleanup - FileUtils.rm_rf(shared.archive_path) if shared&.archive_path + def remove_base_tmp_dir + FileUtils.rm_rf(shared.base_path) if shared&.base_path end def notify_error! @@ -91,21 +92,21 @@ module Groups end def notify_success - @shared.logger.info( - group_id: @group.id, - group_name: @group.name, - message: 'Group Import/Export: Export succeeded' + @logger.info( + message: 'Group Export succeeded', + group_id: @group.id, + group_name: @group.name ) notification_service.group_was_exported(@group, @current_user) end def notify_error - @shared.logger.error( - group_id: @group.id, + @logger.error( + message: 'Group Export failed', + group_id: @group.id, group_name: @group.name, - error: @shared.errors.join(', '), - message: 'Group Import/Export: Export failed' + errors: @shared.errors.join(', ') ) notification_service.group_was_not_exported(@group, @current_user, @shared.errors) diff --git a/app/services/groups/import_export/import_service.rb b/app/services/groups/import_export/import_service.rb index 6f692c98c38..a5c776f8fc2 100644 --- a/app/services/groups/import_export/import_service.rb +++ b/app/services/groups/import_export/import_service.rb @@ -9,6 +9,20 @@ module Groups @group = group @current_user = user @shared = Gitlab::ImportExport::Shared.new(@group) + @logger = Gitlab::Import::Logger.build + end + + def async_execute + group_import_state = GroupImportState.safe_find_or_create_by!(group: group) + jid = GroupImportWorker.perform_async(current_user.id, group.id) + + if jid.present? + group_import_state.update!(jid: jid) + else + group_import_state.fail_op('Failed to schedule import job') + + false + end end def execute @@ -21,6 +35,7 @@ module Groups end ensure + remove_base_tmp_dir remove_import_file end @@ -77,7 +92,7 @@ module Groups end def notify_success - @shared.logger.info( + @logger.info( group_id: @group.id, group_name: @group.name, message: 'Group Import/Export: Import succeeded' @@ -85,7 +100,7 @@ module Groups end def notify_error - @shared.logger.error( + @logger.error( group_id: @group.id, group_name: @group.name, message: "Group Import/Export: Errors occurred, see '#{Gitlab::ErrorTracking::Logger.file_name}' for details" @@ -97,6 +112,10 @@ module Groups raise Gitlab::ImportExport::Error.new(@shared.errors.to_sentence) end + + def remove_base_tmp_dir + FileUtils.rm_rf(@shared.base_path) + end end end end diff --git a/app/services/groups/transfer_service.rb b/app/services/groups/transfer_service.rb index fe3ab884302..fbbf4ce8baf 100644 --- a/app/services/groups/transfer_service.rb +++ b/app/services/groups/transfer_service.rb @@ -45,6 +45,7 @@ module Groups raise_transfer_error(:invalid_policies) unless valid_policies? 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? end def group_is_already_root? @@ -55,6 +56,11 @@ module Groups @new_parent_group && @new_parent_group.id == @group.parent_id end + def transfer_to_subgroup? + @new_parent_group && \ + @group.self_and_descendants.pluck_primary_key.include?(@new_parent_group.id) + end + def valid_policies? return false unless can?(current_user, :admin_group, @group) @@ -82,6 +88,7 @@ module Groups end @group.parent = @new_parent_group + @group.clear_memoization(:self_and_ancestors_ids) @group.save! end @@ -125,7 +132,8 @@ module Groups group_is_already_root: s_('TransferGroup|Group is already a root group.'), 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.') + 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.') }.freeze end end |