feat(backend): sprint 5 — SimulationTemplate CRUD + instantiation
- SimulationTemplate model + migration 0005 (CREATE TABLE + name index) - 5 CRUD endpoints under /api/templates (admin|redteam only, SOC 403) - POST /api/engagements/<eid>/simulations extended with optional template_id - serialize_template() reusing _enrich_techniques/_enrich_tactics helpers - IntegrityError → 409 for duplicate name on both POST and PATCH - 28 new tests (CRUD, RBAC, dedup, instantiation, migration round-trip) - 221 tests pass; ruff clean; mypy clean Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
32
backend/app/models/simulation_template.py
Normal file
32
backend/app/models/simulation_template.py
Normal file
@@ -0,0 +1,32 @@
|
||||
"""SimulationTemplate model."""
|
||||
from __future__ import annotations
|
||||
|
||||
from datetime import UTC, datetime
|
||||
|
||||
from backend.app.extensions import db
|
||||
|
||||
|
||||
class SimulationTemplate(db.Model): # type: ignore[name-defined]
|
||||
__tablename__ = "simulation_templates"
|
||||
|
||||
id = db.Column(db.Integer, primary_key=True)
|
||||
name = db.Column(db.String(255), nullable=False, unique=True)
|
||||
description = db.Column(db.Text, nullable=True)
|
||||
commands = db.Column(db.Text, nullable=True)
|
||||
prerequisites = db.Column(db.Text, nullable=True)
|
||||
techniques = db.Column(db.JSON, nullable=False, default=list)
|
||||
tactic_ids = db.Column(db.JSON, nullable=False, default=list)
|
||||
created_at = db.Column(
|
||||
db.DateTime, nullable=False, default=lambda: datetime.now(UTC)
|
||||
)
|
||||
updated_at = db.Column(db.DateTime, nullable=True)
|
||||
created_by_id = db.Column(
|
||||
db.Integer,
|
||||
db.ForeignKey("users.id", ondelete="RESTRICT"),
|
||||
nullable=False,
|
||||
)
|
||||
|
||||
created_by = db.relationship("User", lazy="joined")
|
||||
|
||||
def __repr__(self) -> str:
|
||||
return f"<SimulationTemplate {self.id} {self.name!r}>"
|
||||
Reference in New Issue
Block a user