forum v2 : rôles cumulables (propriétaire, adjoint, modérateur, adhérent, propriétaire de station), Bulletin de la semaine fixe, sujets épinglés (5 max), sujets de station à valider, photos sans métadonnées (10 photos / 25 Mo), pages aux couleurs du site ; 18 tests

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Cette révision appartient à :
Théo GastineletClaude Opus 5.5 a révisé 2026-11-04 15:16:57 +01:00
1 Parent c671a363c7
révision cc63ba1528
8 fichiers modifiés
+970 -492

Aucun fichier ne correspond à votre recherche

+38 -23
Voir le fichier
@@ -1,30 +1,35 @@
"""Schéma SQLite et accès aux données."""
"""Schéma SQLite et accès aux données (version 2 : rôles cumulables, sujets épinglés, photos)."""
import sqlite3
SCHEMA = """
CREATE TABLE IF NOT EXISTS users (
id INTEGER PRIMARY KEY,
hub_id TEXT NOT NULL UNIQUE, -- identifiant du compte Gastinel (Hub)
display_name TEXT NOT NULL,
role TEXT NOT NULL DEFAULT 'membre'
CHECK (role IN ('membre','adherent','moderateur','admin')),
display_name TEXT NOT NULL, -- pseudo du compte Gastinel
created_at TEXT NOT NULL DEFAULT (datetime('now'))
);
CREATE TABLE IF NOT EXISTS categories (
id INTEGER PRIMARY KEY,
slug TEXT NOT NULL UNIQUE,
name TEXT NOT NULL,
min_role_topic TEXT NOT NULL DEFAULT 'adherent',
position INTEGER NOT NULL DEFAULT 0
-- Rôles cumulables ; « membre » est implicite pour tout compte. station : id de station pour proprietaire_station.
CREATE TABLE IF NOT EXISTS user_roles (
user_id INTEGER NOT NULL REFERENCES users(id),
role TEXT NOT NULL CHECK (role IN ('adherent','moderateur','proprietaire','proprietaire_adjoint','proprietaire_station')),
station TEXT NOT NULL DEFAULT '',
given_by INTEGER REFERENCES users(id),
given_at TEXT NOT NULL DEFAULT (datetime('now')),
PRIMARY KEY (user_id, role, station)
);
CREATE TABLE IF NOT EXISTS topics (
id INTEGER PRIMARY KEY,
category_id INTEGER NOT NULL REFERENCES categories(id),
title TEXT NOT NULL,
author_id INTEGER NOT NULL REFERENCES users(id),
created_at TEXT NOT NULL DEFAULT (datetime('now')),
locked INTEGER NOT NULL DEFAULT 0,
hidden INTEGER NOT NULL DEFAULT 0
hidden INTEGER NOT NULL DEFAULT 0,
fixed INTEGER NOT NULL DEFAULT 0, -- sujet fixe (Bulletin de la semaine) : toujours épinglé en tête
pinned INTEGER NOT NULL DEFAULT 0,
pin_pos INTEGER NOT NULL DEFAULT 0,
replies_open INTEGER NOT NULL DEFAULT 1, -- 0 : seuls les rôles « publier_bulletin » écrivent
status TEXT NOT NULL DEFAULT 'publie' CHECK (status IN ('publie','en_attente','refuse')),
station TEXT -- sujet d'une station (propriétaire de station)
);
CREATE TABLE IF NOT EXISTS posts (
id INTEGER PRIMARY KEY,
@@ -34,7 +39,17 @@ CREATE TABLE IF NOT EXISTS posts (
created_at TEXT NOT NULL DEFAULT (datetime('now')),
edited_at TEXT,
hidden INTEGER NOT NULL DEFAULT 0,
ip TEXT -- purgée après 13 mois (purger_ips)
ip TEXT -- obligation légale (un an), purgée ensuite (purger_ips)
);
CREATE TABLE IF NOT EXISTS attachments (
id INTEGER PRIMARY KEY,
post_id INTEGER NOT NULL REFERENCES posts(id),
filename TEXT NOT NULL,
mime TEXT NOT NULL,
size INTEGER NOT NULL,
sha256 TEXT NOT NULL,
stored_path TEXT NOT NULL,
created_at TEXT NOT NULL DEFAULT (datetime('now'))
);
CREATE TABLE IF NOT EXISTS reports (
id INTEGER PRIMARY KEY,
@@ -44,16 +59,14 @@ CREATE TABLE IF NOT EXISTS reports (
created_at TEXT NOT NULL DEFAULT (datetime('now')),
UNIQUE (post_id, reporter_id)
);
-- Prévu plus tard : attachments(id, post_id, filename, mime, size, sha256, stored_path)
CREATE INDEX IF NOT EXISTS idx_topics_cat ON topics(category_id, id DESC);
CREATE INDEX IF NOT EXISTS idx_topics_liste ON topics(pinned DESC, pin_pos, id DESC);
CREATE INDEX IF NOT EXISTS idx_posts_topic ON posts(topic_id, id);
CREATE INDEX IF NOT EXISTS idx_attach_post ON attachments(post_id);
CREATE UNIQUE INDEX IF NOT EXISTS idx_un_sujet_par_station ON topics(station) WHERE station IS NOT NULL AND status <> 'refuse';
"""
CATEGORIES_DEFAUT = [
("recapitulatif-semaine", "Récapitulatif de la semaine", "adherent", 0),
("observations", "Observations", "adherent", 1),
("discussion", "Discussion générale", "adherent", 2),
]
SYSTEME = "systeme" # compte technique, auteur du sujet fixe
BULLETIN = "Bulletin de la semaine du Vercors"
def connecter(chemin=":memory:"):
@@ -61,8 +74,10 @@ def connecter(chemin=":memory:"):
con.row_factory = sqlite3.Row
con.execute("PRAGMA foreign_keys = ON")
con.executescript(SCHEMA)
for slug, nom, role, pos in CATEGORIES_DEFAUT:
con.execute("INSERT OR IGNORE INTO categories(slug,name,min_role_topic,position)"
" VALUES (?,?,?,?)", (slug, nom, role, pos))
con.execute("INSERT OR IGNORE INTO users(hub_id, display_name) VALUES (?, ?)", (SYSTEME, "vercors.me"))
if con.execute("SELECT 1 FROM topics WHERE fixed=1").fetchone() is None:
sid = con.execute("SELECT id FROM users WHERE hub_id=?", (SYSTEME,)).fetchone()[0]
con.execute("INSERT INTO topics(title, author_id, fixed, pinned, pin_pos, replies_open)"
" VALUES (?, ?, 1, 1, 0, 0)", (BULLETIN, sid))
con.commit()
return con