Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
Gyuricska Milán
/
cloud
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
8dfcbde6
authored
Oct 04, 2013
by
Őry Máté
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
dashboard: make acl form work (no error handling)
parent
984e705c
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
53 additions
and
7 deletions
+53
-7
circle/dashboard/views.py
+53
-7
No files found.
circle/dashboard/views.py
View file @
8dfcbde6
import
re
from
django.contrib.auth.models
import
User
,
Group
from
django.core
import
signing
from
django.core
import
signing
from
django.http
import
HttpResponse
from
django.shortcuts
import
redirect
from
django.utils.translation
import
ugettext_lazy
as
_
from
django.views.generic
import
TemplateView
,
DetailView
,
UpdateView
from
django.views.generic
import
TemplateView
,
DetailView
from
django_tables2
import
SingleTableView
from
django_tables2
import
SingleTableView
from
guardian.shortcuts
import
(
get_users_with_perms
,
get_groups_with_perms
,
from
guardian.shortcuts
import
(
get_users_with_perms
,
get_groups_with_perms
,
get_perms
)
get_perms
,
remove_perm
,
assign_perm
)
from
tables
import
VmListTable
from
vm.models
import
Instance
from
vm.models
import
Instance
...
@@ -29,6 +30,20 @@ class IndexView(TemplateView):
...
@@ -29,6 +30,20 @@ class IndexView(TemplateView):
return
context
return
context
def
split
(
t
,
at
):
"""
Split collection at first occurance of given element.
>>> split("FooBar", "B")
('Foo', 'Bar')
>>> split(range(5), 2)
([0, 1], [2, 3, 4])
"""
pos
=
t
.
index
(
at
)
return
t
[:
pos
],
t
[
pos
:]
def
first_common_element
(
a
,
b
):
def
first_common_element
(
a
,
b
):
for
i
in
a
:
for
i
in
a
:
if
i
in
b
:
if
i
in
b
:
...
@@ -51,12 +66,22 @@ def get_acl_data(obj):
...
@@ -51,12 +66,22 @@ def get_acl_data(obj):
'url'
:
obj
.
get_absolute_url
()}
'url'
:
obj
.
get_absolute_url
()}
class
VmDetailView
(
DetailView
):
def
set_acl_level
(
obj
,
whom
,
level
):
levels
=
obj
.
_meta
.
permissions
levelids
=
[
id
for
(
id
,
name
)
in
levels
]
to_remove
,
to_add
=
split
(
levelids
,
level
)
for
p
in
to_remove
:
remove_perm
(
p
,
whom
,
obj
)
for
p
in
to_add
:
assign_perm
(
p
,
whom
,
obj
)
class
VmDetailView
(
UpdateView
):
template_name
=
"dashboard/vm-detail.html"
template_name
=
"dashboard/vm-detail.html"
queryset
=
Instance
.
objects
.
all
()
queryset
=
Instance
.
objects
.
all
()
def
get_context_data
(
self
,
**
kwargs
):
def
get_context_data
(
self
,
**
kwargs
):
context
=
super
(
DetailView
,
self
)
.
get_context_data
(
**
kwargs
)
context
=
super
(
Vm
DetailView
,
self
)
.
get_context_data
(
**
kwargs
)
instance
=
context
[
'instance'
]
instance
=
context
[
'instance'
]
if
instance
.
node
:
if
instance
.
node
:
port
=
instance
.
vnc_port
port
=
instance
.
vnc_port
...
@@ -69,6 +94,27 @@ class VmDetailView(DetailView):
...
@@ -69,6 +94,27 @@ class VmDetailView(DetailView):
context
[
'acl'
]
=
get_acl_data
(
instance
)
context
[
'acl'
]
=
get_acl_data
(
instance
)
return
context
return
context
def
post
(
self
,
request
,
*
args
,
**
kwargs
):
super
(
VmDetailView
,
self
)
.
post
(
request
,
*
args
,
**
kwargs
)
context
=
self
.
get_context_data
(
**
kwargs
)
instance
=
context
[
'instance'
]
for
key
,
value
in
request
.
POST
.
items
():
m
=
re
.
match
(
'perm-([ug])-(
\
d+)'
,
key
)
if
m
:
type
,
id
=
m
.
groups
()
entity
=
{
'u'
:
User
,
'g'
:
Group
}[
type
]
.
objects
.
get
(
id
=
id
)
set_acl_level
(
instance
,
entity
,
value
)
name
=
request
.
POST
[
'perm-new-name'
]
value
=
request
.
POST
[
'perm-new'
]
if
name
:
try
:
entity
=
User
.
objects
.
get
(
username
=
name
)
except
User
.
DoesNotExist
:
entity
=
Group
.
objects
.
get
(
name
=
name
)
set_acl_level
(
instance
,
entity
,
value
)
return
redirect
(
instance
)
class
VmList
(
SingleTableView
):
class
VmList
(
SingleTableView
):
template_name
=
"dashboard/vm-list.html"
template_name
=
"dashboard/vm-list.html"
...
...
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