Introducing a new way to review your PRs.

Read the announcement

ever-co / ever-gauzy

Ever® Gauzy™ - Open Business Management Platform (ERP/CRM/HRM/ATS/PM) - https://gauzy.co

View on GitHub

27 documents · Updated Nov 23, 2026

docs / account-deletion

Account deletion

Account deletion gives a person a safe way to remove their Gauzy accounts and, when appropriate, the workspaces and files linked to those accounts. It supports an email link for signed-out users and a protected Danger Zone flow for a signed-in user. Both flows show the planned result first and record a small audit result after deletion.

Deletion entry points

The system has two entry points that share the same deletion rules. The email flow covers every account that uses the requested address, while the signed-in flow covers the current account in the current workspace.

Entry pointProof of ownershipScopeMain user result
Email requestA single-use link sent to the addressAll matching accounts across workspacesA preview page followed by explicit confirmation
Signed-in Danger ZoneThe current authenticated session and delete permissionThe current account and workspaceA preview dialog followed by explicit confirmation

The public API accepts the email request without revealing whether the address has an account. The protected /me API requires the account-delete permission. Both paths use a plan fingerprint so a change in workspace membership cannot silently alter what the user approved.

References: packages/…/account-deletion.controller.ts• L16-23 packages/…/account-deletion.controller.ts• L84-110 packages/…/account-deletion.model.ts• L43-74 apps/…/danger-zone.component.ts• L39-105

Account deletion plan

The deletion plan describes each matching account, its workspace, its organizations, the number of other members, and the result that confirmation will produce. An administrator who is the only member can remove the whole workspace. A shared workspace stays in place and only the person’s account is removed. A non-administrator cannot remove a workspace even when they are its last member. A last administrator warning appears when other members remain. Soft-deleted members count as members for this decision.

The preview produces a planHash, which is a short fingerprint of the accounts and outcomes shown to the user. Confirmation must send that value back. If membership, account identity, role, or the planned outcome changes, the service returns a conflict and deletes nothing for that step. Each account is checked again while locked, so a change after the first account is removed can produce a partial result that the user can review and confirm again.

References: packages/…/account-deletion.service.ts• L270-307 packages/…/account-deletion.service.ts• L786-845 packages/…/account-deletion.service.ts• L923-935 packages/…/account-deletion.service.spec.ts• L108-119 packages/…/account-deletion.service.spec.ts• L341-401 packages/…/account-deletion.model.ts• L51-74

Email request lifecycle

The email lifecycle starts with an address and ends with a confirmation email or an unchanged account. The request endpoint returns 202 Accepted before the account lookup completes, so its response and timing do not confirm that an address exists. The service normalizes the address, matches stored spellings safely across supported database behavior, limits repeated requests, replaces older live links, and sends a link only when matching accounts exist. It also serializes requests for the same address so concurrent API instances cannot create several live links or bypass the request limit.

The main lifecycle is:

flowchart LR
    A[Email address] --> B[Request accepted]
    B --> C{Matching accounts?}
    C -- No --> D[No link sent]
    C -- Yes --> E[Create request and replace live link]
    E --> F[Send confirmation link]
    F --> G[Preview plan]
    G --> H{Plan still matches?}
    H -- No --> I[Conflict; review again]
    H -- Yes --> J[Confirm deletion]
    J --> K[Send completion email]

The request has a short lifetime. Links last 30 minutes by default and are bounded to 5–60 minutes. A single address can receive at most three requests in one hour. A newer request revokes an older live link for the same address, and stale clear addresses are removed while new requests are processed. A caller-supplied confirmation URL is used only when its origin is explicitly allowed by the deployment. The request record remains as an audit row after completion, but the clear address is removed. Address matching also handles stored case, spacing, and supported non-ASCII spellings without widening a search to unrelated addresses.

References: packages/…/account-deletion.controller.ts• L29-51 packages/…/account-deletion.service.ts• L158-207 packages/…/account-deletion.service.ts• L215-267 packages/…/account-deletion.service.ts• L701-759 packages/…/account-deletion.service.ts• L855-905 packages/…/account-deletion.service.spec.ts• L121-311

Confirmation token

The confirmation token is a random, single-use value that proves control of the email inbox. The service sends the value only in the link and stores only its SHA-256 hash. Address and client-address audit digests use a deployment secret when one is available. Lookup still covers older digest forms, so secret changes do not break request limits or live-link replacement. The link places the token in the URL fragment, which keeps it out of normal server requests and referrer data. The confirmation page removes it from the address bar as soon as it reads it and keeps it only in memory.

The token supports three safe states:

  • Preview: checks the token and shows the plan without using the link.
  • Confirm: checks the plan, claims the link, and starts deletion only after an explicit action.
  • Invalid: treats missing, expired, replaced, completed, or actively claimed links in the same way.

A claim is a temporary lease. If a process stops during deletion, a later request can take the link after the lease ends while the link is still valid. Only the current claim holder can renew or complete the request. Progress counts survive a retry, so an interrupted multi-account deletion reports cumulative work rather than starting its audit result from zero.

References: packages/…/account-deletion-token.ts• L4-39 packages/…/account-deletion-token.ts• L42-155 packages/…/account-deletion-token.ts• L157-200 packages/…/account-deletion.service.ts• L270-365 packages/…/account-deletion.service.ts• L647-679 packages/…/account-deletion.service.spec.ts• L314-429 packages/…/delete-account-confirm.component.ts• L26-77

File cleanup

File cleanup removes storage objects before or after the related database rows, depending on whether the whole workspace is deleted. The service first finds files owned by the workspace or departing user. It keeps files that belong to another tenant or that another remaining row still uses. It then deletes the files with the storage settings of the owning workspace. When a whole workspace is removed, billing cancellation happens first. For an account leaving a shared workspace, file removal happens after the database transaction releases member locks. A retry can finish failed cleanup without restoring the deleted account.

The cleanup covers the platform’s file-owning records, including time captures, documents, inbox attachments and raw messages, and image assets. It ignores absolute URLs because they are not storage objects. It deletes only keys under the owning tenant’s path and rejects empty, dot, and traversal segments. Missing plugin tables are skipped. Shared image files stay when another row still uses them. Seeded avatars now use the same persisted image-asset path as uploaded avatars, so deletion checks their shared storage key before removal. Storage failures do not stop the account row deletion; a file counts as removed only after the storage provider confirms removal. The result records how many files were removed and how many could not be removed. This makes the database deletion complete while keeping cleanup failures visible for follow-up.

References: packages/…/account-deletion-files.ts• L7-28 packages/…/account-deletion-files.ts• L30-118 packages/…/account-deletion-files.ts• L127-186 packages/…/account-deletion-files.ts• L188-239 packages/…/account-deletion-files.ts• L298-371 packages/…/account-deletion-files.ts• L373-422 packages/…/account-deletion-files.ts• L425-480 packages/…/account-deletion.service.ts• L459-585 packages/…/account-deletion.service.spec.ts• L31-225 packages/…/user.seed.ts• L341-364 packages/…/user-avatar.seed.ts• L19-78

Deletion persistence

The deletion request is stored in account_deletion_request. It is not tenant-scoped because one email address can own accounts in several workspaces. The row stores the token hash, a keyed address hash when deployment secrets are available, expiry, claim state, branding, and count-only result. It is excluded from tenant export because it is platform audit data and must not recreate a deletion request elsewhere.

The migration adds the request table and the two email template records without changing existing business rows. It supports the repository’s database modes and adds indexes for address and token lookup. The entity is available through both ORM paths, while the deletion process uses the TypeORM data source for its transactional work. A completion row keeps cumulative counts for accounts, removed workspaces, removed files, failed files, and cancelled subscriptions. A session deletion writes an audit row without creating a usable email link.

References: packages/…/account-deletion-request.entity.ts• L10-23 packages/…/account-deletion-request.entity.ts• L24-108 packages/…/1791000003450-CreateAccountDeletionRequestTable.ts• L36-47 packages/…/1791000003450-CreateAccountDeletionRequestTable.ts• L58-82 packages/…/account-deletion.service.ts• L323-365 packages/…/account-deletion.service.ts• L396-436 packages/…/account-deletion.module.ts• L15-27

Email templates

The email system sends two account-deletion messages through the deployment’s default mail transport. The request template carries the confirmation link and its expiry time. The completion template reports the number of deleted accounts and fully removed workspaces. The completion message differs between the email flow, which can remove all matching accounts, and the signed-in flow, which removes one current account.

These messages do not use tenant mail settings because the request can span workspaces or complete after the workspace is gone. Link tracking is disabled, and the messages are not written to email history because that history could retain a live deletion token. Branding and allowed links are checked before they are used.

References: packages/…/email.service.ts• L1390-1423 packages/…/email.service.ts• L1425-1465 packages/…/email.service.ts• L1467-1489 packages/…/1791000003450-CreateAccountDeletionRequestTable.ts• L36-43

Authentication screens

