Files
wekan/client/lib/accountOperationError.js
T
Lauri Ojansivu 57a24eb8ba Own account deletion and username change follow their settings on the server, and the last admin stays.
Admin Panel / People / Login / Self delete user account unticked only hid the
Delete and Anonymize buttons: removeUser and anonymizeUser on your own account
still worked, and so did DELETE /api/users/:userId for an administrator's own
id. And removeUser's self branch returned before the last-administrator
check, so the only site administrator could delete themselves.

Now every self-removal path asks models/lib/selfAccountRemoval.js: refused
while the setting is off (recorded in Admin Panel / Problems as Disabled
setting, never disabling the account), and refused for the last site
administrator (not recorded: the button is there, so it is ordinary use).

Username Change unticked: the setUsername method already refused, but the
Users allow rule still let a client write its own username directly; a
Users.deny rule now refuses that and records it.

Thanks to xet7 !
2026-11-22 18:39:49 +02:00

10 lines
565 B
JavaScript

// Keep server diagnostics in the console; show existing localized UI messages.
// The last-admin case must precede the general authorization failure.
export function accountOperationErrorKey(error) {
if (error?.error === 'not-authorized' && (error.reason === 'Cannot delete the last administrator'
|| error.reason === 'Cannot anonymize the last administrator')) return 'last-admin-desc';
if (error?.error === 'not-authorized') return 'error-notAllowed';
if (error?.error === 'user-not-found') return 'error-user-doesNotExist';
return 'server-error';
}