Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
Fukász Rómeó Ervin
/
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
90fe50ac
authored
Nov 13, 2013
by
Őry Máté
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
acl: add AclBase.set_level(whom, None)
parent
c616998b
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
37 additions
and
15 deletions
+37
-15
circle/acl/models.py
+23
-15
circle/acl/tests/test_acl.py
+14
-0
No files found.
circle/acl/models.py
View file @
90fe50ac
...
@@ -67,8 +67,8 @@ class AclBase(Model):
...
@@ -67,8 +67,8 @@ class AclBase(Model):
:param whom: user or group the level is set for
:param whom: user or group the level is set for
:type whom: User or Group
:type whom: User or Group
:param level: codename of level to set
:param level: codename of level to set
, or None
:type level: Level or str or unicode
:type level: Level or str or unicode
or NoneType
"""
"""
if
isinstance
(
whom
,
User
):
if
isinstance
(
whom
,
User
):
self
.
set_user_level
(
whom
,
level
)
self
.
set_user_level
(
whom
,
level
)
...
@@ -83,17 +83,21 @@ class AclBase(Model):
...
@@ -83,17 +83,21 @@ class AclBase(Model):
:param whom: user the level is set for
:param whom: user the level is set for
:type whom: User
:type whom: User
:param level: codename of level to set
:param level: codename of level to set
, or None
:type level: Level or str or unicode
:type level: Level or str or unicode
or NoneType
"""
"""
logger
.
info
(
'
%
s.set_user_level(
%
s,
%
s) called'
,
logger
.
info
(
'
%
s.set_user_level(
%
s,
%
s) called'
,
*
[
unicode
(
p
)
for
p
in
[
self
,
user
,
level
]])
*
[
unicode
(
p
)
for
p
in
[
self
,
user
,
level
]])
if
isinstance
(
level
,
basestring
):
if
level
is
None
:
level
=
self
.
get_level_object
(
level
)
pk
=
None
if
not
self
.
object_level_set
.
filter
(
level_id
=
level
.
pk
)
.
exists
():
else
:
self
.
object_level_set
.
create
(
level
=
level
)
if
isinstance
(
level
,
basestring
):
level
=
self
.
get_level_object
(
level
)
if
not
self
.
object_level_set
.
filter
(
level_id
=
level
.
pk
)
.
exists
():
self
.
object_level_set
.
create
(
level
=
level
)
pk
=
level
.
pk
for
i
in
self
.
object_level_set
.
all
():
for
i
in
self
.
object_level_set
.
all
():
if
i
.
level_id
!=
level
.
pk
:
if
i
.
level_id
!=
pk
:
i
.
users
.
remove
(
user
)
i
.
users
.
remove
(
user
)
else
:
else
:
i
.
users
.
add
(
user
)
i
.
users
.
add
(
user
)
...
@@ -110,13 +114,17 @@ class AclBase(Model):
...
@@ -110,13 +114,17 @@ class AclBase(Model):
"""
"""
logger
.
info
(
'
%
s.set_group_level(
%
s,
%
s) called'
,
logger
.
info
(
'
%
s.set_group_level(
%
s,
%
s) called'
,
*
[
unicode
(
p
)
for
p
in
[
self
,
group
,
level
]])
*
[
unicode
(
p
)
for
p
in
[
self
,
group
,
level
]])
if
isinstance
(
level
,
basestring
):
if
level
is
None
:
level
=
self
.
get_level_object
(
level
)
pk
=
None
#self.object_level_set.get_or_create(level=level, content_object=self)
else
:
if
not
self
.
object_level_set
.
filter
(
level_id
=
level
.
pk
)
.
exists
():
if
isinstance
(
level
,
basestring
):
self
.
object_level_set
.
create
(
level
=
level
)
level
=
self
.
get_level_object
(
level
)
#self.object_level_set.get_or_create(level=level, content_object=self)
if
not
self
.
object_level_set
.
filter
(
level_id
=
level
.
pk
)
.
exists
():
self
.
object_level_set
.
create
(
level
=
level
)
pk
=
level
.
pk
for
i
in
self
.
object_level_set
.
all
():
for
i
in
self
.
object_level_set
.
all
():
if
i
.
level_id
!=
level
.
pk
:
if
i
.
level_id
!=
pk
:
i
.
groups
.
remove
(
group
)
i
.
groups
.
remove
(
group
)
else
:
else
:
i
.
groups
.
add
(
group
)
i
.
groups
.
add
(
group
)
...
...
circle/acl/tests/test_acl.py
View file @
90fe50ac
...
@@ -133,3 +133,17 @@ class AclUserTest(TestCase):
...
@@ -133,3 +133,17 @@ class AclUserTest(TestCase):
i1
=
TestModel
.
objects
.
create
(
normal_field
=
'Hello'
)
i1
=
TestModel
.
objects
.
create
(
normal_field
=
'Hello'
)
i1
.
set_level
(
self
.
g1
,
'bravo'
)
i1
.
set_level
(
self
.
g1
,
'bravo'
)
unicode
(
ObjectLevel
.
objects
.
all
()[
0
])
unicode
(
ObjectLevel
.
objects
.
all
()[
0
])
def
test_set_user_level_none
(
self
):
i
=
TestModel
.
objects
.
create
(
normal_field
=
'Hello'
)
i
.
set_level
(
self
.
u1
,
'alfa'
)
self
.
assertTrue
(
i
.
has_level
(
self
.
u1
,
'alfa'
))
i
.
set_level
(
self
.
u1
,
None
)
self
.
assertFalse
(
i
.
has_level
(
self
.
u1
,
'alfa'
))
def
test_set_group_level_none
(
self
):
i
=
TestModel
.
objects
.
create
(
normal_field
=
'Hello'
)
i
.
set_level
(
self
.
g1
,
'alfa'
)
self
.
assertTrue
(
i
.
has_level
(
self
.
u1
,
'alfa'
))
i
.
set_level
(
self
.
g1
,
None
)
self
.
assertFalse
(
i
.
has_level
(
self
.
u1
,
'alfa'
))
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