1
0
forked from ScoDoc/ScoDoc

Form. assistance dans exception handler

This commit is contained in:
Emmanuel Viennet 2022-03-14 14:09:59 +01:00
parent c0a8f6f7d6
commit 6a525eb1a1
4 changed files with 37 additions and 15 deletions

View File

@ -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,
)

View File

@ -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"],

View File

@ -3,7 +3,7 @@
{% import 'bootstrap/wtf.html' as wtf %}
{% block title %}Une erreur est survenue !{% endblock %}
{% block body %}
{% block app_content %}
<h1>Une erreur est survenue !</h1>
<p>Oups...</tt> <span style="color:red;"><b>ScoDoc version
<span style="font-size: 120%;">{{SCOVERSION}}</span></b></span>
@ -12,10 +12,22 @@
<p> Si le problème persiste, contacter l'administrateur de votre site,
ou écrire la liste "notes" <a href="mailto:notes@listes.univ-paris13.fr">notes@listes.univ-paris13.fr</a> en
indiquant la version du logiciel
<br />
(plus d'informations sur les listes de diffusion <a href="https://scodoc.org/ListesDeDiffusion/">voir
cette page</a>).
indiquant la version du logiciel.
</p>
{% if 'scodoc_dept' in g %}
<p>Pour aider les développeurs à corriger le problème, nous vous suggérons d'envoyer les données
sur votre configuration:
<form method="POST" action="{{ url_for( 'scolar.sco_dump_and_send_db', scodoc_dept=g.scodoc_dept ) }}">
<input type="hidden" name="request_url" value="{{request_url}}">
<input type="submit" value="Envoyer données assistance">
<div>Message optionnel: </div>
<textarea name="message" cols="40" rows="4"></textarea>
</form>
</p>
{% endif %}
<p>Pour plus d'informations sur les listes de diffusion <a href="https://scodoc.org/ListesDeDiffusion/">voir
cette page</a>.
</p>
<p><a href="{{ url_for('scodoc.index') }}">retour à la page d'accueil</a></p>

View File

@ -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)