From 6a525eb1a199eff52d3b47a1c8c08ca55dfba823 Mon Sep 17 00:00:00 2001 From: Emmanuel Viennet Date: Mon, 14 Mar 2022 14:09:59 +0100 Subject: [PATCH] Form. assistance dans exception handler --- app/__init__.py | 4 +++- app/scodoc/sco_dump_db.py | 14 +++++++++----- app/templates/error_500.html | 22 +++++++++++++++++----- app/views/scolar.py | 12 ++++++++---- 4 files changed, 37 insertions(+), 15 deletions(-) diff --git a/app/__init__.py b/app/__init__.py index 70eac403..7521520e 100644 --- a/app/__init__.py +++ b/app/__init__.py @@ -62,7 +62,7 @@ def handle_access_denied(exc): return render_template("error_access_denied.html", exc=exc), 403 -def internal_server_error(e): +def internal_server_error(exc): """Bugs scodoc, erreurs 500""" # note that we set the 500 status explicitly return ( @@ -70,6 +70,8 @@ def internal_server_error(e): "error_500.html", SCOVERSION=sco_version.SCOVERSION, date=datetime.datetime.now().isoformat(), + exc=exc, + request_url=request.url, ), 500, ) diff --git a/app/scodoc/sco_dump_db.py b/app/scodoc/sco_dump_db.py index 4b55b41f..190cec96 100644 --- a/app/scodoc/sco_dump_db.py +++ b/app/scodoc/sco_dump_db.py @@ -51,7 +51,7 @@ import fcntl import subprocess import requests -from flask import flash +from flask import flash, request from flask_login import current_user import app.scodoc.notesdb as ndb @@ -66,7 +66,7 @@ from app.scodoc.sco_exceptions import ScoValueError SCO_DUMP_LOCK = "/tmp/scodump.lock" -def sco_dump_and_send_db(): +def sco_dump_and_send_db(message: str = "", request_url: str = ""): """Dump base de données et l'envoie anonymisée pour debug""" H = [html_sco_header.sco_header(page_title="Assistance technique")] # get currect (dept) DB name: @@ -95,7 +95,7 @@ def sco_dump_and_send_db(): _anonymize_db(ano_db_name) # Send - r = _send_db(ano_db_name) + r = _send_db(ano_db_name, message, request_url) if ( r.status_code == requests.codes.INSUFFICIENT_STORAGE # pylint: disable=no-member @@ -175,7 +175,7 @@ def _get_scodoc_serial(): return 0 -def _send_db(ano_db_name): +def _send_db(ano_db_name: str, message: str = "", request_url: str = ""): """Dump this (anonymized) database and send it to tech support""" log(f"dumping anonymized database {ano_db_name}") try: @@ -184,7 +184,9 @@ def _send_db(ano_db_name): ) except subprocess.CalledProcessError as e: log(f"sco_dump_and_send_db: exception in anonymisation: {e}") - raise ScoValueError(f"erreur lors de l'anonymisation de la base {ano_db_name}") + raise ScoValueError( + f"erreur lors de l'anonymisation de la base {ano_db_name}" + ) from e log("uploading anonymized dump...") files = {"file": (ano_db_name + ".dump", dump)} @@ -194,6 +196,8 @@ def _send_db(ano_db_name): files=files, data={ "dept_name": sco_preferences.get_preference("DeptName"), + "message": message or "", + "request_url": request_url or request.url, "serial": _get_scodoc_serial(), "sco_user": str(current_user), "sent_by": sco_users.user_info(str(current_user))["nomcomplet"], diff --git a/app/templates/error_500.html b/app/templates/error_500.html index 23a5c609..4e77aa63 100644 --- a/app/templates/error_500.html +++ b/app/templates/error_500.html @@ -3,7 +3,7 @@ {% import 'bootstrap/wtf.html' as wtf %} {% block title %}Une erreur est survenue !{% endblock %} -{% block body %} +{% block app_content %}

Une erreur est survenue !

Oups... ScoDoc version {{SCOVERSION}} @@ -12,10 +12,22 @@

Si le problème persiste, contacter l'administrateur de votre site, ou écrire la liste "notes" notes@listes.univ-paris13.fr en - indiquant la version du logiciel -
- (plus d'informations sur les listes de diffusion voir - cette page). + indiquant la version du logiciel. +

+{% if 'scodoc_dept' in g %} +

Pour aider les développeurs à corriger le problème, nous vous suggérons d'envoyer les données + sur votre configuration: +

+ + +
Message optionnel:
+ + +
+

+{% endif %} +

Pour plus d'informations sur les listes de diffusion voir + cette page.

retour à la page d'accueil

diff --git a/app/views/scolar.py b/app/views/scolar.py index 3258ec58..48efb23b 100644 --- a/app/views/scolar.py +++ b/app/views/scolar.py @@ -2190,7 +2190,11 @@ def stat_bac(formsemestre_id): return Bacs -# --- Dump -sco_publish( - "/sco_dump_and_send_db", sco_dump_db.sco_dump_and_send_db, Permission.ScoView -) +# --- Dump (assistance) +@bp.route("/sco_dump_and_send_db", methods=["GET", "POST"]) +@scodoc +@permission_required(Permission.ScoView) +@scodoc7func +def sco_dump_and_send_db(message="", request_url=""): + "Send anonymized data to supervision" + return sco_dump_db.sco_dump_and_send_db(message, request_url)