Prevent removal of last ADMIN role to avoid lockout #87
Reference in New Issue
Block a user
Delete Branch "%!s()"
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?
Problem
If the last remaining user with the
ADMINrole removes the role from themselves (or is deleted), all admin access is permanently lost. There is no way to recover without direct database intervention.Expected Behavior
The system must enforce that at least one user always holds the
ADMINrole. The following operations should be blocked when they would result in zero admin users:ADMINrole from a userADMIN(if it's their only source of the role)The API should return a clear error (e.g.
409 Conflict) explaining why the operation was rejected.Acceptance Criteria
ADMINuser remainsImplemented in
827ba3c. Guards added in three locations:RbacServiceImpl.removeRoleFromUser— blocks removing ADMIN role when only 1 effective admin remainsUserAdminController.deleteUser— blocks deleting a user who is the sole adminGroupAdminController.removeRoleFromGroup— blocks removing ADMIN from a group when only 1 effective admin remainsAll return 409 Conflict with descriptive error message.