diff --git a/accounts/views.py b/accounts/views.py index 0ffcdb34..c04ffe65 100644 --- a/accounts/views.py +++ b/accounts/views.py @@ -24,8 +24,10 @@ from django.views.decorators.debug import sensitive_post_parameters from django_otp.plugins.otp_totp.models import TOTPDevice from accounts.apps import admin_password_path -from computes.utils import lock_ownership +from computes.utils import lock_ownership, users_lock from logs.audit import audit, audit_vm, changed_fields, failed, snapshot +from operations import claims +from operations.utils import busy_message from accounts.forms import ApiTokenForm, EmailOTPForm, ProfileForm, UserSSHKeyForm from accounts.models import ApiToken, User, UserAttributes, UserInstance, UserSSHKey @@ -36,16 +38,26 @@ from .utils import OTP_LINK, OTP_LINK_MAX_AGE, get_existing_totp_device, get_use def profile(request): publickeys = UserSSHKey.objects.filter(user_id=request.user.id) - before = snapshot(request.user) profile_form = ProfileForm(request.POST or None, instance=request.user) ssh_key_form = UserSSHKeyForm() if profile_form.is_valid(): - with audit(request, None, f"User {request.user.username}", "change") as entry: - profile_form.save() - fields = changed_fields(before, snapshot(request.user)) - entry.action = "change " + ", ".join(fields) - entry.skip = not fields + try: + with audit(request, None, f"User {request.user.username}", "change") as entry, users_lock(): + # the account as saved now (an administrator may have blocked it meanwhile), + # its e-mail address checked again, with the save + account = get_user_model().objects.get(pk=request.user.pk) + before = snapshot(account) + profile_form = ProfileForm(request.POST, instance=account) + entry.skip = not profile_form.is_valid() + if profile_form.is_valid(): + fields = changed_fields(before, snapshot(profile_form.save())) + entry.action = "change " + ", ".join(fields) + entry.skip = not fields + except claims.Busy as busy: + messages.error(request, busy_message(busy, request.user)) + return redirect("accounts:profile") + if profile_form.is_valid(): messages.success(request, _("Profile updated")) return redirect("accounts:profile") diff --git a/admin/tests/test_user_pages.py b/admin/tests/test_user_pages.py index f08fd064..f59609ea 100644 --- a/admin/tests/test_user_pages.py +++ b/admin/tests/test_user_pages.py @@ -2,7 +2,11 @@ user form says what its fields mean, and a password set by an administrator can be one the user must change.""" +from contextlib import contextmanager +from unittest.mock import patch + from accounts.models import ApiToken, UserAttributes +from computes.utils import users_lock from django.contrib.auth import get_user_model from django.contrib.messages import get_messages from django.test import TestCase @@ -179,3 +183,75 @@ class UserPagesTests(TestCase): self.admin.refresh_from_db() self.assertTrue(self.admin.has_usable_password()) + + +class SavedAsCheckedTests(TestCase): + """What a form checked before is checked again as it is saved, while no + other change of the users runs (users_lock): here another change ends + just before this one takes the lock.""" + + def setUp(self): + User = get_user_model() + self.admin = User.objects.create_superuser("sc-admin", "sc@example.com", "pw") + self.other = User.objects.create_superuser("sc-other", "sc-other@example.com", "pw") + # these two are the superusers: not the default admin the migrations make + User.objects.exclude(pk__in=[self.admin.pk, self.other.pk]).update(is_active=False) + self.client.force_login(self.admin) + + def meanwhile(self, change, lock_of="admin.views"): + @contextmanager + def lock(): + change() + with users_lock(): + yield + + return patch(f"{lock_of}.users_lock", lock) + + def test_two_administrators_blocking_each_other_leave_one(self): + # the other blocked this administrator meanwhile: blocking the other would leave none + with self.meanwhile(lambda: get_user_model().objects.filter(pk=self.admin.pk).update(is_active=False)): + response = self.client.post(reverse("admin:user_block", args=[self.other.pk])) + self.assertEqual([str(m) for m in get_messages(response.wsgi_request)], ["This would leave no active superuser"]) + self.other.refresh_from_db() + self.assertTrue(self.other.is_active) + + def test_an_email_address_taken_meanwhile_is_refused(self): + def take(): + get_user_model().objects.create_user("sc-first", email="Bob@example.com") + + with self.meanwhile(take): + response = self.client.post(reverse("admin:user_create"), { + "username": "sc-bob", "email": "bob@example.com", "password": "Wvc-bob-pass-9", "role": "user", + "max_instances": 1, "max_cpus": 1, "max_memory": 1, "max_disk_size": 1}) + self.assertEqual(response.status_code, 200) + self.assertFalse(get_user_model().objects.filter(username="sc-bob").exists()) + + def test_a_form_checked_before_another_change_ends_is_refused_as_saved(self): + # the other change ends after this form's page was read, before its save takes the lock + alice = get_user_model().objects.create_user("sc-alice") + url = reverse("admin:user_update", args=[alice.pk]) + data = {"username": "sc-alice", "is_active": "on", "role": "user", "max_instances": 1, "max_cpus": 1, + "max_memory": 1, "max_disk_size": 1, "seen": user_seen(alice)} + with self.meanwhile(lambda: get_user_model().objects.filter(pk=alice.pk).update(is_active=False)): + response = self.client.post(url, data) + self.assertRedirects(response, url, fetch_redirect_response=False) + alice.refresh_from_db() + self.assertFalse(alice.is_active) + + def test_a_busy_create_is_said_on_the_form(self): + from operations import claims + + with patch("admin.views.users_lock", side_effect=claims.Busy("users")): + response = self.client.post(reverse("admin:user_create"), { + "username": "sc-carl", "password": "Wvc-carl-pass-9", "role": "user", + "max_instances": 1, "max_cpus": 1, "max_memory": 1, "max_disk_size": 1}) + self.assertContains(response, "short operation") + self.assertFalse(get_user_model().objects.filter(username="sc-carl").exists()) + + def test_a_profile_saved_while_an_administrator_blocks_the_account_keeps_the_block(self): + bob = get_user_model().objects.create_user("sc-bob2", password="pw") + self.client.force_login(bob) + with self.meanwhile(lambda: get_user_model().objects.filter(pk=bob.pk).update(is_active=False), "accounts.views"): + self.client.post(reverse("accounts:profile"), {"first_name": "Bob", "last_name": "", "email": ""}) + bob.refresh_from_db() + self.assertEqual((bob.first_name, bob.is_active), ("Bob", False)) diff --git a/admin/views.py b/admin/views.py index 405a5da7..5fd8c619 100644 --- a/admin/views.py +++ b/admin/views.py @@ -1,8 +1,9 @@ +from contextlib import contextmanager from datetime import timedelta from accounts.models import ApiToken, Instance, UserAttributes, UserInstance from appsettings.settings import app_settings -from computes.utils import lock_ownership +from computes.utils import lock_ownership, users_lock from django.conf import settings from django.contrib import messages from django.contrib.auth import update_session_auth_hash @@ -21,6 +22,8 @@ from instances.models import InstanceTombstone from instances.report import workbook from logs.audit import audit, changed_fields, snapshot from logs.models import Logs +from operations import claims +from operations.utils import busy_message from vrtManager import util from . import forms @@ -77,19 +80,32 @@ def group_create(request): @superuser_only def group_update(request, pk): group = get_object_or_404(Group, pk=pk) - subject, before = f"Group {group.name}", group_snapshot(group) - seen = form_seen(before) - if request.method == "POST" and request.POST.get("seen") != seen: - messages.error(request, STALE % {"name": group.name}) - return redirect(request.get_full_path()) - form = forms.GroupForm(request.POST or None, instance=group) - if form.is_valid(): - with audit(request, None, subject, "change") as entry: - form.save() - fields = changed_fields(before, group_snapshot(group)) - entry.action = "change " + ", ".join(fields) - entry.skip = not fields - return redirect("admin:group_list") + subject = f"Group {group.name}" + if request.method == "POST": + try: + # as user_update: read, checked and saved while no other change of the users runs + with audit(request, None, subject, "change") as entry, users_lock(): + group = Group.objects.get(pk=pk) + before = group_snapshot(group) + if request.POST.get("seen") != form_seen(before): + raise Stale("changed since the form was shown") + form = forms.GroupForm(request.POST, instance=group) + entry.skip = not form.is_valid() + if form.is_valid(): + form.save() + fields = changed_fields(before, group_snapshot(group)) + entry.action = "change " + ", ".join(fields) + entry.skip = not fields + except Stale: + messages.error(request, STALE % {"name": group.name}) + return redirect(request.get_full_path()) + except claims.Busy as busy: + messages.error(request, busy_message(busy, request.user)) + return redirect(request.get_full_path()) + if form.is_valid(): + return redirect("admin:group_list") + else: + form = forms.GroupForm(instance=group) return render( request, @@ -97,7 +113,7 @@ def group_update(request, pk): { "form": form, "group": group, - "seen": seen, + "seen": form_seen(group_snapshot(group)), "title": _("Update Group"), }, ) @@ -121,6 +137,27 @@ def group_delete(request, pk): # an administrator who blocks, deletes or demotes their own account is out of # these pages at once, and may have been the last one OWN_ACCOUNT = _("You cannot block, delete or demote your own account") +NO_SUPERUSER = _("This would leave no active superuser") + + +class NoSuperuser(Exception): + pass + + +@contextmanager +def users_change(): + """A change of the panel's users, saved only if an active superuser is + left: two administrators blocking or demoting each other at once would + each leave the other, and then none. One change at a time (users_lock).""" + with users_lock(): + yield + if not User.objects.filter(is_superuser=True, is_active=True).exists(): + raise NoSuperuser("no active superuser would be left") + + +def refused(request, err): + """The message of a users_change() that was not made.""" + messages.error(request, NO_SUPERUSER if isinstance(err, NoSuperuser) else busy_message(err, request.user)) @superuser_only @@ -150,18 +187,21 @@ def user_create(request): user_form = forms.UserCreateForm(request.POST or None) attributes_form = forms.UserAttributesForm(request.POST or None) if user_form.is_valid() and attributes_form.is_valid(): - with audit(request, None, f"User {user_form.cleaned_data['username']}", "add") as entry, transaction.atomic(): - # the form's one-owner check of the default VMs again, with the inserts in one step - lock_ownership() - user_form.full_clean() - entry.skip = not user_form.is_valid() - if user_form.is_valid(): - user = user_form.save() - attributes = attributes_form.save(commit=False) - attributes.user = user - attributes.save() - UserInstance.objects.bulk_create(UserInstance(user=user, instance=instance) - for instance in user_form.default_instances) + # the form's checks again (its e-mail address one user's, the default VMs' one owner), with the inserts + try: + with audit(request, None, f"User {user_form.cleaned_data['username']}", "add") as entry, users_lock(): + lock_ownership() + user_form.full_clean() + entry.skip = not user_form.is_valid() + if user_form.is_valid(): + user = user_form.save() + attributes = attributes_form.save(commit=False) + attributes.user = user + attributes.save() + UserInstance.objects.bulk_create(UserInstance(user=user, instance=instance) + for instance in user_form.default_instances) + except claims.Busy as busy: # the form again, with what was entered + user_form.add_error(None, busy_message(busy, request.user)) if user_form.is_valid(): return redirect("admin:user_list") @@ -176,35 +216,59 @@ def user_create(request): ) +class Stale(Exception): + pass + + +def user_edit_forms(request, pk): + """The user and quota forms of user pk as saved now, bound to the posted + values, and the fingerprint and snapshots of what they hold.""" + user = User.objects.get(pk=pk) + attributes, _created = UserAttributes.objects.get_or_create(user=user) + before = (snapshot(user), snapshot(attributes)) + data = request.POST if request.method == "POST" else None + return (forms.UserForm(data, instance=user), forms.UserAttributesForm(data, instance=attributes), + form_seen(*before), before) + + @sensitive_post_parameters() @superuser_only def user_update(request, pk): user = get_object_or_404(User, pk=pk) - attributes, attributes_created = UserAttributes.objects.get_or_create(user=user) subject = f"User {user.username}" - before, before_attributes = snapshot(user), snapshot(attributes) - seen = form_seen(before, before_attributes) - if request.method == "POST" and request.POST.get("seen") != seen: - messages.error(request, STALE % {"name": user.username}) - return redirect(request.get_full_path()) - user_form = forms.UserForm(request.POST or None, instance=user) - attributes_form = forms.UserAttributesForm( - request.POST or None, instance=attributes - ) - valid = user_form.is_valid() and attributes_form.is_valid() - if valid and user == request.user and not (user_form.cleaned_data["is_active"] and user_form.cleaned_data["is_superuser"]): - user_form.add_error(None, OWN_ACCOUNT) - valid = False + valid = False + if request.method == "POST": + try: + # read, checked and saved while no other change of the users runs: a change + # saved since this form was shown is not undone, and its checks see what is saved + with audit(request, None, subject, "change") as entry, users_change(): + user_form, attributes_form, seen, (before, before_attributes) = user_edit_forms(request, pk) + if request.POST.get("seen") != seen: + raise Stale("changed since the form was shown") + valid = user_form.is_valid() and attributes_form.is_valid() + if valid and user == request.user and not (user_form.cleaned_data["is_active"] + and user_form.cleaned_data["is_superuser"]): + user_form.add_error(None, OWN_ACCOUNT) + valid = False + entry.skip = not valid + if valid: + user = user_form.save() + attributes = attributes_form.save() + if not user.is_active: # as user_block + ApiToken.objects.filter(user=user).delete() + fields = set(changed_fields(before, snapshot(user))) | set(changed_fields(before_attributes, snapshot(attributes))) + fields = sorted(fields - {"password", "last_login"}) + entry.action = "change " + ", ".join(fields) + entry.skip = not fields + except Stale: + messages.error(request, STALE % {"name": user.username}) + return redirect(request.get_full_path()) + except (NoSuperuser, claims.Busy) as err: + refused(request, err) + return redirect(request.get_full_path()) + else: + user_form, attributes_form, seen, _before = user_edit_forms(request, pk) if valid: - with audit(request, None, subject, "change") as entry, transaction.atomic(): - user_form.save() - attributes_form.save() - if not user.is_active: # as user_block - ApiToken.objects.filter(user=user).delete() - fields = set(changed_fields(before, snapshot(user))) | set(changed_fields(before_attributes, snapshot(attributes))) - fields = sorted(fields - {"password", "last_login"}) - entry.action = "change " + ", ".join(fields) - entry.skip = not fields next_url = request.GET.get("next") if next_url and url_has_allowed_host_and_scheme( url=next_url, allowed_hosts={request.get_host()}, require_https=request.is_secure() @@ -260,8 +324,11 @@ def user_delete(request, pk): messages.error(request, OWN_ACCOUNT) return redirect("admin:user_list") if request.method == "POST": - with audit(request, None, f"User {user.username}", "delete"): - user.delete() + try: + with audit(request, None, f"User {user.username}", "delete"), users_change(): + user.delete() + except (NoSuperuser, claims.Busy) as err: + refused(request, err) return redirect("admin:user_list") return render( @@ -279,12 +346,15 @@ def user_block(request, pk): if user == request.user: messages.error(request, OWN_ACCOUNT) return redirect("admin:user_list") - with audit(request, None, f"User {user.username}", "block") as entry, transaction.atomic(): - entry.skip = not user.is_active # already blocked - user.is_active = False - user.save() - # an unblock must not bring back the tokens of someone who took the account over - ApiToken.objects.filter(user=user).delete() + try: + with audit(request, None, f"User {user.username}", "block") as entry, users_change(): + entry.skip = not user.is_active # already blocked + user.is_active = False + user.save(update_fields=["is_active"]) # not the rest as read before the lock + # an unblock must not bring back the tokens of someone who took the account over + ApiToken.objects.filter(user=user).delete() + except (NoSuperuser, claims.Busy) as err: + refused(request, err) return redirect("admin:user_list") @@ -292,10 +362,13 @@ def user_block(request, pk): @superuser_only def user_unblock(request, pk): user: User = get_object_or_404(User, pk=pk) - with audit(request, None, f"User {user.username}", "unblock") as entry: - entry.skip = user.is_active # not blocked - user.is_active = True - user.save() + try: + with audit(request, None, f"User {user.username}", "unblock") as entry, users_lock(): + entry.skip = user.is_active # not blocked + user.is_active = True + user.save(update_fields=["is_active"]) + except claims.Busy as busy: + messages.error(request, busy_message(busy, request.user)) return redirect("admin:user_list") diff --git a/computes/utils.py b/computes/utils.py index 92d872ec..48c3a194 100644 --- a/computes/utils.py +++ b/computes/utils.py @@ -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.""" diff --git a/locale/tr/LC_MESSAGES/django.mo b/locale/tr/LC_MESSAGES/django.mo index eb3120bf..fa43ab17 100644 Binary files a/locale/tr/LC_MESSAGES/django.mo and b/locale/tr/LC_MESSAGES/django.mo differ diff --git a/locale/tr/LC_MESSAGES/django.po b/locale/tr/LC_MESSAGES/django.po index 384b966f..008278cf 100644 --- a/locale/tr/LC_MESSAGES/django.po +++ b/locale/tr/LC_MESSAGES/django.po @@ -11,7 +11,7 @@ msgid "" msgstr "" "Project-Id-Version: PACKAGE VERSION\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2026-11-13 11:29+0000\n" +"POT-Creation-Date: 2026-11-13 11:54+0000\n" "PO-Revision-Date: 2020-11-04 12:00+0000\n" "Last-Translator: catborise , 2020\n" "Language-Team: Turkish (https://www.transifex.com/catborise/teams/110663/tr/)\n" @@ -539,7 +539,7 @@ msgid "Add" msgstr "Ekle" #: accounts/templates/profile.html:64 accounts/templates/profile.html:70 -#: accounts/views.py:72 accounts/views.py:87 +#: accounts/views.py:84 accounts/views.py:99 msgid "Create an API token" msgstr "API anahtarı oluştur" @@ -580,98 +580,98 @@ msgstr "" "\n" "%(url)s" -#: accounts/views.py:49 +#: accounts/views.py:61 msgid "Profile updated" msgstr "Profil güncellendi" -#: accounts/views.py:79 +#: accounts/views.py:91 #, python-format msgid "A user has at most %(limit)s API tokens: delete one first." msgstr "" "Bir kullanıcının en fazla %(limit)s API anahtarı olabilir: önce birini silin." -#: accounts/views.py:81 +#: accounts/views.py:93 #, python-format msgid "You have a token named %(name)s: choose another name." msgstr "%(name)s adlı bir token'ınız var: başka bir ad seçin." -#: accounts/views.py:118 +#: accounts/views.py:130 msgid "API token deleted" msgstr "API anahtarı silindi" -#: accounts/views.py:126 +#: accounts/views.py:138 msgid "Delete API token" msgstr "API anahtarını sil" -#: accounts/views.py:127 +#: accounts/views.py:139 msgid "Scripts and tools that use it can no longer reach the API." msgstr "Onu kullanan betikler ve araçlar artık API'ye erişemez." -#: accounts/views.py:137 +#: accounts/views.py:149 msgid "SSH key added" msgstr "SSH anahtarı eklendi" -#: accounts/views.py:145 +#: accounts/views.py:157 msgid "Add SSH key" msgstr "SSH Anahtarı Ekle" -#: accounts/views.py:166 +#: accounts/views.py:178 msgid "SSH key deleted" msgstr "SSH anahtarı silindi" -#: accounts/views.py:174 +#: accounts/views.py:186 msgid "Delete SSH key" msgstr "SSH anahtarı sil" -#: accounts/views.py:175 +#: accounts/views.py:187 msgid "" "VMs that already have it keep it; VMs created from now on do not get it." msgstr "" "Ona zaten sahip olan sanal makinelerde kalır; bundan sonra oluşturulan sanal " "makinelere eklenmez." -#: accounts/views.py:225 +#: accounts/views.py:237 msgid "Password Changed" msgstr "Parola Değişti" -#: accounts/views.py:256 +#: accounts/views.py:268 msgid "Create User Instance" msgstr "Yeni Kullanıcı Sanal Makinesi Oluştur" -#: accounts/views.py:291 +#: accounts/views.py:303 msgid "Update User Instance" msgstr "Kullanıcı Sanal Makinesini Güncelle" -#: accounts/views.py:309 +#: accounts/views.py:321 msgid "The user loses access to this VM; the VM itself is not changed." msgstr "" "Kullanıcı bu sanal makineye erişimini kaybeder; sanal makinenin kendisi " "değişmez." -#: accounts/views.py:344 +#: accounts/views.py:356 #, python-format msgid "OTP Sent to %(email)s" msgstr "OTP %(email)s ye gönderildi" -#: accounts/views.py:353 +#: accounts/views.py:365 msgid "Email OTP" msgstr "OTP E-Postası" -#: accounts/views.py:387 +#: accounts/views.py:399 #, python-format msgid "The OTP QR code could not be mailed to %(user)s: %(error)s" msgstr "OTP QR kodu %(user)s kullanıcısına e-postayla gönderilemedi: %(error)s" -#: accounts/views.py:391 +#: accounts/views.py:403 #, python-format msgid "OTP QR code was emailed to user %(user)s" msgstr "OTP QR kodu %(user)s kullanıcısına gönderildi" -#: accounts/views.py:395 +#: accounts/views.py:407 msgid "User email not set, failed to send QR code" msgstr "Kullanıcı e-postası girilmemiş, QR kod gönderimi başarısız" -#: accounts/views.py:407 +#: accounts/views.py:419 #, python-format msgid "OTP of %(user)s was reset: a new QR code can be mailed." msgstr "" @@ -961,16 +961,16 @@ msgstr "Sonuç" msgid "IP" msgstr "IP" -#: admin/templates/admin/logs.html:56 admin/views.py:322 instances/states.py:19 +#: admin/templates/admin/logs.html:56 admin/views.py:395 instances/states.py:19 #: instances/views.py:441 logs/views.py:18 msgid "Unknown" msgstr "Bilinmeyen" -#: admin/templates/admin/logs.html:56 admin/views.py:322 logs/views.py:18 +#: admin/templates/admin/logs.html:56 admin/views.py:395 logs/views.py:18 msgid "Done" msgstr "Tamamlandı" -#: admin/templates/admin/logs.html:56 admin/views.py:322 logs/views.py:18 +#: admin/templates/admin/logs.html:56 admin/views.py:395 logs/views.py:18 #: operations/templates/operations/job.html:107 msgid "Failed" msgstr "Başarısız" @@ -1107,7 +1107,7 @@ msgstr "Kullanıcı oluştur" msgid "New user" msgstr "Yeni kullanıcı" -#: admin/templates/admin/user_list.html:19 admin/views.py:142 +#: admin/templates/admin/user_list.html:19 admin/views.py:179 #: instances/templates/instances/settings_tab.html:79 templates/navbar.html:32 msgid "Users" msgstr "Kullanıcılar" @@ -1166,7 +1166,7 @@ msgstr "Burada belirlenen parolayla oturum açar." msgid "Signs in another way, such as LDAP. The current password is removed." msgstr "LDAP gibi başka bir yolla oturum açar. Mevcut parola kaldırılır." -#: admin/views.py:39 +#: admin/views.py:42 #, python-format msgid "" "%(name)s was changed meanwhile: here it is as it is now; make your change " @@ -1174,51 +1174,55 @@ msgid "" msgstr "" "%(name)s bu arada değişti: güncel hâli aşağıda; değişikliğinizi yeniden yapın" -#: admin/views.py:72 +#: admin/views.py:75 msgid "Create Group" msgstr "Grup Oluştur" -#: admin/views.py:101 +#: admin/views.py:117 msgid "Update Group" msgstr "Grubu Güncelle" -#: admin/views.py:117 +#: admin/views.py:133 msgid "Its members stay but lose the permissions it gave them." msgstr "Üyeleri kalır ancak grubun onlara verdiği izinleri kaybeder." -#: admin/views.py:123 +#: admin/views.py:139 msgid "You cannot block, delete or demote your own account" msgstr "Kendi hesabınızı engelleyemez, silemez veya yetkisini düşüremezsiniz" -#: admin/views.py:174 +#: admin/views.py:140 +msgid "This would leave no active superuser" +msgstr "Bu işlem hiç etkin süper kullanıcı bırakmaz" + +#: admin/views.py:214 msgid "Create User" msgstr "Kullanıcı Oluştur" -#: admin/views.py:223 +#: admin/views.py:287 msgid "Update User" msgstr "Kullanıcı Güncelle" -#: admin/views.py:247 +#: admin/views.py:311 #, python-format msgid "Password changed for %(user)s" msgstr "%(user)s parolası değiştirildi" -#: admin/views.py:271 +#: admin/views.py:338 msgid "Their access to VMs, SSH keys and settings go; the VMs themselves stay." msgstr "" "Sanal makinelere erişimi, SSH anahtarları ve ayarları silinir; sanal " "makinelerin kendisi kalır." -#: admin/views.py:371 +#: admin/views.py:444 msgid "deleted user" msgstr "silinmiş kullanıcı" -#: admin/views.py:383 +#: admin/views.py:456 #, python-format msgid "Removed VM %(name)s deleted" msgstr "Kaldırılan sanal makine %(name)s silindi" -#: admin/views.py:390 +#: admin/views.py:463 msgid "Its owners no longer get the VM back if its UUID shows up again." msgstr "" "UUID'si yeniden görünse bile sahipleri sanal makineyi artık geri almaz." diff --git a/locale/zh/LC_MESSAGES/django.mo b/locale/zh/LC_MESSAGES/django.mo index 00dcc009..9204ec26 100644 Binary files a/locale/zh/LC_MESSAGES/django.mo and b/locale/zh/LC_MESSAGES/django.mo differ diff --git a/locale/zh/LC_MESSAGES/django.po b/locale/zh/LC_MESSAGES/django.po index 15a9b3ba..8804ac12 100644 --- a/locale/zh/LC_MESSAGES/django.po +++ b/locale/zh/LC_MESSAGES/django.po @@ -7,7 +7,7 @@ msgid "" msgstr "" "Project-Id-Version: \n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2026-11-13 11:29+0000\n" +"POT-Creation-Date: 2026-11-13 11:54+0000\n" "PO-Revision-Date: \n" "Last-Translator: \n" "Language-Team: \n" @@ -531,7 +531,7 @@ msgid "Add" msgstr "添加" #: accounts/templates/profile.html:64 accounts/templates/profile.html:70 -#: accounts/views.py:72 accounts/views.py:87 +#: accounts/views.py:84 accounts/views.py:99 msgid "Create an API token" msgstr "创建 API 令牌" @@ -570,93 +570,93 @@ msgstr "" "\n" "%(url)s" -#: accounts/views.py:49 +#: accounts/views.py:61 msgid "Profile updated" msgstr "资料已更新" -#: accounts/views.py:79 +#: accounts/views.py:91 #, python-format msgid "A user has at most %(limit)s API tokens: delete one first." msgstr "每个用户最多有 %(limit)s 个 API 令牌:请先删除一个。" -#: accounts/views.py:81 +#: accounts/views.py:93 #, python-format msgid "You have a token named %(name)s: choose another name." msgstr "您已有名为 %(name)s 的令牌:请换一个名称。" -#: accounts/views.py:118 +#: accounts/views.py:130 msgid "API token deleted" msgstr "API 令牌已删除" -#: accounts/views.py:126 +#: accounts/views.py:138 msgid "Delete API token" msgstr "删除 API 令牌" -#: accounts/views.py:127 +#: accounts/views.py:139 msgid "Scripts and tools that use it can no longer reach the API." msgstr "使用它的脚本和工具将无法再访问 API。" -#: accounts/views.py:137 +#: accounts/views.py:149 msgid "SSH key added" msgstr "SSH 密钥已添加" -#: accounts/views.py:145 +#: accounts/views.py:157 msgid "Add SSH key" msgstr "添加 SSH 密钥" -#: accounts/views.py:166 +#: accounts/views.py:178 msgid "SSH key deleted" msgstr "SSH 密钥已删除" -#: accounts/views.py:174 +#: accounts/views.py:186 msgid "Delete SSH key" msgstr "删除 SSH 密钥" -#: accounts/views.py:175 +#: accounts/views.py:187 msgid "" "VMs that already have it keep it; VMs created from now on do not get it." msgstr "已有此密钥的虚拟机会保留它;此后创建的虚拟机不会再获得它。" -#: accounts/views.py:225 +#: accounts/views.py:237 msgid "Password Changed" msgstr "密码已修改" -#: accounts/views.py:256 +#: accounts/views.py:268 msgid "Create User Instance" msgstr "创建用户虚拟机" -#: accounts/views.py:291 +#: accounts/views.py:303 msgid "Update User Instance" msgstr "更新用户虚拟机" -#: accounts/views.py:309 +#: accounts/views.py:321 msgid "The user loses access to this VM; the VM itself is not changed." msgstr "该用户将失去对此虚拟机的访问权限;虚拟机本身不受影响。" -#: accounts/views.py:344 +#: accounts/views.py:356 #, python-format msgid "OTP Sent to %(email)s" msgstr "OTP 已发送至 %(email)s" -#: accounts/views.py:353 +#: accounts/views.py:365 msgid "Email OTP" msgstr "邮件发送 OTP" -#: accounts/views.py:387 +#: accounts/views.py:399 #, python-format msgid "The OTP QR code could not be mailed to %(user)s: %(error)s" msgstr "无法将 OTP 二维码通过邮件发送给 %(user)s:%(error)s" -#: accounts/views.py:391 +#: accounts/views.py:403 #, python-format msgid "OTP QR code was emailed to user %(user)s" msgstr "OTP 二维码已通过邮件发送给用户 %(user)s" -#: accounts/views.py:395 +#: accounts/views.py:407 msgid "User email not set, failed to send QR code" msgstr "未设置用户邮箱,无法发送二维码" -#: accounts/views.py:407 +#: accounts/views.py:419 #, python-format msgid "OTP of %(user)s was reset: a new QR code can be mailed." msgstr "%(user)s 的 OTP 已重置:可以邮寄新的二维码。" @@ -936,16 +936,16 @@ msgstr "结果" msgid "IP" msgstr "IP" -#: admin/templates/admin/logs.html:56 admin/views.py:322 instances/states.py:19 +#: admin/templates/admin/logs.html:56 admin/views.py:395 instances/states.py:19 #: instances/views.py:441 logs/views.py:18 msgid "Unknown" msgstr "未知" -#: admin/templates/admin/logs.html:56 admin/views.py:322 logs/views.py:18 +#: admin/templates/admin/logs.html:56 admin/views.py:395 logs/views.py:18 msgid "Done" msgstr "完成" -#: admin/templates/admin/logs.html:56 admin/views.py:322 logs/views.py:18 +#: admin/templates/admin/logs.html:56 admin/views.py:395 logs/views.py:18 #: operations/templates/operations/job.html:107 msgid "Failed" msgstr "失败" @@ -1076,7 +1076,7 @@ msgstr "创建用户" msgid "New user" msgstr "新建用户" -#: admin/templates/admin/user_list.html:19 admin/views.py:142 +#: admin/templates/admin/user_list.html:19 admin/views.py:179 #: instances/templates/instances/settings_tab.html:79 templates/navbar.html:32 msgid "Users" msgstr "用户" @@ -1134,56 +1134,60 @@ msgstr "使用此处设置的密码登录。" msgid "Signs in another way, such as LDAP. The current password is removed." msgstr "通过其他方式(如 LDAP)登录。当前密码将被移除。" -#: admin/views.py:39 +#: admin/views.py:42 #, python-format msgid "" "%(name)s was changed meanwhile: here it is as it is now; make your change " "again" msgstr "%(name)s 在此期间已更改:以下是其当前状态;请重新进行更改" -#: admin/views.py:72 +#: admin/views.py:75 msgid "Create Group" msgstr "创建用户组" -#: admin/views.py:101 +#: admin/views.py:117 msgid "Update Group" msgstr "更新用户组" -#: admin/views.py:117 +#: admin/views.py:133 msgid "Its members stay but lose the permissions it gave them." msgstr "其成员仍保留,但会失去该用户组授予的权限。" -#: admin/views.py:123 +#: admin/views.py:139 msgid "You cannot block, delete or demote your own account" msgstr "不能禁用、删除或降级你自己的账户" -#: admin/views.py:174 +#: admin/views.py:140 +msgid "This would leave no active superuser" +msgstr "这将导致没有可用的超级用户" + +#: admin/views.py:214 msgid "Create User" msgstr "创建用户" -#: admin/views.py:223 +#: admin/views.py:287 msgid "Update User" msgstr "更新用户" -#: admin/views.py:247 +#: admin/views.py:311 #, python-format msgid "Password changed for %(user)s" msgstr "已为 %(user)s 修改密码" -#: admin/views.py:271 +#: admin/views.py:338 msgid "Their access to VMs, SSH keys and settings go; the VMs themselves stay." msgstr "其对虚拟机、SSH 密钥和设置的访问将被移除;虚拟机本身保留。" -#: admin/views.py:371 +#: admin/views.py:444 msgid "deleted user" msgstr "已删除的用户" -#: admin/views.py:383 +#: admin/views.py:456 #, python-format msgid "Removed VM %(name)s deleted" msgstr "已删除已移除的虚拟机 %(name)s" -#: admin/views.py:390 +#: admin/views.py:463 msgid "Its owners no longer get the VM back if its UUID shows up again." msgstr "若其 UUID 再次出现,其所有者将不再恢复对该虚拟机的所有权。" diff --git a/operations/claims.py b/operations/claims.py index bf6146c1..a9990317 100644 --- a/operations/claims.py +++ b/operations/claims.py @@ -58,6 +58,11 @@ def nwfilters_key(compute_id): return f"nwfilters:{compute_id}" +def users_key(): + """The panel's users: one change of them at a time, checked as it is saved.""" + return "users" + + def name_key(name): """A VM name is the panel's on every compute (the name checks are global).""" return f"name:{name}"