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
56ca75ed
Commit
56ca75ed
authored
4 years ago
by
Hangzhi Yu
Browse files
Options
Downloads
Patches
Plain Diff
Add predicate builder for site preferences check
parent
ce3bb7dd
No related branches found
Branches containing commit
No related tags found
Tags containing commit
1 merge request
!246
Resolve "Add predicate that checks for a preference"
Pipeline
#1923
passed with warnings
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
+14
-0
14 additions, 0 deletions
aleksis/core/util/predicates.py
with
14 additions
and
0 deletions
aleksis/core/util/predicates.py
+
14
−
0
View file @
56ca75ed
...
...
@@ -8,6 +8,7 @@ from guardian.shortcuts import get_objects_for_user
from
rules
import
predicate
from
..models
import
Group
from
.core_helpers
import
get_site_preferences
from
.core_helpers
import
has_person
as
has_person_helper
...
...
@@ -66,6 +67,19 @@ def has_any_object(perm: str, klass):
return
fn
def
check_site_preference
(
section
:
str
,
pref
:
str
):
"""
Builds predicate which checks the boolean value of a given site preference
"""
name
=
f
"
check_site_preference:
{
section
}
__
{
pref
}
"
@predicate
(
name
)
def
fn
()
->
bool
:
if
isinstance
(
get_site_preferences
()[
f
"
{
section
}
__
{
pref
}
"
],
bool
):
return
get_site_preferences
()[
f
"
{
section
}
__
{
pref
}
"
]
return
False
return
fn
@predicate
def
has_person
(
user
:
User
)
->
bool
:
"""
Predicate which checks whether a user has a linked person.
"""
...
...
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