1
0
Fork 0
mirror of https://github.com/retspen/webvirtcloud synced 2025-07-31 12:41:08 +00:00

allow multiple owners of single instance. this is controlled by settings.ALLOW_INSTANCE_MULTIPLE_OWNER

This commit is contained in:
Jan Krcmar 2016-01-15 10:12:03 +01:00
parent 50ddda98f2
commit 6151792d9b
2 changed files with 18 additions and 9 deletions

View file

@ -7,6 +7,7 @@ from django.contrib.auth.decorators import login_required
from accounts.models import UserInstance, UserSSHKey
from instances.models import Instance
from accounts.forms import UserAddForm
from django.conf import settings
@login_required
@ -135,6 +136,11 @@ def account(request, user_id):
user_insts = UserInstance.objects.filter(user_id=user_id)
instances = Instance.objects.all()
def add_user_inst(request, inst_id, user_id):
add_user_inst = UserInstance(instance_id=int(inst_id), user_id=user_id)
add_user_inst.save()
return HttpResponseRedirect(request.get_full_path())
if user.username == request.user.username:
return HttpResponseRedirect(reverse('profile'))
@ -155,13 +161,14 @@ def account(request, user_id):
return HttpResponseRedirect(request.get_full_path())
if 'add' in request.POST:
inst_id = request.POST.get('inst_id', '')
try:
check_inst = UserInstance.objects.get(instance_id=int(inst_id))
msg = _("Instance already added")
error_messages.append(msg)
except UserInstance.DoesNotExist:
add_user_inst = UserInstance(instance_id=int(inst_id), user_id=user_id)
add_user_inst.save()
return HttpResponseRedirect(request.get_full_path())
if settings.ALLOW_INSTANCE_MULTIPLE_OWNER:
return add_user_inst(request, inst_id, user_id)
else:
try:
check_inst = UserInstance.objects.get(instance_id=int(inst_id))
msg = _("Instance already added")
error_messages.append(msg)
except UserInstance.DoesNotExist:
return add_user_inst(request, inst_id, user_id)
return render(request, 'account.html', locals())