From 7482d958add16be5b50ef1ec3001a6dc36b8f51a Mon Sep 17 00:00:00 2001 From: Miroslav Bauer Date: Fri, 1 Mar 2024 14:38:44 +0100 Subject: [PATCH] fix(jinjax): refresh jinjax global env after user logs in or out --- oarepo_ui/ext.py | 10 ++++++++++ oarepo_ui/signals.py | 4 ++++ 2 files changed, 14 insertions(+) create mode 100644 oarepo_ui/signals.py diff --git a/oarepo_ui/ext.py b/oarepo_ui/ext.py index 6a06de0b..a3023b35 100644 --- a/oarepo_ui/ext.py +++ b/oarepo_ui/ext.py @@ -6,6 +6,8 @@ from flask import Response, current_app from invenio_base.utils import obj_or_import_string +from flask_login import user_logged_in, user_logged_out +from .signals import handle_user_change import oarepo_ui.cli # noqa from oarepo_ui.resources.templating.catalog import OarepoCatalog as Catalog @@ -90,6 +92,7 @@ def __init__(self, app=None): def init_app(self, app): self.init_config(app) + self.connect_signals(app) app.extensions["oarepo_ui"] = OARepoUIState(app) def init_config(self, app): @@ -105,3 +108,10 @@ def init_config(self, app): for name, val in getattr(config, k).items(): if name not in app.config[k]: app.config[k][name] = val + + + + def connect_signals(self, app): + """Register signal handlers.""" + user_logged_in.connect(handle_user_change, app) + user_logged_out.connect(handle_user_change, app) diff --git a/oarepo_ui/signals.py b/oarepo_ui/signals.py new file mode 100644 index 00000000..daf524d0 --- /dev/null +++ b/oarepo_ui/signals.py @@ -0,0 +1,4 @@ +from .proxies import current_oarepo_ui + +def handle_user_change(app, user): + current_oarepo_ui.reinitialize_catalog() \ No newline at end of file