1
0
Fork 0
mirror of https://github.com/retspen/webvirtcloud synced 2026-12-02 17:06:09 +00:00

fix(accounts): owners given before one owner was the rule keep editable rights

With "Multiple Owner for VM" turned off after a VM was given two owners,
changing either owner's rights (Delete the VM, say) was refused: the
form's one-owner check counted the other owner. The check now applies to
a new owner only, as its message says.

The user and group forms showed the permissions by the English names the
database keeps (Can clone instances, ...), in every language; they are
named in the user's language now.
This commit is contained in:
catborise 2026-11-13 14:27:32 +03:00
parent dde7672375
commit 35a5bbdb62
10 changed files with 151 additions and 100 deletions

View file

@ -17,6 +17,15 @@ from instances.models import Instance
from .models import Permission
# each permission's name in the user's language: the database keeps the English one
PERMISSION_NAMES = {
"change_password": _("Can change password"),
"clone_instances": _("Can clone instances"),
"passwordless_console": _("Can access console without password"),
"snapshot_instances": _("Can snapshot instances"),
"view_instances": _("Can view instances"),
}
# what each permission lets a user do, shown beside its switch
PERMISSION_HELP = {
"change_password": _("Change their own password on their profile page"),
@ -28,8 +37,13 @@ PERMISSION_HELP = {
def permission_rows(field):
"""Each permission's checkbox of a bound field with what it lets a user do."""
return [(box, PERMISSION_HELP.get(box.data["value"].instance.codename, "")) for box in field]
"""Each permission's checkbox of a bound field with its name and what it lets a user do."""
rows = []
for box in field:
permission = box.data["value"].instance
rows.append((box, PERMISSION_NAMES.get(permission.codename, permission.name),
PERMISSION_HELP.get(permission.codename, "")))
return rows
class GroupForm(forms.ModelForm):

View file

@ -32,12 +32,12 @@
</div>
<div class="col-lg-9 form-section-fields">
<div class="border-top">
{% for box, help in form.permission_rows %}
{% for box, name, help in form.permission_rows %}
<div class="form-check form-switch border-bottom py-2 ps-5">
<input id="{{ box.id_for_label }}" class="form-check-input" type="checkbox" role="switch" name="permissions"
value="{{ box.data.value }}"{% if box.data.selected %} checked{% endif %}>
<label class="form-check-label" for="{{ box.id_for_label }}">
<span class="d-block">{{ box.data.value.instance.name }}</span>
<span class="d-block">{{ name }}</span>
<span class="small text-body-secondary">{{ help }}</span>
</label>
</div>

View file

@ -137,12 +137,12 @@
<legend class="visually-hidden">{% trans "Own permissions" %}</legend>
<p class="small text-body-secondary mb-2">{% trans "Off grants nothing here; it takes away nothing a group grants." %}</p>
<div class="border-top">
{% for box, help in user_form.permission_rows %}
{% for box, name, help in user_form.permission_rows %}
<div class="form-check form-switch border-bottom py-2 ps-5">
<input id="{{ box.id_for_label }}" class="form-check-input" type="checkbox" role="switch" name="user_permissions"
value="{{ box.data.value }}"{% if box.data.selected %} checked{% endif %}>
<label class="form-check-label" for="{{ box.id_for_label }}">
<span class="d-block">{{ box.data.value.instance.name }}</span>
<span class="d-block">{{ name }}</span>
<span class="small text-body-secondary">{{ help }}</span>
</label>
</div>

View file

@ -44,6 +44,14 @@ class UserCreateTests(TestCase):
ticked = set(re.findall(r'<input[^>]*name="user_permissions"[^>]*value="(\d+)"[^>]*checked', page))
self.assertEqual(ticked, {str(self.change_password.pk), str(Permission.objects.get(codename="passwordless_console").pk)})
def test_permissions_are_named_in_the_users_language(self):
# the database keeps each permission's English name
page = self.client.get(reverse("admin:user_create"), HTTP_ACCEPT_LANGUAGE="tr").content.decode()
for name in ("Parola değiştirebilir", "Sanal makineleri klonlayabilir", "Parolasız konsol erişimi yapabilir",
"Sanal makinelerin anlık görüntüsünü alabilir", "Sanal makineleri görebilir"):
self.assertIn(name, page)
self.assertNotIn("Can clone instances", page)
def test_groups_and_permissions_are_saved(self):
group = Group.objects.create(name="uc-group")
self.create(groups=[group.pk], user_permissions=[self.change_password.pk])