mirror of
https://github.com/retspen/webvirtcloud
synced 2026-12-03 17:36:05 +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
|
|
@ -2,6 +2,7 @@ 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 django.conf import settings
|
||||
from django.contrib import messages
|
||||
from django.contrib.auth import update_session_auth_hash
|
||||
|
|
@ -131,14 +132,20 @@ 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"), transaction.atomic():
|
||||
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)
|
||||
return redirect("admin:user_list")
|
||||
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)
|
||||
if user_form.is_valid():
|
||||
return redirect("admin:user_list")
|
||||
|
||||
return render(
|
||||
request,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue