Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

show errors in cms data to admins #2336

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 14 additions & 4 deletions portality/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -314,10 +314,20 @@ 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)
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


##################################################
Expand Down
3 changes: 3 additions & 0 deletions portality/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
17 changes: 17 additions & 0 deletions portality/templates/layouts/static_page.html
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,23 @@
{% if page.preface and page.preface.startswith("/data/") %}
<a class="admin-edit" href="{{ config.get("CMS_EDIT_BASE_URL") }}{{ page.preface.split(".")|first }}.yml" target="_blank" rel="noopener"><span class="sr-only">Edit data content</span><span data-feather="database" aria-hidden="true"></span></a>
{% 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) %}
<div class="container">
<div class="flash_container">
<h2 class="sr-only">Notifications</h2>
<p class="alert alert--danger">
<span data-feather="alert-octagon" aria-hidden="true"></span>
<strong>DATA ERROR:</strong> {{ data_errors.get(datakey) }}
<span class="flash_close alert__close" role="button">(Dismiss)</span>
</p>
</div>
</div>
{% endif %}

{% endif %}

{% if page.layout %}
Expand Down
2 changes: 2 additions & 0 deletions test.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down