diff --git a/app/scodoc/sco_dept.py b/app/scodoc/sco_dept.py
index 274b41d76..c8dcc9142 100644
--- a/app/scodoc/sco_dept.py
+++ b/app/scodoc/sco_dept.py
@@ -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("""
""")
# Liste de toutes les sessions:
sems = sco_formsemestre.do_formsemestre_list()
diff --git a/app/scodoc/sco_up_to_date.py b/app/scodoc/sco_up_to_date.py
index 02c35c77d..152b05691 100644
--- a/app/scodoc/sco_up_to_date.py
+++ b/app/scodoc/sco_up_to_date.py
@@ -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.
"""
- current_app.logger.debug("Warning: is_up_to_date not implemented for ScoDoc9")
- return True, "unimplemented"
+ diag = ""
+ try:
+ response = requests.get(scu.SCO_UP2DATE)
+ except requests.exceptions.ConnectionError:
+ current_app.logger.debug("is_up_to_date: %s", diag)
+ return f"""Attention: installation de {SCONAME} non fonctionnelle.
+ Détails: pas de connexion à {scu.SCO_WEBSITE}.
+ Vérifier paramètrages réseau,
+
voir la documentation.
+
+ """
+ except:
+ current_app.logger.debug("is_up_to_date: %s", diag)
+ return f"""Attention: installation de {SCONAME} non fonctionnelle.
+ Détails: erreur inconnue lors de la connexion à {scu.SCO_WEBSITE}.
+ Vérifier paramètrages réseau,
+
voir la documentation.
+
+ """
+ if response.status_code != 200:
+ current_app.logger.debug(
+ f"is_up_to_date: invalid response code ({response.status_code})"
+ )
+ return f"""Attention: réponse invalide de {scu.SCO_WEBSITE}
+ (erreur http {response.status_code}).
"""
-def html_up_to_date_box():
- """"""
- status, msg = is_up_to_date()
- if status:
- return ""
- return (
- """
-
Attention: cette installation de ScoDoc n'est pas à jour.
-
Contactez votre administrateur. %s
-
"""
- % msg
- )
+ try:
+ infos = json.loads(response.text)
+ except json.decoder.JSONDecodeError:
+ current_app.logger.debug(f"is_up_to_date: invalid response (json)")
+ return f"""Attention: réponse invalide de {scu.SCO_WEBSITE}
+ (erreur json).
"""
+
+ # 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"""Attention: {SCONAME} version ({SCOVERSION}) non à jour
+ ({infos["version"]} disponible).
+
+ """
+ return "" # ok
diff --git a/app/scodoc/sco_utils.py b/app/scodoc/sco_utils.py
index 7c62ca7c4..03e02cbf6 100644
--- a/app/scodoc/sco_utils.py
+++ b/app/scodoc/sco_utils.py
@@ -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"
diff --git a/app/static/css/scodoc.css b/app/static/css/scodoc.css
index 61d2e2ecd..d8a7249c4 100644
--- a/app/static/css/scodoc.css
+++ b/app/static/css/scodoc.css
@@ -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;
}
diff --git a/app/static/js/scodoc.js b/app/static/js/scodoc.js
index c4def3d6d..b1c15017e 100644
--- a/app/static/js/scodoc.js
+++ b/app/static/js/scodoc.js
@@ -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);
+ }
});
diff --git a/app/views/scodoc.py b/app/views/scodoc.py
index 3dc07fea0..70c58cede 100644
--- a/app/views/scodoc.py
+++ b/app/views/scodoc.py
@@ -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
diff --git a/app/views/scolar.py b/app/views/scolar.py
index 48efb23bb..67cb7b7b6 100644
--- a/app/views/scolar.py
+++ b/app/views/scolar.py
@@ -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"]
)
diff --git a/sco_version.py b/sco_version.py
index e962db1f0..0cedeb3dc 100644
--- a/sco_version.py
+++ b/sco_version.py
@@ -1,7 +1,7 @@
# -*- mode: python -*-
# -*- coding: utf-8 -*-
-SCOVERSION = "9.1.81"
+SCOVERSION = "9.1.82"
SCONAME = "ScoDoc"