forked from ScoDoc/ScoDoc
Ajout d'un formulaire de rapport de bug
- Formulaire permettant de saisir un rapport de bug et de l'envoyer sur une nouvelle API scodoc.org - Modification du lien de la page d'accueil pour pointer vers le formulaire de rapport de bug au lieu de simplement dump - Après un échange avec l'API scodoc.org (pour l'upload de dump et la création de ticket), on tente de récuperer le champ json "message" pour l'afficher à l'utilisateur
This commit is contained in:
parent
bb23cdcea7
commit
63b28a3277
97
app/scodoc/sco_bug_report.py
Normal file
97
app/scodoc/sco_bug_report.py
Normal file
@ -0,0 +1,97 @@
|
||||
# -*- mode: python -*-
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
##############################################################################
|
||||
#
|
||||
# Gestion scolarite IUT
|
||||
#
|
||||
# Copyright (c) 1999 - 2024 Emmanuel Viennet. All rights reserved.
|
||||
#
|
||||
# This program is free software; you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
# the Free Software Foundation; either version 2 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program; if not, write to the Free Software
|
||||
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
#
|
||||
# Emmanuel Viennet emmanuel.viennet@viennet.net
|
||||
#
|
||||
##############################################################################
|
||||
|
||||
"""Rapport de bug ScoDoc
|
||||
|
||||
Permet de créer un rapport de bug (ticket) sur la plateforme git scodoc.org.
|
||||
|
||||
Le principe est le suivant:
|
||||
1- Si l'utilisateur le demande, on dump la base de données et on l'envoie
|
||||
|
||||
2- ScoDoc envoie une requête POST à scodoc.org pour qu'un ticket git soit créé avec les
|
||||
informations fournies par l'utilisateur + quelques métadonnées.
|
||||
|
||||
"""
|
||||
|
||||
import app.scodoc.sco_utils as scu, sco_version, requests
|
||||
from flask import g
|
||||
from flask_login import current_user
|
||||
from app import log
|
||||
from app.scodoc.sco_exceptions import ScoValueError
|
||||
from app.scodoc.sco_dump_db import sco_dump_and_send_db
|
||||
|
||||
|
||||
def sco_bug_report(
|
||||
title: str = "", message: str = "", etab: str = "", include_dump: bool = False
|
||||
) -> requests.Response:
|
||||
dump_id = None
|
||||
|
||||
if include_dump:
|
||||
dump = sco_dump_and_send_db()
|
||||
|
||||
try:
|
||||
dump_id = dump.json()["dump_id"]
|
||||
except (requests.exceptions.JSONDecodeError, KeyError):
|
||||
dump_id = "inconnu"
|
||||
|
||||
try:
|
||||
r = requests.post(
|
||||
scu.SCO_BUG_REPORT_URL,
|
||||
json={
|
||||
"ticket": {
|
||||
"title": title,
|
||||
"message": message,
|
||||
"etab": etab,
|
||||
"dept": getattr(g, "scodoc_dept", "-"),
|
||||
},
|
||||
"user": {
|
||||
"name": current_user.get_nomcomplet(),
|
||||
"email": current_user.email,
|
||||
},
|
||||
"dump": {
|
||||
"included": include_dump,
|
||||
"id": dump_id,
|
||||
},
|
||||
"scodoc": {
|
||||
"version": sco_version.SCOVERSION,
|
||||
},
|
||||
},
|
||||
timeout=scu.SCO_ORG_TIMEOUT,
|
||||
)
|
||||
|
||||
except (requests.exceptions.ConnectionError, requests.exceptions.Timeout) as exc:
|
||||
log("ConnectionError: Impossible de joindre le serveur d'assistance")
|
||||
raise ScoValueError(
|
||||
"""
|
||||
Impossible de joindre le serveur d'assistance (scodoc.org).
|
||||
Veuillez contacter le service informatique de votre établissement pour
|
||||
corriger la configuration de ScoDoc. Dans la plupart des cas, il
|
||||
s'agit d'un proxy mal configuré.
|
||||
"""
|
||||
) from exc
|
||||
|
||||
return r
|
@ -67,7 +67,7 @@ SCO_DUMP_LOCK = "/tmp/scodump.lock"
|
||||
|
||||
def sco_dump_and_send_db(
|
||||
message: str = "", request_url: str = "", traceback_str_base64: str = ""
|
||||
):
|
||||
) -> requests.Response:
|
||||
"""Dump base de données et l'envoie anonymisée pour debug"""
|
||||
traceback_str = base64.urlsafe_b64decode(traceback_str_base64).decode(
|
||||
scu.SCO_ENCODING
|
||||
@ -97,7 +97,6 @@ def sco_dump_and_send_db(
|
||||
|
||||
# Send
|
||||
r = _send_db(ano_db_name, message, request_url, traceback_str=traceback_str)
|
||||
code = r.status_code
|
||||
|
||||
finally:
|
||||
# Drop anonymized database
|
||||
@ -107,7 +106,7 @@ def sco_dump_and_send_db(
|
||||
|
||||
log("sco_dump_and_send_db: done.")
|
||||
|
||||
return code
|
||||
return r
|
||||
|
||||
|
||||
def _duplicate_db(db_name, ano_db_name):
|
||||
|
@ -719,6 +719,7 @@ SCO_DEV_MAIL = "emmanuel.viennet@gmail.com" # SVP ne pas changer
|
||||
# ne pas changer (ou vous perdez le support)
|
||||
SCO_DUMP_UP_URL = "https://scodoc.org/scodoc-installmgr/upload-dump"
|
||||
SCO_UP2DATE = "https://scodoc.org/scodoc-installmgr/check_version"
|
||||
SCO_BUG_REPORT_URL = "https://scodoc.org/scodoc-installmgr/report"
|
||||
SCO_ORG_TIMEOUT = 180 # contacts scodoc.org
|
||||
SCO_EXT_TIMEOUT = 180 # appels à des ressources extérieures (siret, ...)
|
||||
SCO_TEST_API_TIMEOUT = 5 # pour tests unitaires API
|
||||
|
@ -297,7 +297,7 @@ div.effectif {
|
||||
rel="noopener noreferrer">Contact (Discord)</a>
|
||||
</li>
|
||||
<li>
|
||||
<a class="stdlink" href="sco_dump_and_send_db">Envoyer données</a>
|
||||
<a class="stdlink" href="sco_bug_report">Créer un ticket</a>
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
|
@ -85,6 +85,7 @@ from app.scodoc import (
|
||||
html_sco_header,
|
||||
sco_import_etuds,
|
||||
sco_archives_etud,
|
||||
sco_bug_report,
|
||||
sco_cache,
|
||||
sco_debouche,
|
||||
sco_dept,
|
||||
@ -2534,25 +2535,105 @@ def stat_bac(formsemestre_id):
|
||||
def sco_dump_and_send_db(message="", request_url="", traceback_str_base64=""):
|
||||
"Send anonymized data to supervision"
|
||||
|
||||
status_code = sco_dump_db.sco_dump_and_send_db(
|
||||
r = sco_dump_db.sco_dump_and_send_db(
|
||||
message, request_url, traceback_str_base64=traceback_str_base64
|
||||
)
|
||||
|
||||
status_code = r.status_code
|
||||
|
||||
try:
|
||||
r_msg = r.json()["message"]
|
||||
except (requests.exceptions.JSONDecodeError, KeyError):
|
||||
r_msg = "Erreur: code <tt>"
|
||||
+status_code
|
||||
+'</tt> Merci de contacter <a href="mailto:'
|
||||
+scu.SCO_DEV_MAIL
|
||||
+'">'
|
||||
+scu.SCO_DEV_MAIL
|
||||
+"</a>"
|
||||
|
||||
H = [html_sco_header.sco_header(page_title="Assistance technique")]
|
||||
if status_code == requests.codes.INSUFFICIENT_STORAGE: # pylint: disable=no-member
|
||||
H.append(
|
||||
"""<p class="warning">
|
||||
Erreur: espace serveur trop plein.
|
||||
Merci de contacter <a href="mailto:{0}">{0}</a></p>""".format(
|
||||
scu.SCO_DEV_MAIL
|
||||
)
|
||||
)
|
||||
elif status_code == requests.codes.OK: # pylint: disable=no-member
|
||||
H.append("""<p>Opération effectuée.</p>""")
|
||||
if status_code == requests.codes.OK: # pylint: disable=no-member
|
||||
H.append(f"""<p>Opération effectuée.</p><p>{r_msg}</p>""")
|
||||
else:
|
||||
H.append(
|
||||
f"""<p class="warning">
|
||||
Erreur: code <tt>{status_code}</tt>
|
||||
Merci de contacter <a href="mailto:{scu.SCO_DEV_MAIL}">{scu.SCO_DEV_MAIL}</a></p>"""
|
||||
)
|
||||
H.append(f"""<p class="warning">{r_msg}</p>""")
|
||||
flash("Données envoyées au serveur d'assistance")
|
||||
return "\n".join(H) + html_sco_header.sco_footer()
|
||||
|
||||
|
||||
# --- Report form (assistance)
|
||||
@bp.route("/sco_bug_report", methods=["GET"])
|
||||
@scodoc
|
||||
@permission_required(Permission.ScoView)
|
||||
@scodoc7func
|
||||
def sco_bug_report_form():
|
||||
"Formulaire de création d'un ticket d'assistance"
|
||||
|
||||
H = [
|
||||
html_sco_header.sco_header(page_title="Assistance technique"),
|
||||
"""<h2>Assistance technique</h2>
|
||||
<p>
|
||||
Ce formulaire permet d'effectuer une demande d'assistance technique.<br>
|
||||
Son <b>contenu sera accessible publiquement</b> sur scodoc.org, veuillez donc ne pas y inclure d'informations sensibles.<br>
|
||||
L'adresse email associée à votre compte ScoDoc est automatiquement transmise avec votre demande mais ne sera pas
|
||||
affichée publiquement.<br>
|
||||
</p>
|
||||
<form method="POST">
|
||||
<label for="title">Titre du ticket</label><span style="color: red;">*</span><br>
|
||||
<input type="text" name="title" id="title" required><br>
|
||||
<label for="message">Message</label><span style="color: red;">*</span><br>
|
||||
<textarea name="message" rows="10" cols="45" required></textarea><br>
|
||||
<label for="etab" >Établissement</label><br>
|
||||
""",
|
||||
]
|
||||
|
||||
H.append(
|
||||
'<input type="text" name="etab" value="'
|
||||
+ (sco_preferences.get_preference("InstituteName") or "")
|
||||
+ '"><br>'
|
||||
)
|
||||
|
||||
H.append(
|
||||
"""
|
||||
<input type="checkbox" name="include_dump">
|
||||
<label for="include_dump">Inclure une copie anonymisée des données ? (ces données permettent aux développeur·euse·s de reproduire l'erreur rencontrée)</label><br><br>
|
||||
<input type="submit" value="Envoyer">
|
||||
</form>
|
||||
"""
|
||||
)
|
||||
|
||||
return "\n".join(H) + html_sco_header.sco_footer()
|
||||
|
||||
|
||||
# --- Report create (assistance)
|
||||
@bp.route("/sco_bug_report", methods=["POST"])
|
||||
@scodoc
|
||||
@permission_required(Permission.ScoView)
|
||||
@scodoc7func
|
||||
def sco_bug_report_create(title=None, message=None, etab="", include_dump=False):
|
||||
"Création d'un ticket d'assistance"
|
||||
|
||||
if not title or not message:
|
||||
flash("Les champs titre et message sont obligatoires.")
|
||||
return flask.redirect(url_for("scolar.sco_bug_report"))
|
||||
|
||||
r = sco_bug_report.sco_bug_report(title, message, etab, include_dump)
|
||||
|
||||
status_code = r.status_code
|
||||
try:
|
||||
r_msg = r.json()["message"]
|
||||
except (requests.exceptions.JSONDecodeError, KeyError):
|
||||
r_msg = "Erreur: code <tt>"
|
||||
+status_code
|
||||
+'</tt> Merci de contacter <a href="mailto:'
|
||||
+scu.SCO_DEV_MAIL
|
||||
+'">'
|
||||
+scu.SCO_DEV_MAIL
|
||||
+"</a>"
|
||||
|
||||
H = [html_sco_header.sco_header(page_title="Assistance technique")]
|
||||
if r.status_code >= 200 and r.status_code < 300:
|
||||
H.append(f"""<p>Opération effectuée.</p><p>{r_msg}</p>""")
|
||||
else:
|
||||
H.append(f"""<p class="warning">{r_msg}</p>""")
|
||||
return "\n".join(H) + html_sco_header.sco_footer()
|
||||
|
Loading…
Reference in New Issue
Block a user