diff --git a/accounts/forms.py b/accounts/forms.py index 836435ae..f7cb7a9d 100644 --- a/accounts/forms.py +++ b/accounts/forms.py @@ -21,10 +21,9 @@ class UserInstanceForm(ModelForm): def clean_instance(self): instance = self.cleaned_data["instance"] - if app_settings.ALLOW_INSTANCE_MULTIPLE_OWNER == "False": - # the ownership being edited is not another owner - exists = UserInstance.objects.filter(instance=instance).exclude(pk=self.instance.pk) - if exists: + # a new owner only: rights of one the VM has may still be changed after the setting is turned off + if app_settings.ALLOW_INSTANCE_MULTIPLE_OWNER == "False" and self.instance.pk is None: + if UserInstance.objects.filter(instance=instance).exists(): raise ValidationError(_("Instance owned by another user")) return instance diff --git a/accounts/tests/test_views.py b/accounts/tests/test_views.py index cec60105..ef9f0b9d 100644 --- a/accounts/tests/test_views.py +++ b/accounts/tests/test_views.py @@ -329,6 +329,12 @@ class SingleOwnerEditTests(TestCase): self.assertRedirects(response, reverse("accounts:account", args=[bob.pk]), fetch_redirect_response=False) ui.refresh_from_db() self.assertTrue(ui.is_vnc) + # owners given while more were allowed: each one's rights still change + carol = UserInstance.objects.create(user=get_user_model().objects.create_user("carol"), instance=vm) + response = self.client.post(reverse("accounts:user_instance_update", args=[carol.pk]), {"is_delete": "on"}) + self.assertRedirects(response, reverse("accounts:account", args=[carol.user.pk]), fetch_redirect_response=False) + carol.refresh_from_db() + self.assertTrue(carol.is_delete) class OwnerRightsReturnTestCase(TestCase): diff --git a/admin/forms.py b/admin/forms.py index 3fd41208..a428b8e7 100644 --- a/admin/forms.py +++ b/admin/forms.py @@ -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): diff --git a/admin/templates/admin/group_form.html b/admin/templates/admin/group_form.html index 2880d660..8a008c93 100644 --- a/admin/templates/admin/group_form.html +++ b/admin/templates/admin/group_form.html @@ -32,12 +32,12 @@
{% trans "Off grants nothing here; it takes away nothing a group grants." %}