1
0
Fork 0
mirror of https://github.com/retspen/webvirtcloud synced 2026-12-03 01:16:10 +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:
catborise 2026-11-13 14:26:24 +03:00
parent 8263680c48
commit dde7672375
7 changed files with 121 additions and 83 deletions

View file

@ -10,7 +10,8 @@ from django.db.models import Q
from django.utils.translation import gettext_lazy as _
from accounts.forms import UniqueEmailMixin
from accounts.models import UserAttributes
from accounts.models import UserAttributes, UserInstance
from appsettings.settings import app_settings
from instances.models import Instance
from .models import Permission
@ -140,6 +141,10 @@ class UserCreateForm(UserForm):
found = list(Instance.objects.filter(name=name)[:2])
if len(found) != 1:
raise ValidationError(_("NEW_USER_DEFAULT_INSTANCES: %(name)s is not exactly one VM") % {"name": name})
# as on the VM's Users tab: with one owner allowed, an owned VM is not given a second
if app_settings.ALLOW_INSTANCE_MULTIPLE_OWNER == "False" and UserInstance.objects.filter(instance=found[0]).exists():
raise ValidationError(_("NEW_USER_DEFAULT_INSTANCES: %(name)s has an owner, and only one is allowed")
% {"name": name})
self.default_instances += found
return cleaned