1
0
Fork 0
mirror of https://github.com/retspen/webvirtcloud synced 2024-12-25 15:45:23 +00:00

Add an option to allow an user to change VNC settings

This commit is contained in:
Valentin Samir 2016-05-09 12:08:31 +02:00
parent 7b3fcd17ea
commit 7efbfec17f
6 changed files with 43 additions and 0 deletions

View file

@ -0,0 +1,19 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('accounts', '0003_usersshkey'),
]
operations = [
migrations.AddField(
model_name='userinstance',
name='is_vnc',
field=models.BooleanField(default=False),
),
]

View file

@ -8,6 +8,7 @@ class UserInstance(models.Model):
instance = models.ForeignKey(Instance) instance = models.ForeignKey(Instance)
is_change = models.BooleanField(default=False) is_change = models.BooleanField(default=False)
is_delete = models.BooleanField(default=False) is_delete = models.BooleanField(default=False)
is_vnc = models.BooleanField(default=False)
def __unicode__(self): def __unicode__(self):
return self.instance.name return self.instance.name

View file

@ -29,6 +29,7 @@
<tr> <tr>
<th>#</th> <th>#</th>
<th>{% trans "Instance" %}</th> <th>{% trans "Instance" %}</th>
<th>{% trans "VNC" %}</th>
<th>{% trans "Resize" %}</th> <th>{% trans "Resize" %}</th>
<th>{% trans "Delete" %}</th> <th>{% trans "Delete" %}</th>
<th colspan="2">{% trans "Action" %}</th> <th colspan="2">{% trans "Action" %}</th>
@ -39,6 +40,7 @@
<tr> <tr>
<td>{{ forloop.counter }}</td> <td>{{ forloop.counter }}</td>
<td><a href="{% url 'instance' inst.instance.compute.id inst.instance.name %}">{{ inst.instance.name }}</a></td> <td><a href="{% url 'instance' inst.instance.compute.id inst.instance.name %}">{{ inst.instance.name }}</a></td>
<td>{{ inst.is_vnc }}</td>
<td>{{ inst.is_change }}</td> <td>{{ inst.is_change }}</td>
<td>{{ inst.is_delete }}</td> <td>{{ inst.is_delete }}</td>
<td style="width:5px;"> <td style="width:5px;">
@ -57,6 +59,15 @@
<div class="modal-body"> <div class="modal-body">
<form class="form-horizontal" method="post" action="" role="form">{% csrf_token %} <form class="form-horizontal" method="post" action="" role="form">{% csrf_token %}
<input type="hidden" name="user_inst" value="{{ inst.id }}"> <input type="hidden" name="user_inst" value="{{ inst.id }}">
<div class="form-group">
<label class="col-sm-4 control-label">{% trans "VNC" %}</label>
<div class="col-sm-6">
<select type="text" class="form-control" name="inst_vnc">
<option value="">False</option>
<option value="1" {% if inst.is_vnc %}selected{% endif %}>True</option>
</select>
</div>
</div>
<div class="form-group"> <div class="form-group">
<label class="col-sm-4 control-label">{% trans "Resize" %}</label> <label class="col-sm-4 control-label">{% trans "Resize" %}</label>
<div class="col-sm-6"> <div class="col-sm-6">

View file

@ -151,11 +151,13 @@ def account(request, user_id):
return HttpResponseRedirect(request.get_full_path()) return HttpResponseRedirect(request.get_full_path())
if 'permission' in request.POST: if 'permission' in request.POST:
user_inst = request.POST.get('user_inst', '') user_inst = request.POST.get('user_inst', '')
inst_vnc = request.POST.get('inst_vnc', '')
inst_change = request.POST.get('inst_change', '') inst_change = request.POST.get('inst_change', '')
inst_delete = request.POST.get('inst_delete', '') inst_delete = request.POST.get('inst_delete', '')
edit_user_inst = UserInstance.objects.get(id=user_inst) edit_user_inst = UserInstance.objects.get(id=user_inst)
edit_user_inst.is_change = bool(inst_change) edit_user_inst.is_change = bool(inst_change)
edit_user_inst.is_delete = bool(inst_delete) edit_user_inst.is_delete = bool(inst_delete)
edit_user_inst.is_vnc = bool(inst_vnc)
edit_user_inst.save() edit_user_inst.save()
return HttpResponseRedirect(request.get_full_path()) return HttpResponseRedirect(request.get_full_path())
if 'add' in request.POST: if 'add' in request.POST:

View file

@ -477,11 +477,15 @@
{% trans "Autostart" %} {% trans "Autostart" %}
</a> </a>
</li> </li>
{% endif %}
{% if request.user.is_superuser or userinstace.is_vnc %}
<li role="presentation"> <li role="presentation">
<a href="#vncsettings" aria-controls="vncsettings" role="tab" data-toggle="tab"> <a href="#vncsettings" aria-controls="vncsettings" role="tab" data-toggle="tab">
{% trans "VNC" %} {% trans "VNC" %}
</a> </a>
</li> </li>
{% endif %}
{% if request.user.is_superuser %}
<li role="presentation"> <li role="presentation">
<a href="#clone" aria-controls="clone" role="tab" data-toggle="tab"> <a href="#clone" aria-controls="clone" role="tab" data-toggle="tab">
{% trans "Clone" %} {% trans "Clone" %}
@ -551,6 +555,8 @@
</form> </form>
<div class="clearfix"></div> <div class="clearfix"></div>
</div> </div>
{% endif %}
{% if request.user.is_superuser or userinstace.is_vnc %}
<div role="tabpanel" class="tab-pane tab-pane-bordered" id="vncsettings"> <div role="tabpanel" class="tab-pane tab-pane-bordered" id="vncsettings">
<p>{% trans "To set console's type, shutdown the instance." %}</p> <p>{% trans "To set console's type, shutdown the instance." %}</p>
<form class="form-horizontal" method="post" role="form">{% csrf_token %} <form class="form-horizontal" method="post" role="form">{% csrf_token %}
@ -643,6 +649,8 @@
</form> </form>
<div class="clearfix"></div> <div class="clearfix"></div>
</div> </div>
{% endif %}
{% if request.user.is_superuser %}
<div role="tabpanel" class="tab-pane tab-pane-bordered" id="clone"> <div role="tabpanel" class="tab-pane tab-pane-bordered" id="clone">
<p style="font-weight:bold;">{% trans "Create a clone" %}</p> <p style="font-weight:bold;">{% trans "Create a clone" %}</p>
<form class="form-horizontal" action="" method="post" role="form">{% csrf_token %} <form class="form-horizontal" action="" method="post" role="form">{% csrf_token %}

View file

@ -418,6 +418,7 @@ 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() + '#xmledit') return HttpResponseRedirect(request.get_full_path() + '#xmledit')
if request.user.is_superuser or userinstace.is_vnc:
if 'set_console_passwd' in request.POST: if 'set_console_passwd' in request.POST:
if request.POST.get('auto_pass', ''): if request.POST.get('auto_pass', ''):
passwd = randomPasswd() passwd = randomPasswd()
@ -456,6 +457,7 @@ 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() + '#vncsettings') return HttpResponseRedirect(request.get_full_path() + '#vncsettings')
if request.user.is_superuser:
if 'migrate' in request.POST: if 'migrate' in request.POST:
compute_id = request.POST.get('compute_id', '') compute_id = request.POST.get('compute_id', '')
live = request.POST.get('live_migrate', False) live = request.POST.get('live_migrate', False)