From 5fbb6ddf23da52cf68ed4f87137debfb6f30f6e8 Mon Sep 17 00:00:00 2001 From: Valery Sizov Date: Mon, 13 Aug 2018 14:54:31 +0300 Subject: Fix: Project deletion may not log audit events during group deletion --- app/services/groups/destroy_service.rb | 7 ++++--- ...eletion-may-not-log-audit-events-during-group-deletion.yml | 5 +++++ spec/services/groups/destroy_service_spec.rb | 11 +++++++++++ 3 files changed, 20 insertions(+), 3 deletions(-) create mode 100644 changelogs/unreleased/49796-project-deletion-may-not-log-audit-events-during-group-deletion.yml diff --git a/app/services/groups/destroy_service.rb b/app/services/groups/destroy_service.rb index c4554ce45fb..12aeba4af71 100644 --- a/app/services/groups/destroy_service.rb +++ b/app/services/groups/destroy_service.rb @@ -2,6 +2,8 @@ module Groups class DestroyService < Groups::BaseService + DestroyError = Class.new(StandardError) + 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}") @@ -12,9 +14,8 @@ module Groups group.projects.each do |project| # Execute the destruction of the models immediately to ensure atomic cleanup. - # Skip repository removal because we remove directory with namespace - # that contain all these repositories - ::Projects::DestroyService.new(project, current_user, skip_repo: project.legacy_storage?).execute + success = ::Projects::DestroyService.new(project, current_user).execute + raise DestroyError, "Project #{project.id} can't be deleted" unless success end group.children.each do |group| diff --git a/changelogs/unreleased/49796-project-deletion-may-not-log-audit-events-during-group-deletion.yml b/changelogs/unreleased/49796-project-deletion-may-not-log-audit-events-during-group-deletion.yml new file mode 100644 index 00000000000..bb7633abdb1 --- /dev/null +++ b/changelogs/unreleased/49796-project-deletion-may-not-log-audit-events-during-group-deletion.yml @@ -0,0 +1,5 @@ +--- +title: 'Fix: Project deletion may not log audit events during group deletion' +merge_request: 21162 +author: +type: fixed diff --git a/spec/services/groups/destroy_service_spec.rb b/spec/services/groups/destroy_service_spec.rb index b54491cf5f9..d80d0f5a8a8 100644 --- a/spec/services/groups/destroy_service_spec.rb +++ b/spec/services/groups/destroy_service_spec.rb @@ -135,6 +135,17 @@ describe Groups::DestroyService do it_behaves_like 'group destruction', false end + context 'repository removal status is taken into account' do + it 'raises exception' do + expect_next_instance_of(::Projects::DestroyService) do |destroy_service| + expect(destroy_service).to receive(:execute).and_return(false) + end + + expect { destroy_group(group, user, false) } + .to raise_error(Groups::DestroyService::DestroyError, "Project #{project.id} can't be deleted" ) + end + end + describe 'repository removal' do before do destroy_group(group, user, false) -- cgit v1.2.1