From c5bd3d138e5889d9012b30e9bfb81629e6ef2e5a Mon Sep 17 00:00:00 2001 From: Cian Hughes Date: Tue, 3 Jun 2025 11:07:35 +0100 Subject: [PATCH] Attempt to fix loading issues when oauth is not responding --- invenio_theme_iform/__about__.py | 2 +- invenio_theme_iform/ext.py | 12 +++++++++++- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/invenio_theme_iform/__about__.py b/invenio_theme_iform/__about__.py index dbb0982..435fb8b 100644 --- a/invenio_theme_iform/__about__.py +++ b/invenio_theme_iform/__about__.py @@ -8,4 +8,4 @@ """Metadata for this python module.""" -__version__ = "2025.5.20.8" +__version__ = "2025.6.3" diff --git a/invenio_theme_iform/ext.py b/invenio_theme_iform/ext.py index 621c164..fd82868 100644 --- a/invenio_theme_iform/ext.py +++ b/invenio_theme_iform/ext.py @@ -8,6 +8,7 @@ """invenio module for I-Form theme.""" +from flask import g, has_request_context from flask_login import login_required from invenio_records_marc21.ui.theme import current_identity_can_view @@ -34,7 +35,16 @@ class InvenioThemeIform(object): @app.context_processor def inject_visibility(): - return {"can_view_marc21": current_identity_can_view()} + def can_view_marc21(): + try: + # Only check if we're in a request context and identity exists + if has_request_context() and hasattr(g, "identity") and g.identity: + return current_identity_can_view() + return False + except (AttributeError, RuntimeError): + return False + + return {"can_view_marc21": can_view_marc21()} app.extensions["invenio-theme-iform"] = self