mirror of
https://github.com/retspen/webvirtcloud
synced 2026-12-03 09:26:03 +00:00
fix(admin): a new user is not given a VM that has its one owner
NEW_USER_DEFAULT_INSTANCES gives each new user the VMs it names. With "Multiple Owner for VM" off, an owned VM named there was given the new user as a second owner anyway, with its power and console. Creating the user is now refused, as adding a second owner on the VM's Users tab is; the check runs again with the inserts, under the ownership lock.
This commit is contained in:
parent
8263680c48
commit
dde7672375
7 changed files with 121 additions and 83 deletions
|
|
@ -96,6 +96,18 @@ class DefaultInstancesTests(TestCase):
|
|||
self.assertRedirects(self.create(), reverse("admin:user_list"))
|
||||
self.assertEqual([o.instance for o in UserInstance.objects.filter(user__username="newbie")], [self.web])
|
||||
|
||||
@override_settings(NEW_USER_DEFAULT_INSTANCES=["web"])
|
||||
def test_an_owned_vm_is_not_given_a_second_owner_when_one_is_allowed(self):
|
||||
from appsettings.models import AppSettings
|
||||
|
||||
UserInstance.objects.create(user=User.objects.create_user("alice"), instance=self.web)
|
||||
AppSettings.objects.filter(key="ALLOW_INSTANCE_MULTIPLE_OWNER").update(value="False")
|
||||
self.assertContains(self.create(), "NEW_USER_DEFAULT_INSTANCES: web has an owner, and only one is allowed")
|
||||
self.assertFalse(User.objects.filter(username="newbie").exists())
|
||||
AppSettings.objects.filter(key="ALLOW_INSTANCE_MULTIPLE_OWNER").update(value="True")
|
||||
self.assertRedirects(self.create(), reverse("admin:user_list"))
|
||||
self.assertEqual(UserInstance.objects.filter(instance=self.web).count(), 2)
|
||||
|
||||
def test_a_name_that_is_not_one_vm_is_refused_on_the_form(self):
|
||||
for name in ("no-such-vm", "db"):
|
||||
with self.subTest(name), override_settings(NEW_USER_DEFAULT_INSTANCES=["web", name]):
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue