1
0
Fork 0
mirror of https://github.com/retspen/webvirtcloud synced 2024-11-01 03:54:15 +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', '')
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:
add_user_inst = UserInstance(instance_id=int(inst_id), user_id=user_id)
add_user_inst.save()
return HttpResponseRedirect(request.get_full_path())
return add_user_inst(request, inst_id, user_id)
return render(request, 'account.html', locals())

View file

@ -8,7 +8,7 @@ BASE_DIR = os.path.dirname(os.path.dirname(__file__))
SECRET_KEY = '4y(f4rfqc6f2!i8_vfuu)kav6tdv5#sc=n%o451dm+th0&3uci'
DEBUG = True
DEBUG = False
TEMPLATE_DEBUG = DEBUG
@ -111,3 +111,5 @@ QEMU_KEYMAPS = ['ar', 'da', 'de', 'de-ch', 'en-gb', 'en-us', 'es', 'et', 'fi',
# keepalive interval and count for libvirt connections
LIBVIRT_KEEPALIVE_INTERVAL = 5
LIBVIRT_KEEPALIVE_COUNT = 5
ALLOW_INSTANCE_MULTIPLE_OWNER = True