Avertissement si pas de mise à jour ou pb réseau

This commit is contained in:
Emmanuel Viennet 2022-03-19 22:00:31 +01:00
parent ede90c799d
commit d1af865ebd
8 changed files with 82 additions and 40 deletions

View File

@ -56,7 +56,7 @@ def index_html(showcodes=0, showsemtable=0):
H.append(sco_news.scolar_news_summary_html())
# Avertissement de mise à jour:
H.append(sco_up_to_date.html_up_to_date_box())
H.append("""<div id="update_warning"></div>""")
# Liste de toutes les sessions:
sems = sco_formsemestre.do_formsemestre_list()

View File

@ -28,30 +28,61 @@
""" Verification version logiciel vs version "stable" sur serveur
N'effectue pas la mise à jour automatiquement, mais permet un affichage d'avertissement.
Désactivé temporairement pour ScoDoc 9.
"""
import json
import requests
import time
from flask import current_app
import app.scodoc.sco_utils as scu
from sco_version import SCOVERSION, SCONAME
def is_up_to_date():
"""True if up_to_date
Returns status, message
def is_up_to_date() -> str:
"""Check installed version vs last release.
Returns html message, empty of ok.
"""
diag = ""
try:
response = requests.get(scu.SCO_UP2DATE)
except requests.exceptions.ConnectionError:
current_app.logger.debug("is_up_to_date: %s", diag)
return f"""<div>Attention: installation de {SCONAME} non fonctionnelle.</div>
<div>Détails: pas de connexion à {scu.SCO_WEBSITE}.
Vérifier paramètrages réseau,
<a href="https://scodoc.org/GuideInstallDebian11/#informations-sur-les-flux-reseau">voir la documentation</a>.
</div>
"""
except:
current_app.logger.debug("is_up_to_date: %s", diag)
return f"""<div>Attention: installation de {SCONAME} non fonctionnelle.</div>
<div>Détails: erreur inconnue lors de la connexion à {scu.SCO_WEBSITE}.
Vérifier paramètrages réseau,
<a href="https://scodoc.org/GuideInstallDebian11/#informations-sur-les-flux-reseau">voir la documentation</a>.
</div>
"""
current_app.logger.debug("Warning: is_up_to_date not implemented for ScoDoc9")
return True, "unimplemented"
def html_up_to_date_box():
""""""
status, msg = is_up_to_date()
if status:
return ""
return (
"""<div class="update_warning">
<span>Attention: cette installation de ScoDoc n'est pas à jour.</span>
<div class="update_warning_sub">Contactez votre administrateur. %s</div>
</div>"""
% msg
if response.status_code != 200:
current_app.logger.debug(
f"is_up_to_date: invalid response code ({response.status_code})"
)
return f"""<div>Attention: réponse invalide de {scu.SCO_WEBSITE}</div>
<div>(erreur http {response.status_code}).</div>"""
try:
infos = json.loads(response.text)
except json.decoder.JSONDecodeError:
current_app.logger.debug(f"is_up_to_date: invalid response (json)")
return f"""<div>Attention: réponse invalide de {scu.SCO_WEBSITE}</div>
<div>(erreur json).</div>"""
# nb: si de nouveaux paquets sont publiés chaque jour, le décalage ne sera jamais signalé.
# mais en régime "normal", on aura une alerte après 24h sans mise à jour.
days_since_last_package = (time.time() - infos["publication_time"]) / (24 * 60 * 60)
if (infos["version"] != SCOVERSION) and (days_since_last_package > 1.0):
return f"""<div>Attention: {SCONAME} version ({SCOVERSION}) non à jour
({infos["version"]} disponible).</div>
<div>Contacter votre administrateur système
(<a href="https://scodoc.org/MisesAJour/">documentation</a>).
</div>
"""
return "" # ok

View File

@ -361,7 +361,7 @@ SCO_DEV_MAIL = "emmanuel.viennet@gmail.com" # SVP ne pas changer
# Adresse pour l'envoi des dumps (pour assistance technnique):
# 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/last_stable_version"
CSV_FIELDSEP = ";"
CSV_LINESEP = "\n"
CSV_MIMETYPE = "text/comma-separated-values"

View File

@ -2883,7 +2883,8 @@ div.othersemlist input {
}
div.update_warning {
div#update_warning {
/* display: none; */
border: 1px solid red;
background-color: rgb(250,220,220);
margin: 3ex;
@ -2891,11 +2892,11 @@ div.update_warning {
padding-right: 1ex;
padding-bottom: 1ex;
}
div.update_warning span:before {
div#update_warning > div:first-child:before {
content: url(/ScoDoc/static/icons/warning_img.png);
vertical-align: -80%;
}
div.update_warning_sub {
div#update_warning > div:nth-child(2) {
font-size: 80%;
padding-left: 8ex;
}

View File

@ -53,6 +53,13 @@ $(function () {
);
$(".sco_dropdown_menu > li > a > span").switchClass("ui-icon-carat-1-e", "ui-icon-carat-1-s");
/* up-to-date status */
var update_div = document.getElementById("update_warning");
if (update_div) {
fetch('install_info').then(
response => response.text()
).then(text => update_div.innerHTML = text);
}
});

View File

@ -54,6 +54,11 @@ from werkzeug.exceptions import BadRequest, NotFound
from app import db
from app.auth.models import User
from app.decorators import (
admin_required,
scodoc7func,
scodoc,
)
from app.forms.main import config_logos, config_main
from app.forms.main.create_dept import CreateDeptForm
from app.forms.main.config_apo import CodesDecisionsForm
@ -63,14 +68,11 @@ from app.models import departements
from app.models import FormSemestre, FormSemestreInscription
from app.models import ScoDocSiteConfig
from app.models import UniteEns
from app.scodoc import sco_codes_parcours, sco_logos
from app.scodoc import sco_find_etud
from app.scodoc import sco_logos
from app.scodoc import sco_utils as scu
from app.decorators import (
admin_required,
scodoc7func,
scodoc,
)
from app.scodoc.sco_exceptions import AccessDenied
from app.scodoc.sco_permissions import Permission
from app.views import scodoc_bp as bp

View File

@ -65,23 +65,18 @@ from app.scodoc.sco_exceptions import (
ScoValueError,
)
from app.scodoc.TrivialFormulator import TrivialFormulator, tf_error_message
import app
from app.scodoc.gen_tables import GenTable
from app.scodoc import html_sco_header
from app.scodoc import sco_import_etuds
from app.scodoc import sco_abs
from app.scodoc import sco_archives_etud
from app.scodoc import sco_codes_parcours
from app.scodoc import sco_cache
from app.scodoc import sco_debouche
from app.scodoc import sco_dept
from app.scodoc import sco_dump_db
from app.scodoc import sco_edt_cal
from app.scodoc import sco_excel
from app.scodoc import sco_etud
from app.scodoc import sco_find_etud
from app.scodoc import sco_formations
from app.scodoc import sco_formsemestre
from app.scodoc import sco_formsemestre_edit
from app.scodoc import sco_formsemestre_inscriptions
from app.scodoc import sco_groups
from app.scodoc import sco_groups_edit
@ -92,12 +87,10 @@ from app.scodoc import sco_permissions_check
from app.scodoc import sco_photos
from app.scodoc import sco_portal_apogee
from app.scodoc import sco_preferences
from app.scodoc import sco_report
from app.scodoc import sco_synchro_etuds
from app.scodoc import sco_trombino
from app.scodoc import sco_trombino_tours
from app.scodoc import sco_up_to_date
from app.scodoc import sco_etud
def sco_publish(route, function, permission, methods=["GET"]):
@ -338,6 +331,14 @@ def index_html(showcodes=0, showsemtable=0):
return sco_dept.index_html(showcodes=showcodes, showsemtable=showsemtable)
@bp.route("/install_info")
@scodoc
@permission_required(Permission.ScoView)
def install_info():
"""Information on install status (html str)"""
return sco_up_to_date.is_up_to_date()
sco_publish(
"/trombino", sco_trombino.trombino, Permission.ScoView, methods=["GET", "POST"]
)

View File

@ -1,7 +1,7 @@
# -*- mode: python -*-
# -*- coding: utf-8 -*-
SCOVERSION = "9.1.81"
SCOVERSION = "9.1.82"
SCONAME = "ScoDoc"