fix(webapp): the last administrator can't be demoted or deleted (#835) #837
Loading…
Reference in a new issue
No description provided.
Delete branch "fix/last-admin-guard"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Closes #835.
The bug:
PATCH /admin/users/{id}/adminhad no checks. So the last administrator, whether yourself or someone else, could be demoted, leaving a server nobody can administer. Deleting the last admin's account went unchecked too.The fix:
user_service.count_admins, which leaves system users out; deleted users are hard-deleted.DELETE /meorDELETE /admin/users/{id}, returns 409. Both paths go throughaccount_deletion_service.delete_user_account, which now raisesLastAdminErrorbefore the ownership gate.Tests:
tests/test_last_admin_guard.pyhas 6 tests. The 3 refusal tests failed before the fix. With the admin, users and account-deletion modules, 107 pass. ruff is clean.🤖 Generated with Claude Code
PATCH /admin/users/{id}/admin had no checks: revoking admin from the sole remaining administrator left a server nobody could administer. Both this endpoint and the account-deletion service (self-service and admin-initiated) now count administrators (excluding the system/ tombstone user) and refuse with 409 when the change would leave zero, whether the target is the caller or someone else. Tests in webapp/backend/tests/test_last_admin_guard.py written first and confirmed failing against the pre-fix code. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>