From b5fc68b8c29298bf87b1d3969b18b2db13d41827 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Th=C3=A9o=20Gastinel?= <264859180+gastinelt@users.noreply.github.com> Date: Thu, 5 Nov 2026 11:19:37 +0100 Subject: [PATCH] =?UTF-8?q?forum=20:=20photos=20=C3=A9pingl=C3=A9es=20sur?= =?UTF-8?q?=20la=20fiche=20d'une=20station=20et=20route=20JSON=20publique?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit GET /forum/api/station/.json (lecture seule, sans cookie, cache 60 s vidé à chaque changement, max-age 300) : url du sujet et 3 photos épinglées au plus. Bouton « Épingler sur la fiche » sous les photos du sujet de la station pour le Propriétaire, l'adjoint et le propriétaire de cette station. 61 tests passent. Co-Authored-By: Claude Opus 5.5 --- forum/README.md | 8 ++- forum/db.py | 10 +++- forum/forum.py | 63 +++++++++++++++++++++++ forum/roles.py | 1 + forum/server.py | 63 +++++++++++++++++++++-- forum/tests/test_forum.py | 105 +++++++++++++++++++++++++++++++++++++- 6 files changed, 243 insertions(+), 7 deletions(-) diff --git a/forum/README.md b/forum/README.md index fed7190..f22a359 100644 --- a/forum/README.md +++ b/forum/README.md @@ -12,7 +12,13 @@ Forum où le père de Théo et d'autres adhérents météo publient (ex. « Réc - Demandes d'adhésion : `/adhesion` (message + 10 photos / 25 Mo, métadonnées retirées, photos hors du dossier public), `/adhesions` pour le propriétaire et l'adjoint ; méthodes `demander_adhesion`, `demandes_adhesion`, `demande_adhesion`, `decider_adhesion`, `photo_adhesion` dans `forum.py` pour le futur panneau LAN. -- Tests : `cd forum && python -m unittest` (52 tests, Hub simulé par un faux serveur local). +- Fiche de station (page station de vercors.me) : `GET /forum/api/station/.json`, publique, lecture seule, sans cookie, + cache mémoire 60 s vidé à chaque changement + `Cache-Control: public, max-age=300`. Renvoie `{"station", "sujet": "/forum/t/N" ou null, + "photos": [{"url": "/forum/photo/.ext", "auteur"}]}` (3 photos au plus, déjà nettoyées à l'envoi ; pas de vignette réduite, la page les réduit). + Épinglage : bouton « Épingler sur la fiche » sous chaque photo du sujet de la station (POST `/fiche-photo`), pour le Propriétaire, + l'adjoint et le propriétaire de CETTE station. Une photo masquée (message ou sujet) disparaît de la fiche. + Attention : `vercors-forum.caddy` force `Cache-Control: no-store` sur tout `/forum*` ; le cache navigateur de la route ne joue qu'une fois ce point revu. +- Tests : `cd forum && python -m unittest` (61 tests, Hub simulé par un faux serveur local). ## Production : préfixe et écoute - `FORUM_PREFIXE` (ex. `/forum`, défaut vide) est appliqué à tous les liens, formulaires, redirections, chemins de cookie et à la `redirect_uri` par défaut (`https://vercors.me/connexion/retour`, sinon `FORUM_REDIRECT_URI`). Le serveur accepte les requêtes avec ou sans préfixe : Caddy peut le retirer (`handle_path`) ou non. diff --git a/forum/db.py b/forum/db.py index 8c6afa0..fada4c9 100644 --- a/forum/db.py +++ b/forum/db.py @@ -1,4 +1,4 @@ -"""Schéma SQLite et accès aux données (version 3 : + sessions Gastinel, demandes d'adhésion).""" +"""Schéma SQLite et accès aux données (version 4 : + sessions Gastinel, demandes d'adhésion, photos de la fiche station).""" import sqlite3 SCHEMA = """ @@ -91,6 +91,14 @@ CREATE TABLE IF NOT EXISTS adhesion_photos ( sha256 TEXT NOT NULL, stored_path TEXT NOT NULL ); +-- Photos épinglées sur la fiche publique d'une station (3 au plus), choisies dans le sujet de la station. +CREATE TABLE IF NOT EXISTS fiche_photos ( + attachment_id INTEGER PRIMARY KEY REFERENCES attachments(id), + station TEXT NOT NULL, + pinned_by INTEGER REFERENCES users(id), + pinned_at TEXT NOT NULL DEFAULT (datetime('now')) +); +CREATE INDEX IF NOT EXISTS idx_fiche_station ON fiche_photos(station, pinned_at); CREATE UNIQUE INDEX IF NOT EXISTS idx_une_demande_en_cours ON adhesions(user_id) WHERE status = 'en_attente'; CREATE INDEX IF NOT EXISTS idx_sessions_user ON sessions(user_id); CREATE INDEX IF NOT EXISTS idx_topics_liste ON topics(pinned DESC, pin_pos, id DESC); diff --git a/forum/forum.py b/forum/forum.py index f1507a8..e9fedae 100644 --- a/forum/forum.py +++ b/forum/forum.py @@ -14,6 +14,7 @@ import roles TITRE_MAX, CORPS_MAX = 150, 20000 EPINGLES_MAX = 5 # sujet fixe compris +FICHE_PHOTOS_MAX = 3 # photos épinglées sur la fiche publique d'une station PHOTOS_MAX, OCTETS_MAX = 10, 25 * 1024 * 1024 # par message, sauf propriétaires (et par demande d'adhésion) ADHESION_MAX = 4000 # longueur du message d'une demande d'adhésion SESSION_JOURS, ETAT_MINUTES = 30, 10 @@ -34,6 +35,7 @@ class Forum: self.dossier_photos = dossier_photos self.proprietaire_id = proprietaire_id or None # id Gastinel de Théo (FORUM_PROPRIETAIRE_ID) self.apres_roles = None # fonction(hub_id, roles) : envoie les rôles au Hub (branchée par server.py) + self.version = 0 # augmente à chaque changement visible sur les fiches de station (cache de server.py) def _pousser_roles(self, hub_id): if not self.apres_roles: @@ -270,6 +272,7 @@ class Forum: raise Invalide("rien à valider") self.con.execute("UPDATE topics SET status=? WHERE id=?", ("publie" if accepte else "refuse", topic_id)) self.con.commit() + self.version += 1 def repondre(self, user, topic_id, corps, ip=None): self._exiger(user, "repondre") @@ -452,6 +455,7 @@ class Forum: self._post(post_id) self.con.execute("UPDATE posts SET hidden=? WHERE id=?", (int(masque), post_id)) self.con.commit() + self.version += 1 def masquer_sujet(self, user, topic_id, masque=True): self._exiger(user, "masquer") @@ -460,6 +464,7 @@ class Forum: raise Refus("le Bulletin de la semaine ne se masque pas") self.con.execute("UPDATE topics SET hidden=? WHERE id=?", (int(masque), topic_id)) self.con.commit() + self.version += 1 def verrouiller(self, user, topic_id, verrou=True): self._exiger(user, "verrouiller") @@ -467,6 +472,64 @@ class Forum: self.con.execute("UPDATE topics SET locked=? WHERE id=?", (int(verrou), topic_id)) self.con.commit() + # --- fiche publique d'une station (page station de vercors.me) ------ + def _photo_de_station(self, attachment_id): + r = self.con.execute( + "SELECT a.id, a.post_id, p.topic_id, p.hidden AS message_masque, t.station, t.status, t.hidden AS sujet_masque" + " FROM attachments a JOIN posts p ON p.id=a.post_id JOIN topics t ON t.id=p.topic_id WHERE a.id=?", + (attachment_id,)).fetchone() + if r is None: + raise Invalide("photo introuvable") + if not r["station"]: + raise Invalide("cette photo n'est pas dans le sujet d'une station") + return r + + def peut_epingler_photo(self, user, station): + """Propriétaire et adjoint : toutes les stations ; propriétaire de station : la sienne seulement.""" + rs = self.roles_de(user) + if not station or not roles.peut(rs, "epingler_photo_fiche"): + return False + return bool(rs & roles.PROPRIOS) or station in self.stations_de(user) + + def epingler_photo(self, user, attachment_id, epingle=True): + """Épingle (ou retire) une photo du sujet de la station sur sa fiche publique, FICHE_PHOTOS_MAX au plus.""" + ph = self._photo_de_station(attachment_id) + if not self.peut_epingler_photo(user, ph["station"]): + raise Refus("épingler une photo de cette station") + if epingle: + if ph["status"] != "publie" or ph["sujet_masque"] or ph["message_masque"]: + raise Invalide("seule une photo publiée peut aller sur la fiche") + if self.con.execute("SELECT 1 FROM fiche_photos WHERE attachment_id=?", (attachment_id,)).fetchone(): + return ph["topic_id"], ph["post_id"] + n = self.con.execute("SELECT COUNT(*) FROM fiche_photos WHERE station=?", (ph["station"],)).fetchone()[0] + if n >= FICHE_PHOTOS_MAX: + raise Refus("%d photos au plus sur la fiche ; retires-en une d'abord" % FICHE_PHOTOS_MAX) + self.con.execute("INSERT INTO fiche_photos(attachment_id, station, pinned_by) VALUES (?, ?, ?)", + (attachment_id, ph["station"], user["id"])) + else: + self.con.execute("DELETE FROM fiche_photos WHERE attachment_id=?", (attachment_id,)) + self.con.commit() + self.version += 1 + return ph["topic_id"], ph["post_id"] + + def photos_fiche_ids(self, station): + return {r[0] for r in self.con.execute("SELECT attachment_id FROM fiche_photos WHERE station=?", (station,))} + + def fiche_station(self, station): + """Lecture publique : sujet publié de la station et ses photos épinglées encore visibles.""" + if station not in self.stations: + raise Invalide("station inconnue") + t = self.con.execute("SELECT id FROM topics WHERE station=? AND status='publie' AND hidden=0", + (station,)).fetchone() + photos_ = [] + if t is not None: + photos_ = [{"fichier": os.path.basename(r["stored_path"]), "auteur": r["auteur"]} for r in self.con.execute( + "SELECT a.stored_path, u.display_name AS auteur FROM fiche_photos f" + " JOIN attachments a ON a.id=f.attachment_id JOIN posts p ON p.id=a.post_id JOIN users u ON u.id=p.author_id" + " WHERE f.station=? AND p.topic_id=? AND p.hidden=0 ORDER BY f.pinned_at, f.attachment_id LIMIT ?", + (station, t["id"], FICHE_PHOTOS_MAX))] + return {"station": station, "sujet": t["id"] if t is not None else None, "photos": photos_} + # --- RGPD ---------------------------------------------------------- def purger_ips(self, mois=12): """Efface les adresses IP de plus de `mois` mois (obligation légale : un an). Retourne le nombre de lignes.""" diff --git a/forum/roles.py b/forum/roles.py index 4653dd8..136d450 100644 --- a/forum/roles.py +++ b/forum/roles.py @@ -44,6 +44,7 @@ DROITS = { "creer_sujet_station": {STATION}, "valider_sujet": PROPRIOS, "epingler": PROPRIOS, # décision de Théo : pas les modérateurs + "epingler_photo_fiche": PROPRIOS | {STATION}, # propriétaire de station : seulement pour SA station "demander_adhesion": {MEMBRE}, "valider_adhesion": PROPRIOS, "masquer": {MODERATEUR} | PROPRIOS, diff --git a/forum/server.py b/forum/server.py index 481375d..ac02a64 100644 --- a/forum/server.py +++ b/forum/server.py @@ -24,6 +24,8 @@ import json import os import re import sys +import threading +import time from http import cookies from http.server import BaseHTTPRequestHandler, ThreadingHTTPServer from urllib.parse import parse_qs, urlparse @@ -31,7 +33,7 @@ from urllib.parse import parse_qs, urlparse sys.path.insert(0, os.path.dirname(os.path.abspath(__file__))) import connexion # noqa: E402 import roles # noqa: E402 -from forum import OCTETS_MAX, PHOTOS_MAX, SESSION_JOURS, ETAT_MINUTES, Forum, Invalide, Refus # noqa: E402 +from forum import FICHE_PHOTOS_MAX, OCTETS_MAX, PHOTOS_MAX, SESSION_JOURS, ETAT_MINUTES, Forum, Invalide, Refus # noqa: E402 SESSION = "forum_session" ETAT = "forum_etat" @@ -40,6 +42,8 @@ ID_OK = re.compile(r"^[A-Za-z0-9_.-]{1,40}$") PHOTO_OK = re.compile(r"^[0-9a-f]{64}\.(jpg|png|webp)$") CORPS_MAX_REQUETE = 30 * 1024 * 1024 # au-delà, refus (sauf propriétaires : 300 Mo) TYPES_IMG = {"jpg": "image/jpeg", "png": "image/png", "webp": "image/webp"} +STATION_JSON = re.compile(r"/api/station/([a-z0-9-]{1,40})\.json") +FICHE_CACHE_S = 60 # cache mémoire de la route publique des fiches (vidé à chaque changement) CSS = """ :root{color-scheme:light;--sapin:#1f4d3a;--mousse:#6f8f5c;--calcaire:#f5f3ee;--pierre:#e4e0d6;--roche:#2b2f2c;--glacier:#6eb5bd;--gris:#5d635e} @@ -78,6 +82,8 @@ h2{font-family:Bitter,Georgia,serif;color:var(--sapin);font-size:21px;margin:30p .msg.cache{border-left:3px solid var(--gris)} .galerie{display:grid;grid-template-columns:repeat(auto-fill,minmax(min(100%,130px),1fr));gap:8px;margin:12px 0;max-width:640px} .galerie img{display:block;width:100%;aspect-ratio:4/3;object-fit:cover;border:1px solid var(--pierre)} +.galerie figure{margin:0;min-width:0}.galerie figure form{margin:4px 0 0}.galerie figure button{font-size:12px;padding:3px 8px;width:100%} +.galerie .sur-fiche img{outline:2px solid var(--sapin);outline-offset:1px} form{margin:14px 0}label{display:block;margin:8px 0 3px;font-size:14px} input,select,textarea,button{font:inherit;border:1px solid var(--roche);padding:7px 9px;background:#fff;color:var(--roche);max-width:100%} textarea{width:100%;min-height:120px}input[type=text]{width:100%} @@ -243,11 +249,20 @@ def signalements_html(forum, acteur, lien): return "".join(cartes) or etat_vide("Aucun signalement à examiner.") -def galerie_html(photos, dossier): +def galerie_html(photos, dossier, fiche=None): + """fiche : ensemble des photos déjà sur la fiche de la station si l'utilisateur peut les épingler, sinon None.""" vignettes = [] for photo in photos: url = dossier + "/" + os.path.basename(photo["stored_path"]) - vignettes.append("%s" % (e(url), e(url), e(photo["filename"]))) + img = "%s" % (e(url), e(url), e(photo["filename"])) + if fiche is None: + vignettes.append(img) + continue + sur = photo["id"] in fiche + vignettes.append("%s
" + "
" + % (" class='sur-fiche'" if sur else "", img, photo["id"], 0 if sur else 1, "true" if sur else "false", + "Retirer de la fiche" if sur else "Épingler sur la fiche")) return "
%s
" % "".join(vignettes) if vignettes else "" @@ -268,6 +283,24 @@ class App: def __init__(self, forum, reglages): self.forum = forum self.reglages = reglages + self.fiches = {} # (station, préfixe) -> (version du forum, instant, octets JSON) + self.verrou = threading.Lock() + + def fiche_json(self, station, prefixe): + """Fiche publique d'une station, en cache mémoire FICHE_CACHE_S secondes et vidée à chaque changement.""" + cle, maintenant = (station, prefixe), time.monotonic() + with self.verrou: + c = self.fiches.get(cle) + if c and c[0] == self.forum.version and maintenant - c[1] < FICHE_CACHE_S: + return c[2] + d = self.forum.fiche_station(station) + corps = json.dumps({ + "station": station, + "sujet": prefixe + "/t/%d" % d["sujet"] if d["sujet"] else None, + "photos": [{"url": prefixe + "/photo/" + p["fichier"], "auteur": p["auteur"]} for p in d["photos"]], + }, ensure_ascii=False, separators=(",", ":")).encode("utf-8") + self.fiches[cle] = (self.forum.version, maintenant, corps) + return corps def _cookie(nom, valeur, age, chemin="/", secure=True): @@ -533,8 +566,14 @@ class Handler(BaseHTTPRequestHandler): out.append("

Signalement pris en compte.

") if not msgs: out.append(etat_vide("Aucun message visible dans ce sujet.")) + fiche = None + if t["station"] and t["status"] == "publie" and f.peut_epingler_photo(user, t["station"]): + fiche = f.photos_fiche_ids(t["station"]) + out.append("

Fiche de la station sur vercors.me : %d photo%s épinglée%s sur %d. " + "Choisis-les avec « Épingler sur la fiche » sous chaque photo.

" + % (len(fiche), "s" if len(fiche) > 1 else "", "s" if len(fiche) > 1 else "", FICHE_PHOTOS_MAX)) for m in msgs: - gal = galerie_html(f.photos_de(m["id"]), "/photo") + gal = galerie_html(f.photos_de(m["id"]), "/photo", None if fiche is None or m["hidden"] else fiche) outils = "" if roles.peut(rs, "signaler") and not m["hidden"]: outils += ("
Signaler le message
" @@ -636,6 +675,16 @@ class Handler(BaseHTTPRequestHandler): return self.envoyer(404, "introuvable", "text/plain; charset=utf-8") self.fichier_image(chemin, nom) + def fiche_station(self, station): + """GET /api/station/.json : lecture seule, publique, sans cookie ni donnée personnelle hors pseudo public.""" + try: + corps = self.app.fiche_json(station, self.prefixe) + except Invalide: + return self.envoyer(404, b'{"erreur":"station inconnue"}', "application/json; charset=utf-8", + [("Cache-Control", "public, max-age=300")]) + self.envoyer(200, corps, "application/json; charset=utf-8", + [("Cache-Control", "public, max-age=300"), ("Access-Control-Allow-Origin", "*")]) + def photo_adhesion(self, user, nom): if not PHOTO_OK.match(nom): return self.envoyer(404, "introuvable", "text/plain; charset=utf-8") @@ -669,6 +718,9 @@ class Handler(BaseHTTPRequestHandler): m = re.fullmatch(r"/photo/([^/]+)", u.path) if m: return self.photo(m.group(1)) + m = STATION_JSON.fullmatch(u.path) + if m: + return self.fiche_station(m.group(1)) m = re.fullmatch(r"/adhesion-photo/([^/]+)", u.path) if m: return self.photo_adhesion(user, m.group(1)) @@ -728,6 +780,9 @@ class Handler(BaseHTTPRequestHandler): tid = int(d.get("sujet", "0")) f.epingler(user, tid, d.get("etat") == "1") return self.rediriger("/t/%d" % tid) + if chemin == "/fiche-photo": + tid, pid = f.epingler_photo(user, int(d.get("photo", "0")), d.get("etat") == "1") + return self.rediriger("/t/%d#message-%d" % (tid, pid)) if chemin == "/signaler": pid = int(d.get("post", "0")) tid = f._post(pid)["topic_id"] diff --git a/forum/tests/test_forum.py b/forum/tests/test_forum.py index 0af2180..7c697e8 100644 --- a/forum/tests/test_forum.py +++ b/forum/tests/test_forum.py @@ -24,7 +24,7 @@ import panneau # noqa: E402 import photos # noqa: E402 import roles # noqa: E402 import server # noqa: E402 -from forum import EPINGLES_MAX, Forum, Invalide, Refus # noqa: E402 +from forum import EPINGLES_MAX, FICHE_PHOTOS_MAX, Forum, Invalide, Refus # noqa: E402 STATIONS = {"geve": "Gêve", "oscence": "Combe de l'Oscence"} @@ -200,6 +200,65 @@ class TestPhotos(Base): self.assertEqual(len(self.f.photos_de(p)), 12) +class TestFichePhotos(Base): + """Photos du sujet de station épinglées sur la fiche publique de vercors.me (3 au plus).""" + def sujet_geve(self, n=4): + t = self.f.creer_sujet_station(self.prop, "geve", "Ma station") + self.f.valider_sujet(self.theo, t) + p = self.f.repondre(self.prop, t, "Photos de la station") + ids = self.f.ajouter_photos(self.prop, p, [("p%d.png" % i, png() + bytes([i])) for i in range(n)]) + return t, p, ids + + def test_qui_epingle(self): + t, p, ids = self.sujet_geve() + self.f.epingler_photo(self.prop, ids[0]) # propriétaire de la station + self.f.epingler_photo(self.pere, ids[1]) # adjoint + self.f.epingler_photo(self.theo, ids[2]) # propriétaire + for qui in (self.membre, self.modo, self.adh, None): + with self.assertRaises(Refus): + self.f.epingler_photo(qui, ids[3]) + autre = self.f.utilisateur("s2", "Oscar") + self.f.donner_role(self.theo, "s2", roles.STATION, "oscence") + with self.assertRaises(Refus): # propriétaire d'une autre station + self.f.epingler_photo(autre, ids[0], False) + self.assertEqual(self.f.photos_fiche_ids("geve"), set(ids[:3])) + + def test_trois_au_plus_et_retrait(self): + t, p, ids = self.sujet_geve() + for i in ids[:FICHE_PHOTOS_MAX]: + self.f.epingler_photo(self.prop, i) + self.f.epingler_photo(self.prop, ids[0]) # déjà épinglée : sans effet + with self.assertRaises(Refus): + self.f.epingler_photo(self.prop, ids[3]) + self.f.epingler_photo(self.prop, ids[0], False) + self.f.epingler_photo(self.prop, ids[3]) + self.assertEqual(len(self.f.fiche_station("geve")["photos"]), 3) + + def test_hors_sujet_de_station_refuse(self): + t = self.f.creer_sujet(self.adh, "Neige", "x") + p = self.f.repondre(self.adh, t, "photo") + i = self.f.ajouter_photos(self.adh, p, [("a.png", png())])[0] + with self.assertRaises(Invalide): + self.f.epingler_photo(self.theo, i) + with self.assertRaises(Invalide): + self.f.epingler_photo(self.theo, 9999) + + def test_fiche_publique(self): + self.assertEqual(self.f.fiche_station("geve"), {"station": "geve", "sujet": None, "photos": []}) + with self.assertRaises(Invalide): + self.f.fiche_station("inconnue") + t, p, ids = self.sujet_geve(2) + self.f.epingler_photo(self.prop, ids[1]) + self.f.epingler_photo(self.prop, ids[0]) + d = self.f.fiche_station("geve") + self.assertEqual(d["sujet"], t) + self.assertEqual([x["auteur"] for x in d["photos"]], ["Sam", "Sam"]) + self.f.masquer_message(self.modo, p) # message masqué : ses photos quittent la fiche + self.assertEqual(self.f.fiche_station("geve")["photos"], []) + self.f.masquer_sujet(self.modo, t) # sujet masqué : plus de lien + self.assertEqual(self.f.fiche_station("geve")["sujet"], None) + + class TestModeration(Base): def test_signalement_et_masquage(self): t = self.f.creer_sujet(self.adh, "Sujet", "x") @@ -631,6 +690,50 @@ class TestAdhesionHTTP(BaseHTTP): self.assertIn(roles.ADHERENT, self.f.roles_de(self.membre)) +class TestFicheHTTP(BaseHTTP): + def setUp(self): + super().setUp() + self.reglages.prefixe = "/forum" + self.t = self.f.creer_sujet_station(self.prop, "geve", "Ma station") + self.f.valider_sujet(self.theo, self.t) + self.p = self.f.repondre(self.prop, self.t, "Photos") + self.ids = self.f.ajouter_photos(self.prop, self.p, [("a.png", png()), ("b.png", png(False))]) + + def test_route_json_publique_et_cache(self): + st, h, b = self.req("/forum/api/station/geve.json") + self.assertEqual(st, 200) + self.assertTrue(h["Content-Type"].startswith("application/json")) + self.assertIn("max-age=300", h["Cache-Control"]) + self.assertIsNone(h["Set-Cookie"]) + d = json.loads(b) + self.assertEqual(d, {"station": "geve", "sujet": "/forum/t/%d" % self.t, "photos": []}) + self.f.epingler_photo(self.prop, self.ids[0]) # le cache est vidé au changement + d = json.loads(self.req("/api/station/geve.json")[2]) + self.assertEqual(len(d["photos"]), 1) + url = d["photos"][0]["url"] + self.assertTrue(url.startswith("/forum/photo/"), url) + st, _, img = self.req(url) + self.assertEqual(st, 200) + self.assertNotIn(b"GPS", img) # photo déjà nettoyée à l'envoi + self.assertEqual(self.req("/forum/api/station/inconnue.json")[0], 404) + self.assertEqual(self.req("/forum/api/station/../db.json")[0], 404) + self.assertEqual(self.req("/forum/api/station/geve.json", corps=b"x=1")[0], 403) # lecture seule + + def test_boutons_et_epinglage(self): + chemin = "/forum/t/%d" % self.t + self.assertIn("action='/forum/fiche-photo'", self.req(chemin, "s1")[2].decode()) + self.assertIn("action='/forum/fiche-photo'", self.req(chemin, "pere")[2].decode()) + self.assertNotIn("fiche-photo", self.req(chemin, "m1")[2].decode()) + self.assertNotIn("fiche-photo", self.req(chemin, "mo1")[2].decode()) + self.assertNotIn("fiche-photo", self.req(chemin)[2].decode()) + st, h, _ = self.req("/forum/fiche-photo", "s1", ("photo=%d&etat=1" % self.ids[1]).encode()) + self.assertEqual((st, h["Location"]), (303, "/forum/t/%d#message-%d" % (self.t, self.p))) + self.assertIn("Retirer de la fiche", self.req(chemin, "s1")[2].decode()) + self.assertEqual(self.req("/forum/fiche-photo", "m1", ("photo=%d&etat=1" % self.ids[0]).encode())[0], 403) + self.assertEqual(self.req("/forum/fiche-photo", "s1", ("photo=%d&etat=1" % self.ids[0]).encode(), origine=False)[0], 403) + self.assertEqual(self.f.photos_fiche_ids("geve"), {self.ids[1]}) + + class TestPrefixe(BaseHTTP): def setUp(self): super().setUp()