Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
Gelencsér Szabolcs
/
circlestack
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Members
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
bdcb0d24
authored
May 18, 2018
by
Szabolcs Gelencser
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
To try changes on production env
parent
19d074a6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
100 additions
and
18 deletions
+100
-18
circle/dashboard/forms.py
+19
-0
circle/dashboard/templates/dashboard/lease-edit.html
+28
-9
circle/dashboard/urls.py
+4
-3
circle/dashboard/views/template.py
+14
-5
circle/vm/migrations/0014_auto_20180518_1125.py
+27
-0
circle/vm/models/common.py
+8
-1
No files found.
circle/dashboard/forms.py
View file @
bdcb0d24
...
...
@@ -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
):
...
...
circle/dashboard/templates/dashboard/lease-edit.html
View file @
bdcb0d24
...
...
@@ -6,16 +6,35 @@
{% block content %}
<div
class=
"row"
>
<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>
<h3
class=
"no-margin"
><i
class=
"fa fa-clock-o"
></i>
{% trans "Edit lease" %}
</h3>
<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>
<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
class=
"panel-body"
>
{% with form=form %}
{% include "display-form-errors.html" %}
{% endwith %}
{% crispy form %}
</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>
...
...
circle/dashboard/urls.py
View file @
bdcb0d24
...
...
@@ -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"),
...
...
circle/dashboard/views/template.py
View file @
bdcb0d24
...
...
@@ -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"
)
...
...
circle/vm/migrations/0014_auto_20180518_1125.py
0 → 100644
View file @
bdcb0d24
# -*- 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'
),
),
]
circle/vm/models/common.py
View file @
bdcb0d24
...
...
@@ -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'
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment