73116b9d1a
* policies/expression: migrate to raw python instead of jinja2 * lib/expression: create base evaluator, custom subclass for policies * core: rewrite propertymappings to use python * providers/saml: update to new PropertyMappings * sources/ldap: update to new PropertyMappings * docs: update docs for new propertymappings * root: remove jinja2 * root: re-add jinja to lock file as its implicitly required
22 lines
661 B
Python
22 lines
661 B
Python
"""Property Mapping Evaluator"""
|
|
from typing import Optional
|
|
|
|
from django.http import HttpRequest
|
|
|
|
from passbook.core.models import User
|
|
from passbook.lib.expression.evaluator import BaseEvaluator
|
|
|
|
|
|
class PropertyMappingEvaluator(BaseEvaluator):
|
|
"""Custom Evalautor that adds some different context variables."""
|
|
|
|
def set_context(
|
|
self, user: Optional[User], request: Optional[HttpRequest], **kwargs
|
|
):
|
|
"""Update context with context from PropertyMapping's evaluate"""
|
|
if user:
|
|
self._context["user"] = user
|
|
if request:
|
|
self._context["request"] = request
|
|
self._context.update(**kwargs)
|