The signed-out screens provide the user-facing part of the email lifecycle. The request screen accepts an email and always shows the same inbox message after submission. The confirmation screen previews the masked address and planned account outcomes. It requires the user to acknowledge the impact and type DELETE before it sends the confirmation request.

The confirmation screen treats errors by whether the link or the service may recover:

Screen stateMeaningUser action
InvalidThe link is missing, expired, replaced, completed, or unusableRequest a new link
UnavailableThe preview could not be checked because of a temporary failureTry the preview again
ReadyThe plan is shown and confirmation is allowedReview and confirm
FailedDeletion stopped and released the linkTry confirmation again
DoneDeletion completedSign out of the deleted session

The token is removed from the browser address bar and the page applies a no-referrer policy while it is open. The signed-in Danger Zone uses the same preview and plan check, then signs the browser out after success.

References: packages/…/delete-account.component.ts• L9-71 packages/…/delete-account.component.html• L7-64 packages/…/delete-account-confirm.component.ts• L19-35 packages/…/delete-account-confirm.component.ts• L92-155 packages/…/delete-account-confirm.component.html• L10-115 packages/…/referrer-policy.ts• L1-24 apps/…/danger-zone.component.ts• L39-105

Change checklist

When these files or sections are changed, remember to consider these:

  • Keep the contract fields for planHash, deletion outcomes, and result counts aligned across the API, shared contracts, and both user interfaces.
  • Keep token placement, URL redaction, referrer policy, allowed callback origins, and email link tracking aligned when changing the confirmation URL or email delivery.
  • Keep digest lookup compatible with both keyed and legacy request rows when changing deployment secrets or audit fields.
  • Preserve normalized address matching and the per-address lock when changing request limits or live-link replacement.
  • Preserve cumulative counts, claim renewal, and partial-conflict behavior when changing multi-account deletion.
  • Update the persistence migration when request audit fields or email template names change.
  • Update file ownership rules when a feature adds a storage key or a table that can be removed by account, workspace, or reset flows. Include image assets that may share one storage key across users or workspaces.
  • Keep billing cancellation before whole-workspace removal and preserve the difference between whole-workspace deletion and account-only deletion when changing member, soft-deleted member, or administrator rules.

Important failure modes

TriggerConsequenceGuard
Workspace membership, role, or account identity changes after previewThe requested deletion is rejected or must be reviewed againCompare planHash and re-check the outcome under a row lock
Process stops during multi-account deletionSome accounts may be removed while the request remains incompleteUse a renewable claim lease and cumulative audit counts
Another account changes after an earlier account was removedConfirmation returns a partial result and leaves the remaining accounts for reviewRelease the claim and report the partial-conflict state
Billing cancellation fails before workspace removalThe workspace remains and its subscription is not left charging after deletionCancel billing before deleting the workspace
A storage key is forged or normalizes outside the owning tenantA file in another tenant could be removedRequire a valid tenant path with no empty, dot, or traversal segments
A file is shared by a remaining rowShared content could be lostCheck for outside references before deleting the file, including shared image assets
A storage provider reports no client or cannot remove a fileThe database deletion succeeds while the object remains in storageUse the strict delete operation and record failed file counts
Email address or token is exposed in stored recordsA deletion link or address could remain in platform dataStore keyed digests where possible, clear the address, and skip email history

Key files

FileWhy to read it
packages/…/account-deletion.controller.tsAPI entry points and public versus signed-in boundaries
packages/…/account-deletion.service.tsEnd-to-end deletion plan, claim, transaction, billing, cleanup, and audit flow
packages/…/account-deletion.service.spec.tsGuarantees for matching, plan stability, token claims, retry behavior, and whole-workspace rules
packages/…/account-deletion.model.tsShared request, preview, outcome, and result contracts
packages/…/account-deletion-token.tsToken lifetime, digest rules, link shape, and address masking rules
packages/…/account-deletion-files.tsStorage ownership, reset scope, shared-file checks, and cleanup rules
packages/…/account-deletion-request.entity.tsPersistent audit record and export boundary
packages/…/1791000003450-CreateAccountDeletionRequestTable.tsDatabase table and email template migration
packages/…/email.service.tsRequest and completion email contract
packages/…/user.seed.tsSeeded-user avatar association and fallback behavior
packages/…/user-avatar.seed.tsShared image-asset path used to make seeded avatars resolvable and cleanable
packages/…/delete-account.component.tsSigned-out request screen behavior
packages/…/delete-account-confirm.component.tsToken, preview, confirmation, and recovery screen behavior
apps/…/danger-zone.component.tsSigned-in account deletion entry point