feat: Phase 3 - CRUD core for Techniques, Tests and Evidence (T-014 to T-017)
- Add Pydantic schemas for Technique, Test and Evidence - Add CRUD endpoints for Techniques (list with filters, detail, create, update, review) - Add CRUD endpoints for Tests (create, detail, update, validate, reject) - Add evidence upload with SHA-256 integrity and presigned download URLs - Add MinIO/S3 storage client with bucket auto-creation on startup - Add status_service to recalculate technique coverage from test results - Add require_any_role RBAC dependency for multi-role authorization - Update README with API endpoints reference and project structure
This commit is contained in:
36
backend/app/services/status_service.py
Normal file
36
backend/app/services/status_service.py
Normal file
@@ -0,0 +1,36 @@
|
||||
"""Service for recalculating the global status of a Technique
|
||||
based on the state and result of its associated tests."""
|
||||
|
||||
from sqlalchemy.orm import Session
|
||||
|
||||
from app.models.enums import TechniqueStatus
|
||||
from app.models.technique import Technique
|
||||
|
||||
|
||||
def recalculate_technique_status(db: Session, technique: Technique) -> None:
|
||||
"""Recompute ``technique.status_global`` from its tests and commit.
|
||||
|
||||
Rules
|
||||
-----
|
||||
- No tests → ``not_evaluated``
|
||||
- Any test not yet ``validated`` → ``in_progress``
|
||||
- All validated and all ``detected`` → ``validated``
|
||||
- All validated and any ``partially_detected`` → ``partial``
|
||||
- Otherwise → ``not_covered``
|
||||
"""
|
||||
tests = technique.tests
|
||||
|
||||
if not tests:
|
||||
technique.status_global = TechniqueStatus.not_evaluated
|
||||
elif any(t.state != "validated" for t in tests):
|
||||
technique.status_global = TechniqueStatus.in_progress
|
||||
else:
|
||||
results = [t.result for t in tests]
|
||||
if all(r == "detected" for r in results):
|
||||
technique.status_global = TechniqueStatus.validated
|
||||
elif any(r == "partially_detected" for r in results):
|
||||
technique.status_global = TechniqueStatus.partial
|
||||
else:
|
||||
technique.status_global = TechniqueStatus.not_covered
|
||||
|
||||
db.commit()
|
||||
Reference in New Issue
Block a user