Commit dff04fba by Czémán Arnold

dashboard, vm: add boot menu toggle button for vm-detail view and add toggle_boot_menu permission

Issue: #439
parent cbcbb8e6
...@@ -20,6 +20,7 @@ ...@@ -20,6 +20,7 @@
"bootbox": "~4.3.0", "bootbox": "~4.3.0",
"intro.js": "0.9.0", "intro.js": "0.9.0",
"favico.js": "~0.3.5", "favico.js": "~0.3.5",
"datatables": "~1.10.4" "datatables": "~1.10.4",
"bootstrap-toggle": "~2.2.1"
} }
} }
...@@ -178,6 +178,7 @@ PIPELINE_CSS = { ...@@ -178,6 +178,7 @@ PIPELINE_CSS = {
"all": {"source_filenames": ( "all": {"source_filenames": (
"compile_bootstrap.less", "compile_bootstrap.less",
"bootstrap/dist/css/bootstrap-theme.css", "bootstrap/dist/css/bootstrap-theme.css",
"bootstrap-toggle/css/bootstrap-toggle.min.css",
"fontawesome/css/font-awesome.css", "fontawesome/css/font-awesome.css",
"jquery-simple-slider/css/simple-slider.css", "jquery-simple-slider/css/simple-slider.css",
"intro.js/introjs.css", "intro.js/introjs.css",
...@@ -227,6 +228,7 @@ PIPELINE_JS = { ...@@ -227,6 +228,7 @@ PIPELINE_JS = {
"output_filename": "all.js", "output_filename": "all.js",
}, },
"vm-detail": {"source_filenames": ( "vm-detail": {"source_filenames": (
"bootstrap-toggle/js/bootstrap-toggle.min.js",
"dashboard/vm-details.js", "dashboard/vm-details.js",
"no-vnc/include/util.js", "no-vnc/include/util.js",
"no-vnc/include/webutil.js", "no-vnc/include/webutil.js",
......
...@@ -1429,6 +1429,27 @@ class RawDataForm(forms.ModelForm): ...@@ -1429,6 +1429,27 @@ class RawDataForm(forms.ModelForm):
return helper return helper
class ToggleBootMenuForm(forms.ModelForm):
class Meta:
model = Instance
fields = ('boot_menu', )
widgets = {
'boot_menu': forms.CheckboxInput(attrs={'data-toggle': 'toggle',
'data-on': _('On'),
'data-off': _('Off')})
}
@property
def helper(self):
helper = FormHelper()
helper.form_show_labels = True
helper.form_action =\
reverse_lazy("dashboard.views.vm-toggle-boot-menu",
kwargs={'pk': self.instance.pk})
return helper
class GroupPermissionForm(forms.ModelForm): class GroupPermissionForm(forms.ModelForm):
permissions = forms.ModelMultipleChoiceField( permissions = forms.ModelMultipleChoiceField(
queryset=None, queryset=None,
......
...@@ -252,4 +252,8 @@ $(function() { ...@@ -252,4 +252,8 @@ $(function() {
return e.preventDefault(); return e.preventDefault();
}); });
$("#id_boot_menu").change(function(){
$("#id_boot_menu").parents("form").submit();
});
}); });
...@@ -2,7 +2,6 @@ ...@@ -2,7 +2,6 @@
{% load sizefieldtags %} {% load sizefieldtags %}
{% load crispy_forms_tags %} {% load crispy_forms_tags %}
<div class="label label-info label-100" id="modify-the-resources"> <div class="label label-info label-100" id="modify-the-resources">
{% trans "Modify the resources" %} {% trans "Modify the resources" %}
</div> </div>
...@@ -104,6 +103,15 @@ ...@@ -104,6 +103,15 @@
{% endif %} {% endif %}
{% if toggle_boot_menu_form %}
<hr />
<div class="row">
<div class="col-sm-12">
{% crispy toggle_boot_menu_form %}
</div>
</div>
{% endif %}
{% block extra_js %} {% block extra_js %}
<style> <style>
label {padding-top: 6px;} label {padding-top: 6px;}
......
...@@ -42,7 +42,7 @@ from .views import ( ...@@ -42,7 +42,7 @@ from .views import (
ConnectCommandDelete, ConnectCommandDetail, ConnectCommandCreate, ConnectCommandDelete, ConnectCommandDetail, ConnectCommandCreate,
StoreList, store_download, store_upload, store_get_upload_url, StoreRemove, StoreList, store_download, store_upload, store_get_upload_url, StoreRemove,
store_new_directory, store_refresh_toplist, store_new_directory, store_refresh_toplist,
VmTraitsUpdate, VmRawDataUpdate, VmTraitsUpdate, VmRawDataUpdate, VmToggleBootMenuUpdate,
GroupPermissionsView, GroupPermissionsView,
LeaseAclUpdateView, LeaseAclUpdateView,
toggle_template_tutorial, toggle_template_tutorial,
...@@ -113,6 +113,9 @@ urlpatterns = patterns( ...@@ -113,6 +113,9 @@ urlpatterns = patterns(
name='dashboard.views.vm-traits'), name='dashboard.views.vm-traits'),
url(r'^vm/(?P<pk>\d+)/raw_data/$', VmRawDataUpdate.as_view(), url(r'^vm/(?P<pk>\d+)/raw_data/$', VmRawDataUpdate.as_view(),
name='dashboard.views.vm-raw-data'), name='dashboard.views.vm-raw-data'),
url(r'^vm/(?P<pk>\d+)/toggle_boot_menu/$',
VmToggleBootMenuUpdate.as_view(),
name='dashboard.views.vm-toggle-boot-menu'),
url(r'^vm/(?P<pk>\d+)/toggle_tutorial/$', toggle_template_tutorial, url(r'^vm/(?P<pk>\d+)/toggle_tutorial/$', toggle_template_tutorial,
name='dashboard.views.vm-toggle-tutorial'), name='dashboard.views.vm-toggle-tutorial'),
......
...@@ -61,6 +61,7 @@ from .util import ( ...@@ -61,6 +61,7 @@ from .util import (
) )
from ..forms import ( from ..forms import (
AclUserOrGroupAddForm, VmResourcesForm, TraitsForm, RawDataForm, AclUserOrGroupAddForm, VmResourcesForm, TraitsForm, RawDataForm,
ToggleBootMenuForm,
VmAddInterfaceForm, VmCreateDiskForm, VmDownloadDiskForm, VmSaveForm, VmAddInterfaceForm, VmCreateDiskForm, VmDownloadDiskForm, VmSaveForm,
VmRenewForm, VmStateChangeForm, VmListSearchForm, VmCustomizeForm, VmRenewForm, VmStateChangeForm, VmListSearchForm, VmCustomizeForm,
VmDiskResizeForm, RedeployForm, VmDiskRemoveForm, VmDiskResizeForm, RedeployForm, VmDiskRemoveForm,
...@@ -161,6 +162,10 @@ class VmDetailView(GraphMixin, CheckedDetailView): ...@@ -161,6 +162,10 @@ class VmDetailView(GraphMixin, CheckedDetailView):
context['traits_form'] = TraitsForm(instance=instance) context['traits_form'] = TraitsForm(instance=instance)
context['raw_data_form'] = RawDataForm(instance=instance) context['raw_data_form'] = RawDataForm(instance=instance)
if is_owner and user.has_perm("vm.toggle_boot_menu"):
context['toggle_boot_menu_form'] =\
ToggleBootMenuForm(instance=instance)
# resources change perm # resources change perm
context['can_change_resources'] = self.request.user.has_perm( context['can_change_resources'] = self.request.user.has_perm(
"vm.change_resources") "vm.change_resources")
...@@ -310,6 +315,26 @@ class VmRawDataUpdate(SuperuserRequiredMixin, UpdateView): ...@@ -310,6 +315,26 @@ class VmRawDataUpdate(SuperuserRequiredMixin, UpdateView):
return self.get_object().get_absolute_url() + "#resources" return self.get_object().get_absolute_url() + "#resources"
class VmToggleBootMenuUpdate(LoginRequiredMixin, UpdateView):
form_class = ToggleBootMenuForm
model = Instance
def get(self, *args, **kwargs):
raise Http404()
def form_valid(self, form):
user = self.request.user
is_owner = form.instance.has_level(user, "owner")
if not (is_owner and user.has_perm("vm.toggle_boot_menu")):
raise PermissionDenied()
return super(VmToggleBootMenuUpdate, self).form_valid(form)
def get_success_url(self):
return self.get_object().get_absolute_url() + "#resources"
class VmOperationView(AjaxOperationMixin, OperationView): class VmOperationView(AjaxOperationMixin, OperationView):
model = Instance model = Instance
......
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.db import models, migrations
class Migration(migrations.Migration):
dependencies = [
('vm', '0002_interface_model'),
]
operations = [
migrations.AlterModelOptions(
name='instance',
options={'ordering': ('pk',), 'verbose_name': 'instance', 'verbose_name_plural': 'instances', 'permissions': (('access_console', 'Can access the graphical console of a VM.'), ('change_resources', 'Can change resources of a running VM.'), ('set_resources', 'Can change resources of a new VM.'), ('create_vm', 'Can create a new VM.'), ('redeploy', 'Can redeploy a VM.'), ('config_ports', 'Can configure port forwards.'), ('recover', 'Can recover a destroyed VM.'), ('emergency_change_state', 'Can change VM state to NOSTATE.'), ('toggle_boot_menu', 'Can turn on/off boot menu.'))},
),
]
...@@ -272,6 +272,7 @@ class Instance(AclBase, VirtualMachineDescModel, StatusModel, OperatedMixin, ...@@ -272,6 +272,7 @@ class Instance(AclBase, VirtualMachineDescModel, StatusModel, OperatedMixin,
('config_ports', _('Can configure port forwards.')), ('config_ports', _('Can configure port forwards.')),
('recover', _('Can recover a destroyed VM.')), ('recover', _('Can recover a destroyed VM.')),
('emergency_change_state', _('Can change VM state to NOSTATE.')), ('emergency_change_state', _('Can change VM state to NOSTATE.')),
('toggle_boot_menu', _('Can turn on/off boot menu.')),
) )
verbose_name = _('instance') verbose_name = _('instance')
verbose_name_plural = _('instances') verbose_name_plural = _('instances')
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment