Commit 72d3dcf6 authored by Serena Fang's avatar Serena Fang Committed by charlie ablett

Return project delete errors

If group deletion fails, return failure reason.

Changelog: changed
parent b236eb2c
......@@ -11,11 +11,15 @@ module Groups
# rubocop: disable CodeReuse/ActiveRecord
def execute
# TODO - add a policy check here https://gitlab.com/gitlab-org/gitlab/-/issues/353082
raise DestroyError, "You can't delete this group because you're blocked." if current_user.blocked?
group.prepare_for_destroy
group.projects.includes(:project_feature).each do |project|
# Execute the destruction of the models immediately to ensure atomic cleanup.
success = ::Projects::DestroyService.new(project, current_user).execute
raise DestroyError, "Project #{project.id} can't be deleted" unless success
end
......
......@@ -112,6 +112,17 @@ RSpec.describe Groups::DestroyService do
end
end
context 'when group owner is blocked' do
before do
user.block!
end
it 'returns a more descriptive error message' do
expect { destroy_group(group, user, false) }
.to raise_error(Groups::DestroyService::DestroyError, "You can't delete this group because you're blocked.")
end
end
describe 'repository removal' do
before do
destroy_group(group, user, false)
......
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