feat(server): handle account deleting properly (#12399)

<!-- This is an auto-generated comment: release notes by coderabbit.ai -->
## Summary by CodeRabbit

- **New Features**
  - Users are now prevented from deleting their account if they own one or more team workspaces. A clear error message instructs users to transfer ownership or delete those workspaces first.
  - Disabled (banned) users are explicitly prevented from signing in or re-registering.
  - Added new error messages and translations to improve clarity around account deletion restrictions.

- **Bug Fixes**
  - Disabled users are now explicitly handled to prevent sign-in attempts.

- **Tests**
  - Introduced comprehensive end-to-end tests covering account deletion, banning, and re-registration scenarios.

- **Chores**
  - Improved event handling for user deletion and subscription cancellation.
  - Updated localization resources with new error messages.
  - Renamed payment event handler class for clarity.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->
This commit is contained in:
forehalo
2025-05-23 03:57:29 +00:00
parent f99b143bf9
commit f38b8fef4d
15 changed files with 235 additions and 23 deletions
@@ -792,10 +792,17 @@ export const USER_FRIENDLY_ERRORS = {
type: 'action_forbidden',
message: 'Cannot delete all admin accounts.',
},
// Account errors
cannot_delete_own_account: {
type: 'action_forbidden',
message: 'Cannot delete own account.',
},
cannot_delete_account_with_owned_team_workspace: {
type: 'action_forbidden',
message:
'Cannot delete account. You are the owner of one or more team workspaces. Please transfer ownership or delete them first.',
},
// captcha errors
captcha_verification_failed: {
@@ -908,6 +908,12 @@ export class CannotDeleteOwnAccount extends UserFriendlyError {
}
}
export class CannotDeleteAccountWithOwnedTeamWorkspace extends UserFriendlyError {
constructor(message?: string) {
super('action_forbidden', 'cannot_delete_account_with_owned_team_workspace', message);
}
}
export class CaptchaVerificationFailed extends UserFriendlyError {
constructor(message?: string) {
super('bad_request', 'captcha_verification_failed', message);
@@ -1145,6 +1151,7 @@ export enum ErrorNames {
MAILER_SERVICE_IS_NOT_CONFIGURED,
CANNOT_DELETE_ALL_ADMIN_ACCOUNT,
CANNOT_DELETE_OWN_ACCOUNT,
CANNOT_DELETE_ACCOUNT_WITH_OWNED_TEAM_WORKSPACE,
CAPTCHA_VERIFICATION_FAILED,
INVALID_LICENSE_SESSION_ID,
LICENSE_REVEALED,