1
0
Fork 0
mirror of https://github.com/retspen/webvirtcloud synced 2026-12-03 17:36:05 +00:00

fix(admin): two administrators at once leave a superuser and one user per address

An administrator cannot block, delete or demote their own account, but
with two superusers each could block the other at the same moment, and
none was left. Changes of the panel's users (create, edit, block,
unblock, delete, group edits, and a user's own profile) now run one at
a time, under a claim every worker sees, and a block, delete or edit
that would leave no active superuser is refused.

Under that claim each change reads the user or group as saved now: the
edit forms' fingerprint is compared there, a block writes only the
account's Active flag, and a profile saved while an administrator
blocks the account keeps the block.

A user's e-mail address is one user's, case aside, so that "Lost OTP?"
can mail it; two users created or edited at once each passed that check.
The form checks the address again under the same claim, with the save.
This commit is contained in:
catborise 2026-11-13 14:33:06 +03:00
parent ab77b198f2
commit b65d2abaf6
9 changed files with 330 additions and 147 deletions

View file

@ -40,6 +40,15 @@ def hosts_lock(compute=None):
yield
@contextmanager
def users_lock():
"""The panel's users for the block, in one transaction, while no other
change of them runs: what a form checked before (one user per e-mail
address, an active superuser left) is checked again as it is saved."""
with claims.hold({claims.users_key(): Claim.EXCLUSIVE}), transaction.atomic():
yield
@contextmanager
def user_quota_lock(user):
"""One user's quota check and the change it allows run one at a time."""