Commit bdcb0d24 by Szabolcs Gelencser

To try changes on production env

parent 19d074a6
...@@ -58,6 +58,8 @@ from vm.models import ( ...@@ -58,6 +58,8 @@ from vm.models import (
from storage.models import DataStore, Disk from storage.models import DataStore, Disk
from django.contrib.admin.widgets import FilteredSelectMultiple from django.contrib.admin.widgets import FilteredSelectMultiple
from django.contrib.auth.models import Permission from django.contrib.auth.models import Permission
from vm.models.common import Role
from .models import Profile, GroupProfile, Message from .models import Profile, GroupProfile, Message
from circle.settings.base import LANGUAGES, MAX_NODE_RAM from circle.settings.base import LANGUAGES, MAX_NODE_RAM
from django.utils.translation import string_concat from django.utils.translation import string_concat
...@@ -555,6 +557,23 @@ class TemplateForm(forms.ModelForm): ...@@ -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): class LeaseForm(forms.ModelForm):
def __init__(self, *args, **kwargs): def __init__(self, *args, **kwargs):
......
...@@ -6,16 +6,35 @@ ...@@ -6,16 +6,35 @@
{% block content %} {% block content %}
<div class="row"> <div class="row">
<div class="panel panel-default"> <div class="col-md-7">
<div class="panel-heading"> <div class="panel panel-default">
<a class="pull-right btn btn-default btn-xs" href="{% url "dashboard.views.template-list" %}">{% trans "Back" %}</a> <div class="panel-heading">
<h3 class="no-margin"><i class="fa fa-clock-o"></i> {% trans "Edit lease" %}</h3> <a class="pull-right btn btn-default btn-xs" href="{% url "dashboard.views.template-list" %}">{% trans "Back" %}</a>
<h3 class="no-margin"><i class="fa fa-clock-o"></i> {% trans "Edit lease" %}</h3>
</div>
<div class="panel-body">
{% with form=form %}
{% include "display-form-errors.html" %}
{% endwith %}
{% crispy form %}
</div>
</div> </div>
<div class="panel-body"> </div>
{% with form=form %}
{% include "display-form-errors.html" %} <div class="col-md-5">
{% endwith %} <div class="panel panel-default">
{% crispy form %} <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> </div>
</div> </div>
......
...@@ -19,7 +19,8 @@ from __future__ import absolute_import ...@@ -19,7 +19,8 @@ from __future__ import absolute_import
from dashboard.views.autocomplete import AclUserGroupAutocomplete, AclUserAutocomplete from dashboard.views.autocomplete import AclUserGroupAutocomplete, AclUserAutocomplete
from dashboard.views.template import TemplateList, TemplateChoose, TemplateDetail, TemplateDelete, \ 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 dashboard.views.vm import VmDetailView, VmList, VmCreate, vm_activity, vm_ops, FavouriteView, VmPlainImageCreate
from django.conf.urls import url from django.conf.urls import url
...@@ -40,8 +41,8 @@ urlpatterns = [ ...@@ -40,8 +41,8 @@ urlpatterns = [
name="dashboard.views.lease-create"), name="dashboard.views.lease-create"),
url(r'^lease/delete/(?P<pk>\d+)/$', LeaseDelete.as_view(), url(r'^lease/delete/(?P<pk>\d+)/$', LeaseDelete.as_view(),
name="dashboard.views.lease-delete"), name="dashboard.views.lease-delete"),
# url(r'^lease/(?P<pk>\d+)/acl/$', LeaseAclUpdateView.as_view(), url(r'^lease/(?P<pk>\d+)/acl/$', LeaseAclUpdateView.as_view(),
# name="dashboard.views.lease-acl"), name="dashboard.views.lease-acl"),
# #
# url(r'^template/create/$', TemplateCreate.as_view(), # url(r'^template/create/$', TemplateCreate.as_view(),
# name="dashboard.views.template-create"), # name="dashboard.views.template-create"),
......
...@@ -20,7 +20,6 @@ from datetime import timedelta ...@@ -20,7 +20,6 @@ from datetime import timedelta
import json import json
import logging import logging
import openstack_api
from braces.views._access import AccessMixin from braces.views._access import AccessMixin
from django.contrib import messages from django.contrib import messages
from django.contrib.auth.models import User from django.contrib.auth.models import User
...@@ -48,7 +47,7 @@ from storage.models import Disk ...@@ -48,7 +47,7 @@ from storage.models import Disk
from ..forms import ( from ..forms import (
TemplateForm, TemplateListSearchForm, AclUserOrGroupAddForm, LeaseForm, TemplateForm, TemplateListSearchForm, AclUserOrGroupAddForm, LeaseForm,
) LeaseRolesForm)
from ..tables import TemplateListTable, LeaseListTable from ..tables import TemplateListTable, LeaseListTable
from .util import ( from .util import (
...@@ -415,8 +414,8 @@ class LeaseCreate(LoginRequiredMixin, PolicyMixin, ...@@ -415,8 +414,8 @@ class LeaseCreate(LoginRequiredMixin, PolicyMixin,
return reverse_lazy("dashboard.views.template-list") return reverse_lazy("dashboard.views.template-list")
# class LeaseAclUpdateView(AclUpdateView): class LeaseAclUpdateView(AclUpdateView):
# model = Lease model = Lease
class LeaseDetail(LoginRequiredMixin, PolicyMixin, class LeaseDetail(LoginRequiredMixin, PolicyMixin,
...@@ -430,11 +429,21 @@ class LeaseDetail(LoginRequiredMixin, PolicyMixin, ...@@ -430,11 +429,21 @@ class LeaseDetail(LoginRequiredMixin, PolicyMixin,
def get_success_url(self): def get_success_url(self):
return reverse_lazy("dashboard.views.lease-detail", kwargs=self.kwargs) 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): class LeaseDelete(DeleteViewBase):
model = Lease model = Lease
success_message = _("Lease successfully deleted.") success_message = _("Lease successfully deleted.")
os_policy_actions = (("circle", "lease:manage"),) os_policy_actions = (("circle", "lease:am"),)
def get_success_url(self): def get_success_url(self):
return reverse("dashboard.views.template-list") 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 ...@@ -19,7 +19,7 @@ from __future__ import absolute_import, unicode_literals
from datetime import timedelta, datetime from datetime import timedelta, datetime
from django.core.validators import MinValueValidator 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.translation import ugettext_lazy as _
from django.utils.timesince import timeuntil from django.utils.timesince import timeuntil
...@@ -64,6 +64,10 @@ class NamedBaseResourceConfig(BaseResourceConfigModel, TimeStampedModel): ...@@ -64,6 +64,10 @@ class NamedBaseResourceConfig(BaseResourceConfigModel, TimeStampedModel):
return self.name return self.name
class Role(Model):
role_id = CharField(blank=False, max_length=100, unique=True)
class Lease(Model): class Lease(Model):
"""Lease times for VM instances. """Lease times for VM instances.
...@@ -81,6 +85,9 @@ class Lease(Model): ...@@ -81,6 +85,9 @@ class Lease(Model):
verbose_name=_('delete interval'), help_text=_( verbose_name=_('delete interval'), help_text=_(
'Number of seconds after the an instance is deleted.'), 'Number of seconds after the an instance is deleted.'),
null=True, blank=True) null=True, blank=True)
roles_permitted = ManyToManyField(Role, blank=True,
help_text=_("Roles permitted to access this lease."),
verbose_name=_('roles permitted'))
class Meta: class Meta:
app_label = 'vm' 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