mirror of
https://github.com/retspen/webvirtcloud
synced 2024-12-24 23:25:24 +00:00
instance owner view: add owner button, delete owner button
This commit is contained in:
parent
ad3b4d817b
commit
d4158a33ee
3 changed files with 90 additions and 4 deletions
36
instances/templates/add_instance_owner_block.html
Normal file
36
instances/templates/add_instance_owner_block.html
Normal file
|
@ -0,0 +1,36 @@
|
||||||
|
{% load i18n %}
|
||||||
|
{% if request.user.is_superuser %}
|
||||||
|
<a href="#addInstanceOwner" type="button" class="btn btn-success pull-right" data-toggle="modal">
|
||||||
|
<span class="glyphicon glyphicon-plus" aria-hidden="true"></span>
|
||||||
|
</a>
|
||||||
|
|
||||||
|
<!-- Modal pool -->
|
||||||
|
<div class="modal fade" id="addInstanceOwner" tabindex="-1" role="dialog" aria-labelledby="addInstanceOwnerLabel" aria-hidden="true">
|
||||||
|
<div class="modal-dialog">
|
||||||
|
<div class="modal-content">
|
||||||
|
<div class="modal-header">
|
||||||
|
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
|
||||||
|
<h4 class="modal-title">{% trans "Add Instance Owner" %}</h4>
|
||||||
|
</div>
|
||||||
|
<div class="modal-body">
|
||||||
|
<form class="form-horizontal" method="post" action="" role="form">{% csrf_token %}
|
||||||
|
<div class="form-group">
|
||||||
|
<label class="col-sm-4 control-label">{% trans "User" %}</label>
|
||||||
|
<div class="col-sm-6">
|
||||||
|
<select class="form-control" name="user_id">
|
||||||
|
{% for user in users %}
|
||||||
|
<option value="{{ user.id }}">{{ user.username }}</option>
|
||||||
|
{% endfor %}
|
||||||
|
</select>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="modal-footer">
|
||||||
|
<button type="button" class="btn btn-default" data-dismiss="modal">{% trans "Close" %}</button>
|
||||||
|
<button type="submit" class="btn btn-primary" name="add_owner">{% trans "Add" %}</button>
|
||||||
|
</div>
|
||||||
|
</form>
|
||||||
|
</div> <!-- /.modal-content -->
|
||||||
|
</div> <!-- /.modal-dialog -->
|
||||||
|
</div> <!-- /.modal -->
|
||||||
|
{% endif %}
|
|
@ -995,10 +995,31 @@
|
||||||
<div class="clearfix"></div>
|
<div class="clearfix"></div>
|
||||||
</div>
|
</div>
|
||||||
<div role="tabpanel" class="tab-pane tab-pane-bordered" id="users">
|
<div role="tabpanel" class="tab-pane tab-pane-bordered" id="users">
|
||||||
<p style="font-weight:bold;">{% trans "Instance owners" %}</p>
|
<div>
|
||||||
|
<p style="font-weight:bold;">
|
||||||
|
{% trans "Instance owners" %}
|
||||||
|
{% include 'add_instance_owner_block.html' %}
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
<div class="table-responsive">
|
||||||
|
<table class="table table-striped sortable-theme-bootstrap" data-sortable>
|
||||||
|
<tbody class="searchable">
|
||||||
{% for userinstance in userinstances %}
|
{% for userinstance in userinstances %}
|
||||||
<p><a href="{% url 'account' userinstance.user.id %}">{{ userinstance.user }}</a></p>
|
<tr>
|
||||||
|
<td><a href="{% url 'account' userinstance.user.id %}">{{ userinstance.user }}</a></td>
|
||||||
|
<td style="width:30px;">
|
||||||
|
<form action="" method="post" style="height:10px" role="form">{% csrf_token %}
|
||||||
|
<input type="hidden" name="userinstance" value="{{ userinstance.pk }}">
|
||||||
|
<button type="submit" class="btn btn-sm btn-default" name="del_owner" title="{% trans "Delete" %}">
|
||||||
|
<i class="fa fa-trash"></i>
|
||||||
|
</button>
|
||||||
|
</form>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
</div>
|
||||||
<div class="clearfix"></div>
|
<div class="clearfix"></div>
|
||||||
</div>
|
</div>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|
|
@ -14,6 +14,7 @@ from django.utils.translation import ugettext_lazy as _
|
||||||
from django.contrib.auth.decorators import login_required
|
from django.contrib.auth.decorators import login_required
|
||||||
from computes.models import Compute
|
from computes.models import Compute
|
||||||
from instances.models import Instance
|
from instances.models import Instance
|
||||||
|
from django.contrib.auth.models import User
|
||||||
from accounts.models import UserInstance, UserSSHKey
|
from accounts.models import UserInstance, UserSSHKey
|
||||||
from vrtManager.hostdetails import wvmHostDetails
|
from vrtManager.hostdetails import wvmHostDetails
|
||||||
from vrtManager.instance import wvmInstance, wvmInstances
|
from vrtManager.instance import wvmInstance, wvmInstances
|
||||||
|
@ -182,6 +183,7 @@ def instance(request, compute_id, vname):
|
||||||
compute = get_object_or_404(Compute, pk=compute_id)
|
compute = get_object_or_404(Compute, pk=compute_id)
|
||||||
computes = Compute.objects.all()
|
computes = Compute.objects.all()
|
||||||
computes_count = len(computes)
|
computes_count = len(computes)
|
||||||
|
users = User.objects.all().order_by('username')
|
||||||
publickeys = UserSSHKey.objects.filter(user_id=request.user.id)
|
publickeys = UserSSHKey.objects.filter(user_id=request.user.id)
|
||||||
keymaps = QEMU_KEYMAPS
|
keymaps = QEMU_KEYMAPS
|
||||||
console_types = QEMU_CONSOLE_TYPES
|
console_types = QEMU_CONSOLE_TYPES
|
||||||
|
@ -663,6 +665,33 @@ def instance(request, compute_id, vname):
|
||||||
addlogmsg(request.user.username, instance.name, msg)
|
addlogmsg(request.user.username, instance.name, msg)
|
||||||
return HttpResponseRedirect(request.get_full_path() + '#options')
|
return HttpResponseRedirect(request.get_full_path() + '#options')
|
||||||
|
|
||||||
|
if 'add_owner' in request.POST:
|
||||||
|
user_id = int(request.POST.get('user_id', ''))
|
||||||
|
|
||||||
|
if settings.ALLOW_INSTANCE_MULTIPLE_OWNER:
|
||||||
|
check_inst = UserInstance.objects.filter(instance=instance, user_id=user_id)
|
||||||
|
else:
|
||||||
|
check_inst = UserInstance.objects.filter(instance=instance)
|
||||||
|
|
||||||
|
if check_inst:
|
||||||
|
msg = _("Owner already added")
|
||||||
|
error_messages.append(msg)
|
||||||
|
else:
|
||||||
|
add_user_inst = UserInstance(instance=instance, user_id=user_id)
|
||||||
|
add_user_inst.save()
|
||||||
|
msg = _("Added owner %d" % user_id)
|
||||||
|
addlogmsg(request.user.username, instance.name, msg)
|
||||||
|
return HttpResponseRedirect(request.get_full_path() + '#users')
|
||||||
|
|
||||||
|
if 'del_owner' in request.POST:
|
||||||
|
userinstance_id = int(request.POST.get('userinstance', ''))
|
||||||
|
userinstance = UserInstance.objects.get(pk=userinstance_id)
|
||||||
|
userinstance.delete()
|
||||||
|
msg = _("Deleted owner %d" % userinstance_id)
|
||||||
|
addlogmsg(request.user.username, instance.name, msg)
|
||||||
|
return HttpResponseRedirect(request.get_full_path() + '#users')
|
||||||
|
|
||||||
|
|
||||||
if request.user.is_superuser or request.user.userattributes.can_clone_instances:
|
if request.user.is_superuser or request.user.userattributes.can_clone_instances:
|
||||||
if 'clone' in request.POST:
|
if 'clone' in request.POST:
|
||||||
clone_data = {}
|
clone_data = {}
|
||||||
|
|
Loading…
Reference in a new issue