From e63be96dac0038b4b07d0c8be1849188615204c1 Mon Sep 17 00:00:00 2001 From: Tim Van Baak Date: Tue, 28 Apr 2020 00:20:51 -0700 Subject: [PATCH] Prevent articles from being readied when they have errors --- amanuensis/resources/editor.js | 5 ++++- amanuensis/server/session/editor.py | 2 ++ amanuensis/server/session/session.editor.jinja | 1 + 3 files changed, 7 insertions(+), 1 deletion(-) diff --git a/amanuensis/resources/editor.js b/amanuensis/resources/editor.js index 2205561..ef663bc 100644 --- a/amanuensis/resources/editor.js +++ b/amanuensis/resources/editor.js @@ -43,6 +43,7 @@ function update(article) { if (req.readyState == 4 && req.status == 200) { // Update internal state with the returned article object params.status = req.response.status; + params.errors = req.response.error.length; document.getElementById("editor-title").value = req.response.title; // Set editor editability based on article status updateEditorStatus(); @@ -55,11 +56,13 @@ function update(article) { } function updateEditorStatus() { - var ready = !!params.article.status.ready || !!params.article.status.approved; + var ready = !!params.status.ready || !!params.status.approved; document.getElementById("editor-title").disabled = ready; document.getElementById("editor-content").disabled = ready; + var hasErrors = params.errors > 0; var submitButton = document.getElementById("button-submit"); submitButton.innerText = ready ? "Edit article" : "Submit article"; + submitButton.disabled = hasErrors; } function updatePreview(response) { diff --git a/amanuensis/server/session/editor.py b/amanuensis/server/session/editor.py index 67514ca..9715a46 100644 --- a/amanuensis/server/session/editor.py +++ b/amanuensis/server/session/editor.py @@ -114,6 +114,8 @@ def update_draft(lexicon: LexiconModel, article_json): lexicon, current_user, title) content_infos, content_warnings, content_errors = content_constraint_analysis( lexicon, current_user, article.character, parsed) + if any(title_errors) or any(content_errors): + status['ready'] = False # Article update filename = f'{article.character}.{aid}' diff --git a/amanuensis/server/session/session.editor.jinja b/amanuensis/server/session/session.editor.jinja index c94f181..495f2fd 100644 --- a/amanuensis/server/session/session.editor.jinja +++ b/amanuensis/server/session/session.editor.jinja @@ -22,6 +22,7 @@ article: { aid: {{ jsonfmt(article.aid) }}, status: {{ jsonfmt(article.status) }}, + errors: 1, } {% else %} article: null