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
b8e10415
Verified
Commit
b8e10415
authored
3 years ago
by
Hangzhi Yu
Committed by
Jonathan Weth
3 years ago
Browse files
Options
Downloads
Patches
Plain Diff
Comment has_any_object function
(cherry picked from commit
2894a951
)
parent
1c94bd37
No related branches found
Branches containing commit
No related tags found
Tags containing commit
1 merge request
!697
Prepare release 2.0rc4
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
aleksis/core/util/predicates.py
+5
-0
5 additions, 0 deletions
aleksis/core/util/predicates.py
with
5 additions
and
0 deletions
aleksis/core/util/predicates.py
+
5
−
0
View file @
b8e10415
...
...
@@ -75,14 +75,19 @@ def has_any_object(perm: str, klass):
Build predicate which checks whether a user has access
to objects with the provided permission or rule.
Differentiates between object-related permissions and rules.
"""
name
=
f
"
has_any_object:
{
perm
}
"
@predicate
(
name
)
def
fn
(
user
:
User
)
->
bool
:
ct_perm
=
get_content_type_by_perm
(
perm
)
# In case a object-related permission with the same ContentType class as the given class
# is passed, the optimized django-guardian get_objects_for_user function is used.
if
ct_perm
and
ct_perm
.
model_class
()
==
klass
:
return
get_objects_for_user
(
user
,
perm
,
klass
).
exists
()
# In other cases, it is checked for each object of the given model whether the current user
# fulfills the given rule.
else
:
return
queryset_rules_filter
(
user
,
klass
.
objects
.
all
(),
perm
).
exists
()
...
...
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