fix(organizations): release permalink when organization is deleted by c41ms0n · Pull Request #3642 · postalserver/postal · GitHub
Skip to content

fix(organizations): release permalink when organization is deleted - #3642

Open
c41ms0n wants to merge 1 commit into
postalserver:mainfrom
c41ms0n:bugfix/organization-deletion-state
Open

c41ms0n wants to merge 1 commit into
postalserver:mainfrom
c41ms0n:bugfix/organization-deletion-state

Conversation

@c41ms0n

@c41ms0n c41ms0n commented Sep 21, 2026

Copy link
Copy Markdown

Summary

Fix organization deletion so the short name and permalink are released immediately instead of remaining reserved until the background purge.

What changed

  • Organization#soft_destroy now replaces the permalink with a unique deleted-<uuid> tombstone before saving.
  • Permalink uniqueness and Organization.find_unique_permalink now only consider present organizations (deleted_at: nil).
  • Deleted organizations therefore no longer block or affect permalink generation, including deleted records created before this change.
  • The delete page now explains that the organization and short name are removed immediately, while mail servers and data are purged in the background.
  • The purge task logs the organization name rather than its tombstoned permalink.

Result

Deleting an organization immediately frees its short name for reuse. Re-creating it no longer fails because of an invisible deleted organization or receives an unnecessary permalink suffix.

Records are still retained until the background purge, so deletion remains non-blocking.

…eted

Deleting an organization only soft deletes it: the row (and its permalink) is
kept until the hourly deletion task purges it. The web UI, however, hides it
immediately -- it disappears from the organization list, the header switcher
and every lookup (all scoped to `present`). That left an invisible squatter:
re-creating an organization with the same short name failed with "Short name
has already been taken" even though no conflicting organization was visible
anywhere, while the same name silently produced a suffixed permalink (acme-2).

Separate the two concerns so what the UI shows matches what the system
enforces:

  * Organization#soft_destroy releases the permalink (moves it to a unique
    `deleted-<uuid>` tombstone) before saving, so the short name is free again
    the moment deletion completes and can be reused immediately.
  * Permalink uniqueness and Organization.find_unique_permalink are scoped to
    present (deleted_at: nil), so deleted organizations can never block or
    perturb permalink generation again.
  * The delete page explains the behaviour: the organization and its short name
    go immediately; mail servers and data are purged in the background.
  * The purge task logs the organization name, since the permalink is a
    tombstone by the time that task runs.

Records are still retained until the background purge, so deleting stays
non-blocking, and stale deleted rows predating this change are ignored too.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants