From 6dc0f6c296728ed1689341ea318ac432d91400dd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Th=C3=A9o=20Gastinel?= <264859180+gastinelt@users.noreply.github.com> Date: Thu, 29 Oct 2026 15:44:47 +0100 Subject: [PATCH] feat(admin): suivi des candidatures recues, suppression de code et compteur d utilisations --- assets/css/espace.css | 99 +++++++++++++++++++++ beta/server.py | 42 +++++++++ beta/tests/test_http.py | 22 +++++ index.html | 187 ++++++++++++++++++++++++++++++++-------- 4 files changed, 313 insertions(+), 37 deletions(-) diff --git a/assets/css/espace.css b/assets/css/espace.css index 4e9de2a..9c7c4f8 100644 --- a/assets/css/espace.css +++ b/assets/css/espace.css @@ -382,3 +382,102 @@ footer{max-width:1080px;margin:0 auto;padding:0 16px 32px;color:var(--doux);font padding: 12px 0; margin: 0; } + + +/* Badges d'utilisations & actions */ +.badge-usages { + display: inline-block; + font-size: 12px; + font-weight: 700; + padding: 3px 8px; + border-radius: 6px; + background: var(--filet); + color: var(--texte); +} +.badge-usages.actif { + background: #D8E0DA; + color: #2F4D35; +} +.date-derniere { + display: block; + font-size: 11px; + color: var(--doux); + margin-top: 3px; +} +.btn-action-suppr { + font-family: inherit; + font-size: 12px; + font-weight: 600; + background: transparent; + color: #A0554B; + border: 1px solid #F5D6D1; + padding: 4px 10px; + border-radius: 6px; + cursor: pointer; + transition: all 0.2s ease; +} +.btn-action-suppr:hover { + background: #A0554B; + color: #FFFFFF; + border-color: #A0554B; +} + +/* Bloc Candidatures */ +.candidatures-bloc { + margin-top: 32px; + border-top: 1.5px solid var(--filet); + padding-top: 24px; +} +.btn-remplir-code { + font-family: inherit; + font-size: 12px; + font-weight: 700; + background: var(--sauge); + color: #FFFFFF; + border: none; + border-radius: 999px; + padding: 5px 12px; + cursor: pointer; + display: inline-flex; + align-items: center; + gap: 4px; + transition: all 0.2s ease; + white-space: nowrap; +} +.btn-remplir-code:hover { + background: #6E8173; +} +.contact-ligne { + font-size: 12.5px; + display: flex; + flex-direction: column; + gap: 2px; +} +.contact-ligne a { + color: var(--texte); + text-decoration: underline; + text-underline-offset: 2px; +} +.contact-ligne a:hover { + color: var(--sauge); +} +.badge-age { + display: inline-block; + font-size: 11px; + font-weight: 700; + padding: 2px 7px; + border-radius: 4px; + background: #EAE8E2; + color: var(--texte); + margin-left: 6px; +} +.badge-age.mineur { + background: #F8E3D8; + color: #8C4824; +} +.parent-info { + display: block; + font-size: 11px; + color: #8C4824; + margin-top: 2px; +} diff --git a/beta/server.py b/beta/server.py index 16b62bc..eeda0f1 100644 --- a/beta/server.py +++ b/beta/server.py @@ -71,6 +71,7 @@ LIMITES_POST = { "/__beta/api/tester": 8000, "/__beta/api/feedback": 2_600_000, "/_admin/api/codes/creer": 4000, + "/_admin/api/codes/supprimer": 1000, } @@ -276,6 +277,8 @@ class Handler(BaseHTTPRequestHandler): return self.fichier(RACINE / "assets" / "img", p[len("/assets/img/"):]) if p == "/_admin/api/codes/liste": return self.admin_liste_codes() + if p == "/_admin/api/candidatures/liste": + return self.admin_liste_candidatures() s = self.session() if not s: if p.endswith(".html") or p == "/": @@ -305,6 +308,8 @@ class Handler(BaseHTTPRequestHandler): return self.formulaire_testeur() if p == "/_admin/api/codes/creer": return self.admin_creer_code() + if p == "/_admin/api/codes/supprimer": + return self.admin_supprimer_code() s = self.session() if not s: return self.json(401, {"erreur": "session expirée, ressaisir le code"}) @@ -534,6 +539,43 @@ class Handler(BaseHTTPRequestHandler): "created_at": time.time() }) + def admin_supprimer_code(self): + if self.headers.get("X-Admin") != "1": + return self.json(403, {"erreur": "accès réservé à l'administration"}) + try: + d = json.loads(self._corps.decode("utf-8")) + code_id = int(d.get("id")) + except Exception: + return self.json(400, {"erreur": "ID de code invalide"}) + + self.c.execute("DELETE FROM sessions WHERE code_id=?", (code_id,)) + self.c.execute("DELETE FROM codes WHERE id=?", (code_id,)) + self.c.execute("UPDATE audit SET code_id=NULL WHERE code_id=?", (code_id,)) + self.c.commit() + db.journal(self.c, "code_supprime", None, None, f"id={code_id}") + return self.json(200, {"ok": True, "id": code_id}) + + def admin_liste_candidatures(self): + if self.headers.get("X-Admin") != "1": + return self.json(403, {"erreur": "accès réservé à l'administration"}) + + lignes = [] + for r in self.c.execute("SELECT id, ts, nom, prenom, email, tel, naissance, mineur, parent_nom, parent_email, suivi_reseaux FROM testers ORDER BY id DESC LIMIT 100"): + lignes.append({ + "id": r["id"], + "ts": r["ts"], + "nom": r["nom"], + "prenom": r["prenom"], + "email": r["email"], + "tel": r["tel"], + "naissance": r["naissance"], + "mineur": bool(r["mineur"]), + "parent_nom": r["parent_nom"], + "parent_email": r["parent_email"], + "suivi_reseaux": bool(r["suivi_reseaux"]), + }) + return self.json(200, {"ok": True, "candidatures": lignes}) + def admin_liste_codes(self): if self.headers.get("X-Admin") != "1": return self.json(403, {"erreur": "accès réservé à l'administration"}) diff --git a/beta/tests/test_http.py b/beta/tests/test_http.py index ce3b74e..d6e35aa 100644 --- a/beta/tests/test_http.py +++ b/beta/tests/test_http.py @@ -236,6 +236,28 @@ class T(unittest.TestCase): self.assertTrue(res.get("ok")) labels = [c["label"] for c in res.get("codes", [])] self.assertIn("Testeur Admin", labels) + code_id = res["codes"][0]["id"] + + # 4. Supprimer le code + s, _, d = self.req("POST", "/_admin/api/codes/supprimer", {"id": code_id}, headers={"X-Admin": "1"}) + self.assertEqual(s, 200) + res = json.loads(d.decode()) + self.assertTrue(res.get("ok")) + self.assertEqual(res.get("id"), code_id) + + # Vérification qu'il n'est plus dans la liste + s, _, d = self.req("GET", "/_admin/api/codes/liste", headers={"X-Admin": "1"}) + self.assertEqual(s, 200) + res = json.loads(d.decode()) + labels_after = [c["label"] for c in res.get("codes", [])] + self.assertNotIn("Testeur Admin", labels_after) + + # 5. Liste des candidatures + s, _, d = self.req("GET", "/_admin/api/candidatures/liste", headers={"X-Admin": "1"}) + self.assertEqual(s, 200) + res = json.loads(d.decode()) + self.assertTrue(res.get("ok")) + self.assertIsInstance(res.get("candidatures"), list) if __name__ == "__main__": diff --git a/index.html b/index.html index 38ddd2d..184d709 100644 --- a/index.html +++ b/index.html @@ -113,13 +113,24 @@
Chargement des codes en cours...
Chargement des candidatures...
+Impossible de charger les codes (' + res.status + ').
'; - return; - } - const data = await res.json(); - afficherTableau(data.codes || []); - } catch (e) { - conteneurTableau.innerHTML = 'Impossible de contacter le serveur.
'; - } - } - - function afficherTableau(codes) { - if (!codes.length) { - conteneurTableau.innerHTML = 'Aucun code émis pour le moment.
'; - return; - } - let html = '| ID | Testeur | Créé le | Expire | Usages | Statut |
|---|---|---|---|---|---|
| #' + c.id + ' | ' + - '' + escapeHtml(c.label) + ' | ' + - '' + fmtDate(c.created_at) + ' | ' + - '' + (c.expires_at ? fmtDate(c.expires_at) : 'Illimité') + ' | ' + - '' + (c.uses || 0) + ' | ' + - '' + escapeHtml(c.status) + ' | ' + - '
Impossible de charger les codes (' + res.status + ').
'; + return; + } + const data = await res.json(); + afficherTableauCodes(data.codes || []); + } catch (e) { + conteneurTableauCodes.innerHTML = 'Impossible de contacter le serveur.
'; + } + } + + function afficherTableauCodes(codes) { + if (compteCodesEl) compteCodesEl.textContent = codes.length; + if (!codes.length) { + conteneurTableauCodes.innerHTML = 'Aucun code émis pour le moment.
'; + return; + } + let html = '| ID | Testeur | Créé le | Expire | Utilisations | Statut | Action |
|---|---|---|---|---|---|---|
| #' + c.id + ' | ' + + '' + escapeHtml(c.label) + ' | ' + + '' + fmtDate(c.created_at) + ' | ' + + '' + (c.expires_at ? fmtDate(c.expires_at) : 'Illimité') + ' | ' + + '' + usesHtml + ' | ' + + '' + escapeHtml(c.status) + ' | ' + + '' + + ' |
Impossible de charger les candidatures (' + res.status + ').
'; + return; + } + const data = await res.json(); + afficherTableauCandidatures(data.candidatures || []); + } catch (e) { + conteneurTableauCandidatures.innerHTML = 'Impossible de contacter le serveur.
'; + } + } + + function afficherTableauCandidatures(liste) { + if (compteCandidaturesEl) compteCandidaturesEl.textContent = liste.length; + if (!liste.length) { + conteneurTableauCandidatures.innerHTML = 'Aucune candidature reçue via le formulaire pour le moment.
'; + return; + } + let html = '| Date | Candidat | Contact | Réseaux | Action |
|---|---|---|---|---|
| ' + fmtDateHeure(item.ts) + ' | ' + + '' + escapeHtml(item.prenom) + ' ' + escapeHtml(item.nom) + ' ' + ageBadge + parentHtml + ' | ' + + '' +
+ '' + escapeHtml(item.email) + '' +
+ '' + escapeHtml(item.tel) + '' +
+ ' | ' +
+ '' + (item.suivi_reseaux ? '✓ Insta' : '-') + ' | ' + + '' + + ' |