From 7a75a399ceae6a51912e99381185535174577229 Mon Sep 17 00:00:00 2001 From: Steve Eardley Date: Wed, 3 Jan 2024 12:43:57 +0000 Subject: [PATCH 1/2] show errors in cms data to admins --- portality/core.py | 17 +++++++++++++---- portality/templates/layouts/static_page.html | 17 +++++++++++++++++ 2 files changed, 30 insertions(+), 4 deletions(-) diff --git a/portality/core.py b/portality/core.py index c74493a9a0..18b11916ee 100644 --- a/portality/core.py +++ b/portality/core.py @@ -314,10 +314,19 @@ def _load_data(app): datadir = os.path.join(app.config["BASE_FILE_PATH"], "..", "cms", "data") for datafile in os.listdir(datadir): with open(os.path.join(datadir, datafile)) as f: - data = yaml.load(f, Loader=yaml.FullLoader) - dataname = datafile.split(".")[0] - dataname = dataname.replace("-", "_") - app.jinja_env.globals["data"][dataname] = data + + dataname = datafile.split(".")[0] + dataname = dataname.replace("-", "_") + + try: + data = yaml.load(f, Loader=yaml.FullLoader) + app.jinja_env.globals["data"][dataname] = data + except yaml.error.MarkedYAMLError as e: + app.logger.error(e) + # Problem with loading our yaml - this should be reported to the frontend to allow admins to fix + if not "data_errors" in app.jinja_env.globals: + app.jinja_env.globals["data_errors"] = {} + app.jinja_env.globals["data_errors"][dataname] = e ################################################## diff --git a/portality/templates/layouts/static_page.html b/portality/templates/layouts/static_page.html index c6012b4b58..8b5bb00ee4 100644 --- a/portality/templates/layouts/static_page.html +++ b/portality/templates/layouts/static_page.html @@ -20,6 +20,23 @@ {% if page.preface and page.preface.startswith("/data/") %} Edit data content {% endif %} + + {# Admins will also be interested in any data errors - dump them out on the page here #} + {# FIXME: This is probably an even worse way to find data than the method above! #} + {% set datakey = page_frag.split('/')[2].split('.')[0] %} + {% if data_errors.get(datakey) %} +
+
+

Notifications

+

+ + DATA ERROR: {{ data_errors.get(datakey) }} + (Dismiss) +

+
+
+ {% endif %} + {% endif %} {% if page.layout %} From 92a3f3b87686f824ab1e0cf35442156b3c428057 Mon Sep 17 00:00:00 2001 From: Steven Eardley Date: Mon, 22 Jan 2024 16:44:27 +0000 Subject: [PATCH 2/2] Config key to show / hide CMS errors --- portality/core.py | 9 +++++---- portality/settings.py | 3 +++ test.cfg | 2 ++ 3 files changed, 10 insertions(+), 4 deletions(-) diff --git a/portality/core.py b/portality/core.py index 18b11916ee..965bcfee83 100644 --- a/portality/core.py +++ b/portality/core.py @@ -323,10 +323,11 @@ def _load_data(app): app.jinja_env.globals["data"][dataname] = data except yaml.error.MarkedYAMLError as e: app.logger.error(e) - # Problem with loading our yaml - this should be reported to the frontend to allow admins to fix - if not "data_errors" in app.jinja_env.globals: - app.jinja_env.globals["data_errors"] = {} - app.jinja_env.globals["data_errors"][dataname] = e + if app.config.get("SHOW_ADMIN_PAGE_ERRORS", False): + # Problem with loading our yaml - this should be reported to the frontend to allow admins to fix + if "data_errors" not in app.jinja_env.globals: + app.jinja_env.globals["data_errors"] = {} + app.jinja_env.globals["data_errors"][dataname] = e ################################################## diff --git a/portality/settings.py b/portality/settings.py index 636c4a5526..25dfacfd3c 100644 --- a/portality/settings.py +++ b/portality/settings.py @@ -248,6 +248,9 @@ # http://flask.pocoo.org/snippets/102/ STATIC_DIR = os.path.join(ROOT_DIR, "portality", "static") +# Display pop-up notification to admins on the template when there are CMS page errors (for static pages server) +SHOW_ADMIN_PAGE_ERRORS = False + ###################################### # Service Descriptive Text diff --git a/test.cfg b/test.cfg index 7bcd545b85..93e2a1a57b 100644 --- a/test.cfg +++ b/test.cfg @@ -76,6 +76,8 @@ PLAUSIBLE_URL = None # Testdrive enabled TESTDRIVE_ENABLED = True +# Show CMS errors (notification to admins) +SHOW_ADMIN_PAGE_ERRORS = True # ======================= # Selenium test settings