Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
A
AlekSIS-Core
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Terraform modules
Monitor
Service Desk
Analyze
Contributor analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
AlekSIS®
Official
AlekSIS-Core
Commits
4cbdb5f9
Commit
4cbdb5f9
authored
4 years ago
by
Hangzhi Yu
Browse files
Options
Downloads
Patches
Plain Diff
Fixed content type bug
parent
3302dfad
No related branches found
Branches containing commit
No related tags found
Tags containing commit
1 merge request
!318
Resolve "Add helper function to filter a queryset by a rule"
Pipeline
#3134
failed
4 years ago
Stage: test
Stage: build
Changes
1
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
aleksis/core/util/predicates.py
+7
-6
7 additions, 6 deletions
aleksis/core/util/predicates.py
with
7 additions
and
6 deletions
aleksis/core/util/predicates.py
+
7
−
6
View file @
4cbdb5f9
from
django.contrib.auth.backends
import
ModelBackend
from
django.contrib.auth.models
import
User
from
django.contrib.contenttypes.models
import
ContentType
from
django.db.models
import
Model
from
django.http
import
HttpRequest
...
...
@@ -57,17 +58,17 @@ def has_any_object(perm: str, klass):
"""
Check if has any object.
Build predicate which checks whether a user has access
to objects with the provided permission.
to objects with the provided permission
or rule
.
"""
name
=
f
"
has_any_object:
{
perm
}
"
@predicate
(
name
)
def
fn
(
user
:
User
)
->
bool
:
return
(
get_objects_for_user
(
user
,
perm
,
klass
).
exists
()
or
queryset_rules_filter
(
user
,
klass
.
objects
.
all
(),
perm
).
exists
()
)
ct_perm
=
ContentType
.
objects
.
get
(
app_label
=
perm
.
split
(
'
.
'
,
1
)[
0
],
permission__codename
=
perm
.
split
(
'
.
'
,
1
)[
1
])
if
ct_perm
and
ct_perm
.
model_class
()
==
klass
:
return
get_objects_for_user
(
user
,
perm
,
klass
).
exists
()
else
:
return
queryset_rules_filter
(
user
,
klass
.
objects
.
all
(),
perm
).
exists
()
return
fn
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment