Add Organizations::MarkForDeletionService for soft-deletion

What does this MR do and why?

Introduces Organizations::MarkForDeletionService to handle organization soft-deletion by transitioning the organization to the deletion_scheduled state.

The service:

  • Checks authorization (delete_organization ability)
  • Rejects the default organization
  • Rejects non-empty organizations (those with groups or projects)
  • Calls schedule_deletion! to transition the state
  • Returns ServiceResponse.success with the organization on success
  • Logs the event

The EE extension (EE::Organizations::MarkForDeletionService) overrides log_event to additionally emit an audit event (organization_deletion_scheduled).

References

Implements Add Organizations::MarkForDeletionService for s... (#594308 - closed)

Screenshots or screen recordings

N/A — backend service, no UI changes.

Before After
N/A N/A

How to set up and validate locally

  1. In a Rails console, create a non-default, empty organization and an owner user:
    org = Organizations::Organization.create!(name: 'Test Org', path: 'test-org', visibility_level: 20)
    user = User.first
    org.organization_users.create!(user: user, access_level: :owner)
  2. Run the service:
    result = Organizations::MarkForDeletionService.new(org, current_user: user).execute
    result.success? # => true
    org.reload.deletion_scheduled? # => true

MR acceptance checklist

Evaluate this MR against the MR acceptance checklist. It helps you analyze changes to reduce risks in quality, performance, reliability, security, and maintainability.

Edited by Rémy Coutable

Merge request reports

Loading