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,14 +1,14 @@
|
||||
from flask import g, request, redirect, url_for, jsonify, abort
|
||||
from flask import abort, g, jsonify, redirect, request, url_for
|
||||
from werkzeug.wrappers import Response
|
||||
|
||||
import auth
|
||||
import screens
|
||||
|
||||
from core.flask_app import app
|
||||
from core.sprite_gate import forbid_admin_only_character, forbid_admin_only_background
|
||||
from core.sprite_gate import forbid_admin_only_background, forbid_admin_only_character
|
||||
|
||||
|
||||
@app.route("/game/<slug>/screens/<int:screen_id>/scene-objects/add", methods=["POST"])
|
||||
def scene_object_add(slug, screen_id):
|
||||
def scene_object_add(slug: str, screen_id: int) -> Response:
|
||||
"""Pose un nouvel objet sur la scène — mirror de routes/elements/
|
||||
element_add.py, mais pour _scene_objects (voir screens/scenes/
|
||||
add_scene_object.py).
|
||||
@@ -60,6 +60,7 @@ def scene_object_add(slug, screen_id):
|
||||
# n'en a pas besoin (demande explicite : toujours 200×200 à la
|
||||
# pose, voir add_scene_object.py::_DECOR_DEFAULT_SIZE).
|
||||
import os
|
||||
|
||||
path = os.path.join(auth.user_assets_dir(asset["user_id"]), asset["filename"])
|
||||
try:
|
||||
with open(path, "rb") as fh:
|
||||
@@ -75,10 +76,16 @@ def scene_object_add(slug, screen_id):
|
||||
# visible sur le dessus/le côté). Un "decor"/"personnage" garde lui sa
|
||||
# position de dépôt normale.
|
||||
new_id = screens.add_scene_object(
|
||||
slug, screen_id, kind=kind, forge_character=forge_character,
|
||||
background_slug=background_slug, image_url=image_url,
|
||||
image_width=image_width, image_height=image_height,
|
||||
x=(None if kind == "fond" else drop_x), y=(None if kind == "fond" else drop_y),
|
||||
slug,
|
||||
screen_id,
|
||||
kind=kind,
|
||||
forge_character=forge_character,
|
||||
background_slug=background_slug,
|
||||
image_url=image_url,
|
||||
image_width=image_width,
|
||||
image_height=image_height,
|
||||
x=(None if kind == "fond" else drop_x),
|
||||
y=(None if kind == "fond" else drop_y),
|
||||
)
|
||||
if drop_x is not None and drop_y is not None and kind != "fond":
|
||||
# Ramène dans le cadre de la caméra si le dépôt était trop proche
|
||||
@@ -87,25 +94,42 @@ def scene_object_add(slug, screen_id):
|
||||
# _clamp_to_camera pour l'IA, ici pour un dépôt manuel.
|
||||
obj_for_clamp = screens.get_scene_object(slug, new_id)
|
||||
screen = screens.get_screen(slug, screen_id)
|
||||
assert obj_for_clamp is not None, ( # nosec B101 # noqa: S101 - narrowing de type, sur par construction
|
||||
"new_id vient d'etre cree par screens.add_scene_object juste au-dessus"
|
||||
)
|
||||
assert screen is not None, ( # nosec B101 # noqa: S101 - narrowing de type, sur par construction
|
||||
"screen_id valide : add_scene_object aurait leve IntegrityError sinon (FK scene_id)"
|
||||
)
|
||||
max_x = max(0, screen["scene_width"] - obj_for_clamp["width"])
|
||||
max_y = max(0, screen["scene_height"] - obj_for_clamp["height"])
|
||||
clamped_x = min(max(drop_x, 0), max_x)
|
||||
clamped_y = min(max(drop_y, 0), max_y)
|
||||
if (clamped_x, clamped_y) != (obj_for_clamp["x"], obj_for_clamp["y"]):
|
||||
screens.update_scene_object_geometry(slug, new_id, clamped_x, clamped_y, obj_for_clamp["width"], obj_for_clamp["height"])
|
||||
screens.update_scene_object_geometry(
|
||||
slug, new_id, clamped_x, clamped_y, obj_for_clamp["width"], obj_for_clamp["height"]
|
||||
)
|
||||
if request.headers.get("X-Requested-With") == "fetch":
|
||||
obj = screens.get_scene_object(slug, new_id)
|
||||
return jsonify({
|
||||
"id": new_id, "kind": obj["kind"],
|
||||
"x": obj["x"], "y": obj["y"], "width": obj["width"], "height": obj["height"],
|
||||
"rendered_html": screens.render_scene_object(obj),
|
||||
# Relance l'aperçu animé tout de suite (voir personnage-preview.js
|
||||
# ::restartPersonnageIdlePreview) — sans ça, un personnage
|
||||
# fraîchement posé restait figé sur sa première frame jusqu'au
|
||||
# prochain rechargement de page (qui n'arrive plus jamais, voir
|
||||
# addSceneObject() côté JS).
|
||||
"animations": screens.resolve_personnage_animations(obj) if obj["kind"] == "personnage" else None,
|
||||
})
|
||||
assert obj is not None, ( # nosec B101 # noqa: S101 - narrowing de type, sur par construction
|
||||
"new_id vient d'etre cree par screens.add_scene_object plus haut"
|
||||
)
|
||||
return jsonify(
|
||||
{
|
||||
"id": new_id,
|
||||
"kind": obj["kind"],
|
||||
"x": obj["x"],
|
||||
"y": obj["y"],
|
||||
"width": obj["width"],
|
||||
"height": obj["height"],
|
||||
"rendered_html": screens.render_scene_object(obj),
|
||||
# Relance l'aperçu animé tout de suite (voir personnage-preview.js
|
||||
# ::restartPersonnageIdlePreview) — sans ça, un personnage
|
||||
# fraîchement posé restait figé sur sa première frame jusqu'au
|
||||
# prochain rechargement de page (qui n'arrive plus jamais, voir
|
||||
# addSceneObject() côté JS).
|
||||
"animations": screens.resolve_personnage_animations(obj) if obj["kind"] == "personnage" else None,
|
||||
}
|
||||
)
|
||||
# Même route que l'éditeur document (/game/<slug>/screens/<id>/edit,
|
||||
# endpoint "screen_edit") — c'est CE dispatcher qui bascule vers la
|
||||
# vue de scène selon game_type, voir routes/screens/screen_edit.py.
|
||||
|
||||
Reference in New Issue
Block a user