From 4bf456d8ef0e59922fe7f99a87b56ee02a8b570f Mon Sep 17 00:00:00 2001 From: Patrick Jentsch Date: Wed, 13 Jan 2021 15:43:23 +0100 Subject: [PATCH] Check if corpus is exportable before exporting it --- web/app/corpora/events.py | 10 +++++++++- web/app/static/js/nopaque/displays/CorpusDisplay.js | 3 +++ web/app/templates/corpora/corpus.html.j2 | 2 +- 3 files changed, 13 insertions(+), 2 deletions(-) diff --git a/web/app/corpora/events.py b/web/app/corpora/events.py index 616354a9..7e085814 100644 --- a/web/app/corpora/events.py +++ b/web/app/corpora/events.py @@ -28,7 +28,15 @@ corpus_analysis_clients = {} @socketio_login_required def export_corpus(corpus_id): # TODO: This should not be get_or_404 here - Socket.IO != HTTP request - corpus = Corpus.query.get_or_404(corpus_id) + corpus = Corpus.query.get(corpus_id) + if corpus is None: + response = {'code': 404, 'msg': 'Not found'} + socketio.emit('export_corpus', response, room=request.sid) + return + if corpus.status not in ['prepared', 'start analysis', 'stop analysis']: + response = {'code': 412, 'msg': 'Precondition Failed'} + socketio.emit('export_corpus', response, room=request.sid) + return # delete old corpus archive if it exists/has been build before if corpus.archive_file is not None and os.path.isfile(corpus.archive_file): os.remove(corpus.archive_file) diff --git a/web/app/static/js/nopaque/displays/CorpusDisplay.js b/web/app/static/js/nopaque/displays/CorpusDisplay.js index 68a2a11f..11064623 100644 --- a/web/app/static/js/nopaque/displays/CorpusDisplay.js +++ b/web/app/static/js/nopaque/displays/CorpusDisplay.js @@ -79,6 +79,9 @@ class CorpusDisplay extends RessourceDisplay { } } for (let element of this.displayElement.querySelectorAll('.corpus-status')) {this.setElement(element, status);} + for (let exportCorpusTriggerElement of this.displayElement.querySelectorAll('.export-corpus-trigger')) { + exportCorpusTriggerElement.classList.toggle('disabled', !['prepared', 'start analysis', 'stop analysis'].includes(status)); + } for (let element of this.displayElement.querySelectorAll('.status')) {element.dataset.status = status;} for (let element of this.displayElement.querySelectorAll('.status-spinner')) { if (['submitted', 'queued', 'running', 'canceling', 'start analysis', 'stop analysis'].includes(status)) { diff --git a/web/app/templates/corpora/corpus.html.j2 b/web/app/templates/corpora/corpus.html.j2 index cba42208..eabed2c1 100644 --- a/web/app/templates/corpora/corpus.html.j2 +++ b/web/app/templates/corpora/corpus.html.j2 @@ -72,7 +72,7 @@
searchAnalyze buildBuild - import_exportExport + import_exportExport deleteDelete