Files

20 lines
378 B
Python
Raw Permalink Normal View History

2026-06-27 19:08:48 +08:00
from contextlib import contextmanager
from threading import local
_state = local()
def get_current_actor():
return getattr(_state, "actor", None)
@contextmanager
def audit_actor(actor):
previous = get_current_actor()
_state.actor = actor if getattr(actor, "is_authenticated", True) else None
try:
yield
finally:
_state.actor = previous