Skip to content
Snippets Groups Projects
Commit 56ca75ed authored by Hangzhi Yu's avatar Hangzhi Yu
Browse files

Add predicate builder for site preferences check

parent ce3bb7dd
No related branches found
No related tags found
1 merge request!246Resolve "Add predicate that checks for a preference"
Pipeline #1923 passed with warnings
......@@ -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."""
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment