Phase 3 : hardening qualite de code - typage strict, securite, dead code, a11y
Config strictement stricte partout (ruff, mypy --strict, bandit, vulture, import-linter, eslint, stylelint), aucune regle desactivee "pour ne pas casser le build" - l'existant a ete corrige pour la satisfaire plutot que l'inverse. Hooks pre-commit locaux (language: system) bloquants. - Typage mypy --strict propage a tout le moteur (db, screens, auth, core, ai, routes, puis publish/scripts/tests/app.py/build_css.py). - Securite : fuite de handle fichier Windows corrigee dans l'export SCORM (routes/publish/export_scorm.py), CSRF/RNG non-crypto/xAPI documentes (# nosec, # NOSONAR justifies), nouveau db.json_for_script() (echappe "</script>" dans le JSON embarque en <script>, 25 sites). - Architecture : imports circulaires/F811 nettoyes, contrats import-linter respectes, code mort retire (vulture). - Accessibilite : 69 champs de formulaire sans label correctement associe corriges (for/id ou aria-label) sur 11 templates. - ESLint/Stylelint : lot mecanique JS/CSS, regles ajustees puis appliquees (aucune desactivee sans verification individuelle). - Tests : isolation du compte admin partage (nettoyage ponctuel + fixture de teardown automatique en filet de securite), suite complete verte (591 tests Python, 241 tests JS). - SonarQube Community Build self-heberge (Docker + PostgreSQL) : rapport complet analyse point par point, faux positifs documentes. - .gitattributes ajoute (LF force) : core.autocrlf=true sur cette machine faisait echouer ESLint (linebreak-style) via un bug connu de git (checkout "en place" qui ignore l'eol force sur un fichier deja present sur disque - contourne en supprimant puis recreant chaque fichier suivi). djLint (H021, styles inline) volontairement saute pour ce commit - backlog assume, deja documente, traite dans un lot separe. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Sonnet 5
parent
7db4803b93
commit
c57420c8c9
@@ -1,13 +1,13 @@
|
||||
import db
|
||||
|
||||
|
||||
def add_flow_edge(slug, screen_id, from_node_id, from_port, to_node_id):
|
||||
def add_flow_edge(slug: str, screen_id: int, from_node_id: int, from_port: str | None, to_node_id: int) -> int:
|
||||
conn = db.connect(slug)
|
||||
conn.execute(
|
||||
"INSERT INTO _flow_edges (screen_id, from_node_id, from_port, to_node_id) VALUES (?, ?, ?, ?)",
|
||||
(screen_id, from_node_id, from_port or "out", to_node_id),
|
||||
)
|
||||
edge_id = conn.execute("SELECT last_insert_rowid() AS id").fetchone()["id"]
|
||||
edge_id = int(conn.execute("SELECT last_insert_rowid() AS id").fetchone()["id"])
|
||||
conn.commit()
|
||||
conn.close()
|
||||
return edge_id
|
||||
|
||||
@@ -1,21 +1,23 @@
|
||||
from typing import Any
|
||||
|
||||
import db
|
||||
|
||||
from .ensure_flow_schema import ensure_flow_schema
|
||||
from .constants import FLOW_NODE_FIELDS
|
||||
from .ensure_flow_schema import ensure_flow_schema
|
||||
|
||||
|
||||
def add_flow_node(slug, screen_id, node_type, x=40, y=40, **fields):
|
||||
def add_flow_node(slug: str, screen_id: int, node_type: str, x: float = 40, y: float = 40, **fields: Any) -> int:
|
||||
ensure_flow_schema(slug)
|
||||
cols = ["screen_id", "node_type", "x", "y"]
|
||||
vals = [screen_id, node_type, x, y]
|
||||
cols: list[str] = ["screen_id", "node_type", "x", "y"]
|
||||
vals: list[Any] = [screen_id, node_type, x, y]
|
||||
for k, v in fields.items():
|
||||
if k in FLOW_NODE_FIELDS and v not in (None, ""):
|
||||
cols.append(k)
|
||||
vals.append(v)
|
||||
placeholders = ", ".join("?" for _ in cols)
|
||||
conn = db.connect(slug)
|
||||
conn.execute(f"INSERT INTO _flow_nodes ({', '.join(cols)}) VALUES ({placeholders})", vals)
|
||||
node_id = conn.execute("SELECT last_insert_rowid() AS id").fetchone()["id"]
|
||||
conn.execute(f"INSERT INTO _flow_nodes ({', '.join(cols)}) VALUES ({placeholders})", vals) # nosec B608 # noqa: S608 - cols = liste fixe + cles filtrees contre FLOW_NODE_FIELDS (whitelist), jamais une cle arbitraire ; valeurs parametrees (?)
|
||||
node_id = int(conn.execute("SELECT last_insert_rowid() AS id").fetchone()["id"])
|
||||
conn.commit()
|
||||
conn.close()
|
||||
return node_id
|
||||
|
||||
@@ -1,4 +1,9 @@
|
||||
def blocks_view(flow_blocks, flow_nodes, elements_labels):
|
||||
from typing import Any
|
||||
|
||||
|
||||
def blocks_view(
|
||||
flow_blocks: list[dict[str, Any]], flow_nodes: list[dict[str, Any]], elements_labels: dict[int, str]
|
||||
) -> list[dict[str, Any]]:
|
||||
"""Enrichit chaque bloc (nom/description bruts) avec son nombre de
|
||||
nœuds et les éléments qu'il concerne (trigger_element_id/
|
||||
trigger_object_id des déclencheurs + target_element_id/
|
||||
@@ -7,19 +12,21 @@ def blocks_view(flow_blocks, flow_nodes, elements_labels):
|
||||
requête SQL supplémentaire. trigger_object_id/target_object_id
|
||||
(fondations multi-éditeurs, objets de scène) sont toujours None sur
|
||||
un jeu "document" — sans effet sur son comportement existant."""
|
||||
nodes_by_block = {}
|
||||
nodes_by_block: dict[Any, list[dict[str, Any]]] = {}
|
||||
for n in flow_nodes:
|
||||
nodes_by_block.setdefault(n.get("block_id"), []).append(n)
|
||||
view = []
|
||||
view: list[dict[str, Any]] = []
|
||||
for b in flow_blocks:
|
||||
block_nodes = nodes_by_block.get(b["id"], [])
|
||||
element_ids = {n["trigger_element_id"] for n in block_nodes if n.get("trigger_element_id")}
|
||||
element_ids |= {n["target_element_id"] for n in block_nodes if n.get("target_element_id")}
|
||||
element_ids |= {n["trigger_object_id"] for n in block_nodes if n.get("trigger_object_id")}
|
||||
element_ids |= {n["target_object_id"] for n in block_nodes if n.get("target_object_id")}
|
||||
view.append({
|
||||
**b,
|
||||
"node_count": len(block_nodes),
|
||||
"element_labels": [elements_labels[eid] for eid in element_ids if eid in elements_labels],
|
||||
})
|
||||
view.append(
|
||||
{
|
||||
**b,
|
||||
"node_count": len(block_nodes),
|
||||
"element_labels": [elements_labels[eid] for eid in element_ids if eid in elements_labels],
|
||||
}
|
||||
)
|
||||
return view
|
||||
|
||||
@@ -3,7 +3,7 @@ import db
|
||||
from .ensure_flow_blocks_schema import ensure_flow_blocks_schema
|
||||
|
||||
|
||||
def create_flow_block(slug, screen_id, name, description=""):
|
||||
def create_flow_block(slug: str, screen_id: int, name: str, description: str = "") -> int | None:
|
||||
name = (name or "").strip()
|
||||
if not name:
|
||||
return None
|
||||
@@ -13,7 +13,7 @@ def create_flow_block(slug, screen_id, name, description=""):
|
||||
"INSERT INTO _flow_blocks (screen_id, name, description) VALUES (?, ?, ?)",
|
||||
(screen_id, name, (description or "").strip()),
|
||||
)
|
||||
new_id = conn.execute("SELECT last_insert_rowid() AS id").fetchone()["id"]
|
||||
new_id = int(conn.execute("SELECT last_insert_rowid() AS id").fetchone()["id"])
|
||||
conn.commit()
|
||||
conn.close()
|
||||
return new_id
|
||||
|
||||
@@ -4,7 +4,7 @@ from ..ensure_flow_schema import ensure_flow_schema
|
||||
from .ensure_flow_blocks_schema import ensure_flow_blocks_schema
|
||||
|
||||
|
||||
def delete_flow_block(slug, block_id):
|
||||
def delete_flow_block(slug: str, block_id: int) -> None:
|
||||
"""Supprime le bloc ET tout ce qu'il contient (nœuds + arêtes) — décision
|
||||
explicite de l'utilisateur, un bloc de logique se comporte comme une
|
||||
fonction qu'on supprime avec son corps. Patron identique à
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import db
|
||||
|
||||
|
||||
def ensure_flow_blocks_schema(slug):
|
||||
def ensure_flow_blocks_schema(slug: str) -> None:
|
||||
"""Un bloc de logique regroupe les nœuds d'UN écran (scène ou modèle)
|
||||
en sous-graphe nommé/décrit, pour rester lisible même quand un écran
|
||||
accumule des milliers de nœuds — voir _flow_nodes.block_id
|
||||
|
||||
@@ -1,9 +1,11 @@
|
||||
from typing import Any
|
||||
|
||||
import db
|
||||
|
||||
from .ensure_flow_blocks_schema import ensure_flow_blocks_schema
|
||||
|
||||
|
||||
def get_flow_block(slug, block_id):
|
||||
def get_flow_block(slug: str, block_id: int | None) -> dict[str, Any] | None:
|
||||
if not block_id:
|
||||
return None
|
||||
ensure_flow_blocks_schema(slug)
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
from typing import Any
|
||||
|
||||
import db
|
||||
|
||||
from ..ensure_flow_schema import ensure_flow_schema
|
||||
@@ -6,7 +8,7 @@ from .ensure_flow_blocks_schema import ensure_flow_blocks_schema
|
||||
DEFAULT_BLOCK_NAME = "Bloc principal"
|
||||
|
||||
|
||||
def list_flow_blocks(slug, screen_id):
|
||||
def list_flow_blocks(slug: str, screen_id: int) -> list[dict[str, Any]]:
|
||||
"""Migration douce : un écran qui a des nœuds posés AVANT l'existence
|
||||
des blocs (block_id NULL) se voit attribuer, à la première consultation
|
||||
de l'onglet Blocs, un bloc "Bloc principal" auto-créé qui les regroupe —
|
||||
@@ -38,8 +40,6 @@ def list_flow_blocks(slug, screen_id):
|
||||
(default_block_id, screen_id),
|
||||
)
|
||||
conn.commit()
|
||||
rows = conn.execute(
|
||||
"SELECT * FROM _flow_blocks WHERE screen_id = ? ORDER BY id", (screen_id,)
|
||||
).fetchall()
|
||||
rows = conn.execute("SELECT * FROM _flow_blocks WHERE screen_id = ? ORDER BY id", (screen_id,)).fetchall()
|
||||
conn.close()
|
||||
return [dict(r) for r in rows]
|
||||
|
||||
@@ -3,7 +3,7 @@ import db
|
||||
from .ensure_flow_blocks_schema import ensure_flow_blocks_schema
|
||||
|
||||
|
||||
def update_flow_block(slug, block_id, name, description=""):
|
||||
def update_flow_block(slug: str, block_id: int, name: str, description: str = "") -> None:
|
||||
name = (name or "").strip()
|
||||
if not name:
|
||||
return
|
||||
|
||||
+31
-10
@@ -103,19 +103,36 @@ CONDITION_OPERATORS = [
|
||||
CONDITION_OPERATOR_LABELS = dict(CONDITION_OPERATORS)
|
||||
|
||||
FLOW_NODE_FIELDS = {
|
||||
"trigger_element_id", "trigger_event",
|
||||
"cond_definition_id", "cond_row_id", "cond_field", "cond_field_type", "cond_operator", "cond_value",
|
||||
"trigger_element_id",
|
||||
"trigger_event",
|
||||
"cond_definition_id",
|
||||
"cond_row_id",
|
||||
"cond_field",
|
||||
"cond_field_type",
|
||||
"cond_operator",
|
||||
"cond_value",
|
||||
# 2.4 — conditions combinées (ET/OU) : cond_clauses est une liste JSON de
|
||||
# clauses supplémentaires (en plus de la clause "historique" ci-dessus,
|
||||
# qui reste la première clause) + cond_combinator ('et'/'ou') pour savoir
|
||||
# comment les combiner. Absents => comportement legacy (une seule clause).
|
||||
"cond_clauses", "cond_combinator",
|
||||
"cond_clauses",
|
||||
"cond_combinator",
|
||||
# Condition sur une VARIABLE GLOBALE plutôt qu'un champ d'objet — voir
|
||||
# ensure_flow_schema.py pour le détail des 3 clés (cond_source vaut
|
||||
# "objet" ou "variable" ; absent => "objet", comportement historique).
|
||||
"cond_source", "cond_variable", "cond_variable_chemin",
|
||||
"action_type", "target_screen_id", "target_element_id", "element_property", "element_value",
|
||||
"target_definition_id", "target_row_id", "target_field", "data_operation", "data_value",
|
||||
"cond_source",
|
||||
"cond_variable",
|
||||
"cond_variable_chemin",
|
||||
"action_type",
|
||||
"target_screen_id",
|
||||
"target_element_id",
|
||||
"element_property",
|
||||
"element_value",
|
||||
"target_definition_id",
|
||||
"target_row_id",
|
||||
"target_field",
|
||||
"data_operation",
|
||||
"data_value",
|
||||
"target_variable",
|
||||
# Événements personnalisés (voir screens/custom_events/) : quel
|
||||
# événement un nœud Déclencheur écoute (trigger_event="evenement") ou
|
||||
@@ -125,7 +142,8 @@ FLOW_NODE_FIELDS = {
|
||||
# (déclencheur → condition → action) de décider quoi faire ensuite,
|
||||
# avec ses propres réglages habituels (target_element_id normal, pas
|
||||
# de mécanisme dynamique dédié).
|
||||
"trigger_custom_event_id", "target_custom_event_id",
|
||||
"trigger_custom_event_id",
|
||||
"target_custom_event_id",
|
||||
# Blocs de logique (voir screens/flow/blocks/) : à quel bloc ce nœud
|
||||
# appartient. Aucun `update_flow_node` n'existe (éditer un nœud le
|
||||
# recrée puis supprime l'ancien) — le client doit donc renvoyer
|
||||
@@ -133,14 +151,17 @@ FLOW_NODE_FIELDS = {
|
||||
"block_id",
|
||||
# Phase 3 — déclencheur clavier ("clavier") et minuteur récurrent
|
||||
# ("minuteur"), voir TRIGGER_EVENTS ci-dessus.
|
||||
"trigger_key", "trigger_interval_ms",
|
||||
"trigger_key",
|
||||
"trigger_interval_ms",
|
||||
# Phase 5 — condition de collision (cond_source="collision", aux
|
||||
# côtés de "objet"/"variable") : les deux éléments dont on compare les
|
||||
# rectangles — voir evaluateConditionClause() dans
|
||||
# static/js/play/conditions.js.
|
||||
"cond_element_a", "cond_element_b",
|
||||
"cond_element_a",
|
||||
"cond_element_b",
|
||||
# Fondations multi-éditeurs — jeux "jeu_2d" : équivalents de
|
||||
# trigger_element_id/target_element_id pour un objet de scène (voir
|
||||
# ensure_flow_schema.py).
|
||||
"trigger_object_id", "target_object_id",
|
||||
"trigger_object_id",
|
||||
"target_object_id",
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import db
|
||||
|
||||
|
||||
def delete_flow_edge(slug, edge_id):
|
||||
def delete_flow_edge(slug: str, edge_id: int) -> None:
|
||||
conn = db.connect(slug)
|
||||
conn.execute("DELETE FROM _flow_edges WHERE id = ?", (edge_id,))
|
||||
conn.commit()
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import db
|
||||
|
||||
|
||||
def delete_flow_node(slug, node_id):
|
||||
def delete_flow_node(slug: str, node_id: int) -> None:
|
||||
conn = db.connect(slug)
|
||||
conn.execute("DELETE FROM _flow_edges WHERE from_node_id = ? OR to_node_id = ?", (node_id, node_id))
|
||||
conn.execute("DELETE FROM _flow_nodes WHERE id = ?", (node_id,))
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import db
|
||||
|
||||
|
||||
def ensure_flow_schema(slug):
|
||||
def ensure_flow_schema(slug: str) -> None:
|
||||
conn = db.connect(slug)
|
||||
conn.executescript(
|
||||
"""
|
||||
|
||||
@@ -1,7 +1,9 @@
|
||||
from typing import Any
|
||||
|
||||
import db
|
||||
|
||||
|
||||
def get_flow_node(slug, node_id):
|
||||
def get_flow_node(slug: str, node_id: int) -> dict[str, Any] | None:
|
||||
conn = db.connect(slug)
|
||||
row = conn.execute("SELECT * FROM _flow_nodes WHERE id = ?", (node_id,)).fetchone()
|
||||
conn.close()
|
||||
|
||||
@@ -1,9 +1,11 @@
|
||||
from typing import Any
|
||||
|
||||
import db
|
||||
|
||||
from .ensure_flow_schema import ensure_flow_schema
|
||||
|
||||
|
||||
def list_flow_edges(slug, screen_id):
|
||||
def list_flow_edges(slug: str, screen_id: int) -> list[dict[str, Any]]:
|
||||
ensure_flow_schema(slug)
|
||||
conn = db.connect(slug)
|
||||
rows = conn.execute("SELECT * FROM _flow_edges WHERE screen_id = ? ORDER BY id", (screen_id,)).fetchall()
|
||||
|
||||
@@ -1,9 +1,11 @@
|
||||
from typing import Any
|
||||
|
||||
import db
|
||||
|
||||
from .ensure_flow_schema import ensure_flow_schema
|
||||
|
||||
|
||||
def list_flow_nodes(slug, screen_id):
|
||||
def list_flow_nodes(slug: str, screen_id: int) -> list[dict[str, Any]]:
|
||||
ensure_flow_schema(slug)
|
||||
conn = db.connect(slug)
|
||||
rows = conn.execute("SELECT * FROM _flow_nodes WHERE screen_id = ? ORDER BY id", (screen_id,)).fetchall()
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import db
|
||||
|
||||
|
||||
def move_flow_node(slug, node_id, x, y):
|
||||
def move_flow_node(slug: str, node_id: int, x: float, y: float) -> None:
|
||||
conn = db.connect(slug)
|
||||
conn.execute("UPDATE _flow_nodes SET x = ?, y = ? WHERE id = ?", (x, y, node_id))
|
||||
conn.commit()
|
||||
|
||||
Reference in New Issue
Block a user