Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
Gelencsér Szabolcs
/
cloud
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Members
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
1be19049
authored
Apr 24, 2014
by
Kálmán Viktor
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'feature-filter-su-perms' into 'master'
Filter out not owned VM-s for superuser
parents
451790d6
73218bb7
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
19 additions
and
4 deletions
+19
-4
circle/acl/models.py
+4
-3
circle/acl/tests/test_acl.py
+14
-0
circle/dashboard/views.py
+1
-1
No files found.
circle/acl/models.py
View file @
1be19049
...
...
@@ -177,14 +177,15 @@ class AclBase(Model):
@classmethod
def
get_objects_with_level
(
cls
,
level
,
user
,
group_also
=
True
,
owner_also
=
False
):
group_also
=
True
,
owner_also
=
False
,
disregard_superuser
=
False
):
logger
.
debug
(
'
%
s.get_objects_with_level(
%
s,
%
s) called'
,
unicode
(
cls
),
unicode
(
level
),
unicode
(
user
))
if
user
is
None
or
not
user
.
is_authenticated
():
return
cls
.
objects
.
none
()
if
getattr
(
user
,
'is_superuser'
,
False
):
if
getattr
(
user
,
'is_superuser'
,
False
)
and
not
disregard_superuser
:
logger
.
debug
(
'- superuser granted'
)
return
cls
.
objects
return
cls
.
objects
.
all
()
if
isinstance
(
level
,
basestring
):
level
=
cls
.
get_level_object
(
level
)
logger
.
debug
(
"- level set by str:
%
s"
,
unicode
(
level
))
...
...
circle/acl/tests/test_acl.py
View file @
1be19049
...
...
@@ -161,6 +161,20 @@ class AclUserTest(TestCase):
self
.
assertItemsEqual
(
TestModel
.
get_objects_with_level
(
'alfa'
,
self
.
u2
),
[
i2
])
def
test_get_objects_with_level_for_superuser
(
self
):
i1
=
TestModel
.
objects
.
create
(
normal_field
=
'Hello1'
)
i2
=
TestModel
.
objects
.
create
(
normal_field
=
'Hello2'
)
i1
.
set_level
(
self
.
u1
,
'alfa'
)
i2
.
set_level
(
self
.
us
,
'alfa'
)
self
.
assertItemsEqual
(
TestModel
.
get_objects_with_level
(
'alfa'
,
self
.
u1
),
[
i1
])
self
.
assertItemsEqual
(
TestModel
.
get_objects_with_level
(
'alfa'
,
self
.
us
),
[
i1
,
i2
])
self
.
assertItemsEqual
(
TestModel
.
get_objects_with_level
(
'alfa'
,
self
.
us
,
disregard_superuser
=
True
),
[
i2
])
def
test_get_objects_with_level_for_group
(
self
):
i1
=
TestModel
.
objects
.
create
(
normal_field
=
'Hello1'
)
i2
=
TestModel
.
objects
.
create
(
normal_field
=
'Hello2'
)
...
...
circle/dashboard/views.py
View file @
1be19049
...
...
@@ -90,7 +90,7 @@ class IndexView(LoginRequiredMixin, TemplateView):
# instances
favs
=
Instance
.
objects
.
filter
(
favourite__user
=
self
.
request
.
user
)
instances
=
Instance
.
get_objects_with_level
(
'user'
,
user
)
.
filter
(
destroyed_at
=
None
)
'user'
,
user
,
disregard_superuser
=
True
)
.
filter
(
destroyed_at
=
None
)
display
=
list
(
favs
)
+
list
(
set
(
instances
)
-
set
(
favs
))
for
d
in
display
:
d
.
fav
=
True
if
d
in
favs
else
False
...
...
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