Commit bdcb0d24 by Szabolcs Gelencser

To try changes on production env

parent 19d074a6
......@@ -58,6 +58,8 @@ from vm.models import (
from storage.models import DataStore, Disk
from django.contrib.admin.widgets import FilteredSelectMultiple
from django.contrib.auth.models import Permission
from vm.models.common import Role
from .models import Profile, GroupProfile, Message
from circle.settings.base import LANGUAGES, MAX_NODE_RAM
from django.utils.translation import string_concat
......@@ -555,6 +557,23 @@ class TemplateForm(forms.ModelForm):
}
class LeaseRolesForm(forms.Form):
roles = forms.MultipleChoiceField(
widget=forms.SelectMultiple(attrs={
'class': "form-control",
})
)
def __init__(self, roles, *args, **kwargs):
lease = kwargs.pop("lease", None)
super(LeaseRolesForm, self).__init__(*args, **kwargs)
self.fields['roles'].choices = (
(role.id, role.name) for role in roles
)
class LeaseForm(forms.ModelForm):
def __init__(self, *args, **kwargs):
......
......@@ -6,6 +6,7 @@
{% block content %}
<div class="row">
<div class="col-md-7">
<div class="panel panel-default">
<div class="panel-heading">
<a class="pull-right btn btn-default btn-xs" href="{% url "dashboard.views.template-list" %}">{% trans "Back" %}</a>
......@@ -18,6 +19,24 @@
{% crispy form %}
</div>
</div>
</div>
<div class="col-md-5">
<div class="panel panel-default">
<div class="panel-heading">
<h4 class="no-margin"><i class="icon-group"></i> {% trans "Manage access" %}</h4>
</div>
<div class="panel-body">
<form action="{% url "dashboard.views.lease-acl" pk=object.pk %}" method="post">
{% csrf_token %}
{{ lease_roles_form.roles }}
<div class="pull-right" style="margin-top: 20px">
<button type="submit" class="btn btn-success">{% trans "Save" %}</button>
</div>
</form>
</div>
</div>
</div>
</div>
{% endblock %}
......@@ -19,7 +19,8 @@ from __future__ import absolute_import
from dashboard.views.autocomplete import AclUserGroupAutocomplete, AclUserAutocomplete
from dashboard.views.template import TemplateList, TemplateChoose, TemplateDetail, TemplateDelete, \
TransferTemplateOwnershipConfirmView, TransferTemplateOwnershipView, LeaseCreate, LeaseDetail, LeaseDelete
TransferTemplateOwnershipConfirmView, TransferTemplateOwnershipView, LeaseCreate, LeaseDetail, LeaseDelete, \
LeaseAclUpdateView
from dashboard.views.vm import VmDetailView, VmList, VmCreate, vm_activity, vm_ops, FavouriteView, VmPlainImageCreate
from django.conf.urls import url
......@@ -40,8 +41,8 @@ urlpatterns = [
name="dashboard.views.lease-create"),
url(r'^lease/delete/(?P<pk>\d+)/$', LeaseDelete.as_view(),
name="dashboard.views.lease-delete"),
# url(r'^lease/(?P<pk>\d+)/acl/$', LeaseAclUpdateView.as_view(),
# name="dashboard.views.lease-acl"),
url(r'^lease/(?P<pk>\d+)/acl/$', LeaseAclUpdateView.as_view(),
name="dashboard.views.lease-acl"),
#
# url(r'^template/create/$', TemplateCreate.as_view(),
# name="dashboard.views.template-create"),
......
......@@ -20,7 +20,6 @@ from datetime import timedelta
import json
import logging
import openstack_api
from braces.views._access import AccessMixin
from django.contrib import messages
from django.contrib.auth.models import User
......@@ -48,7 +47,7 @@ from storage.models import Disk
from ..forms import (
TemplateForm, TemplateListSearchForm, AclUserOrGroupAddForm, LeaseForm,
)
LeaseRolesForm)
from ..tables import TemplateListTable, LeaseListTable
from .util import (
......@@ -415,8 +414,8 @@ class LeaseCreate(LoginRequiredMixin, PolicyMixin,
return reverse_lazy("dashboard.views.template-list")
# class LeaseAclUpdateView(AclUpdateView):
# model = Lease
class LeaseAclUpdateView(AclUpdateView):
model = Lease
class LeaseDetail(LoginRequiredMixin, PolicyMixin,
......@@ -430,11 +429,21 @@ class LeaseDetail(LoginRequiredMixin, PolicyMixin,
def get_success_url(self):
return reverse_lazy("dashboard.views.lease-detail", kwargs=self.kwargs)
def get_context_data(self, **kwargs):
from openstack_api import keystone
roles = keystone.role_list(self.request)
context = super(LeaseDetail, self).get_context_data(**kwargs)
context.update({
'lease_roles_form': LeaseRolesForm(roles),
})
return context
class LeaseDelete(DeleteViewBase):
model = Lease
success_message = _("Lease successfully deleted.")
os_policy_actions = (("circle", "lease:manage"),)
os_policy_actions = (("circle", "lease:am"),)
def get_success_url(self):
return reverse("dashboard.views.template-list")
......
# -*- coding: utf-8 -*-
# Generated by Django 1.11.6 on 2018-05-18 09:25
from __future__ import unicode_literals
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('vm', '0013_vmlease_suspend_done'),
]
operations = [
migrations.CreateModel(
name='Role',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('role_id', models.CharField(max_length=100, unique=True)),
],
),
migrations.AddField(
model_name='lease',
name='roles_permitted',
field=models.ManyToManyField(blank=True, help_text='Roles permitted to access this lease.', to='vm.Role', verbose_name='roles permitted'),
),
]
......@@ -19,7 +19,7 @@ from __future__ import absolute_import, unicode_literals
from datetime import timedelta, datetime
from django.core.validators import MinValueValidator
from django.db.models import Model, CharField, IntegerField, permalink
from django.db.models import Model, CharField, IntegerField, permalink, ManyToManyField
from django.utils.translation import ugettext_lazy as _
from django.utils.timesince import timeuntil
......@@ -64,6 +64,10 @@ class NamedBaseResourceConfig(BaseResourceConfigModel, TimeStampedModel):
return self.name
class Role(Model):
role_id = CharField(blank=False, max_length=100, unique=True)
class Lease(Model):
"""Lease times for VM instances.
......@@ -81,6 +85,9 @@ class Lease(Model):
verbose_name=_('delete interval'), help_text=_(
'Number of seconds after the an instance is deleted.'),
null=True, blank=True)
roles_permitted = ManyToManyField(Role, blank=True,
help_text=_("Roles permitted to access this lease."),
verbose_name=_('roles permitted'))
class Meta:
app_label = 'vm'
......
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