Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
CIRCLE
/
cloud
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
94
Merge Requests
10
Pipelines
Wiki
Snippets
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):
:param whom: user or group the level is set for
:type whom: User or Group
:param level: codename of level to set
:type level: Level or str or unicode
:param level: codename of level to set
, or None
:type level: Level or str or unicode
or NoneType
"""
if
isinstance
(
whom
,
User
):
self
.
set_user_level
(
whom
,
level
)
...
...
@@ -83,17 +83,21 @@ class AclBase(Model):
:param whom: user the level is set for
:type whom: User
:param level: codename of level to set
:type level: Level or str or unicode
:param level: codename of level to set
, or None
:type level: Level or str or unicode
or NoneType
"""
logger
.
info
(
'
%
s.set_user_level(
%
s,
%
s) called'
,
*
[
unicode
(
p
)
for
p
in
[
self
,
user
,
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
)
if
level
is
None
:
pk
=
None
else
:
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
():
if
i
.
level_id
!=
level
.
pk
:
if
i
.
level_id
!=
pk
:
i
.
users
.
remove
(
user
)
else
:
i
.
users
.
add
(
user
)
...
...
@@ -110,13 +114,17 @@ class AclBase(Model):
"""
logger
.
info
(
'
%
s.set_group_level(
%
s,
%
s) called'
,
*
[
unicode
(
p
)
for
p
in
[
self
,
group
,
level
]])
if
isinstance
(
level
,
basestring
):
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
)
if
level
is
None
:
pk
=
None
else
:
if
isinstance
(
level
,
basestring
):
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
():
if
i
.
level_id
!=
level
.
pk
:
if
i
.
level_id
!=
pk
:
i
.
groups
.
remove
(
group
)
else
:
i
.
groups
.
add
(
group
)
...
...
circle/acl/tests/test_acl.py
View file @
90fe50ac
...
...
@@ -133,3 +133,17 @@ class AclUserTest(TestCase):
i1
=
TestModel
.
objects
.
create
(
normal_field
=
'Hello'
)
i1
.
set_level
(
self
.
g1
,
'bravo'
)
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