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
c5b84d2d
authored
Jan 15, 2014
by
Őry Máté
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
acl: add get_objects_with_group_level
parent
6f0adf06
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
28 additions
and
1 deletions
+28
-1
circle/acl/models.py
+12
-0
circle/acl/tests/models.py
+3
-1
circle/acl/tests/test_acl.py
+13
-0
No files found.
circle/acl/models.py
View file @
c5b84d2d
...
...
@@ -201,5 +201,17 @@ class AclBase(Model):
clsfilter
|=
Q
(
owner
=
user
)
return
cls
.
objects
.
filter
(
clsfilter
)
@classmethod
def
get_objects_with_group_level
(
cls
,
level
,
group
):
if
isinstance
(
level
,
basestring
):
level
=
cls
.
get_level_object
(
level
)
ct
=
ContentType
.
objects
.
get_for_model
(
cls
)
levelfilter
=
Q
(
groups
=
group
)
ols
=
ObjectLevel
.
objects
.
filter
(
levelfilter
,
content_type
=
ct
,
level__weight__gte
=
level
.
weight
)
.
distinct
()
clsfilter
=
Q
(
object_level_set__in
=
ols
.
all
())
return
cls
.
objects
.
filter
(
clsfilter
)
class
Meta
:
abstract
=
True
circle/acl/tests/models.py
View file @
c5b84d2d
from
django.db.models
import
TextField
from
django.db.models
import
TextField
,
ForeignKey
from
django.contrib.auth.models
import
User
from
..models
import
AclBase
...
...
@@ -15,6 +16,7 @@ class TestModel(AclBase):
class
Test2Model
(
AclBase
):
normal2_field
=
TextField
()
owner
=
ForeignKey
(
User
)
ACL_LEVELS
=
(
(
'one'
,
'One'
),
...
...
circle/acl/tests/test_acl.py
View file @
c5b84d2d
...
...
@@ -14,6 +14,8 @@ class AclUserTest(TestCase):
self
.
g1
.
user_set
.
add
(
self
.
u1
)
self
.
g1
.
user_set
.
add
(
self
.
u2
)
self
.
g1
.
save
()
self
.
g2
=
Group
.
objects
.
create
(
name
=
'group2'
)
self
.
g2
.
save
()
def
test_level_exists
(
self
):
for
codename
,
name
in
TestModel
.
ACL_LEVELS
:
...
...
@@ -147,3 +149,14 @@ class AclUserTest(TestCase):
self
.
assertTrue
(
i
.
has_level
(
self
.
u1
,
'alfa'
))
i
.
set_level
(
self
.
g1
,
None
)
self
.
assertFalse
(
i
.
has_level
(
self
.
u1
,
'alfa'
))
def
test_get_objects_with_group_level
(
self
):
i1
=
TestModel
.
objects
.
create
(
normal_field
=
'Hello1'
)
i2
=
TestModel
.
objects
.
create
(
normal_field
=
'Hello2'
)
i1
.
set_level
(
self
.
g1
,
'alfa'
)
i2
.
set_level
(
self
.
g1
,
'bravo'
)
i2
.
set_level
(
self
.
g2
,
'bravo'
)
self
.
assertItemsEqual
(
TestModel
.
get_objects_with_group_level
(
'alfa'
,
self
.
g1
),
[
i1
,
i2
])
self
.
assertItemsEqual
(
TestModel
.
get_objects_with_group_level
(
'alfa'
,
self
.
g2
),
[
i2
])
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