feat: implement assurance graph and screening evidence

This commit is contained in:
2026-08-01 17:48:39 +02:00
parent bbf7288e14
commit a23b53dc9e
18 changed files with 4005 additions and 42 deletions
@@ -152,11 +152,12 @@ def run_screening(
raise RiskSanctionsConflictError(
"Idempotency key was already used for another screening request."
)
return get_screening_run(
return _screening_result(
session,
principal,
run_id=existing.id,
), False
created=False,
)
list_snapshot = _visible_list_snapshot(
session,
@@ -207,11 +208,12 @@ def run_screening(
run.outcome = list_state
run.completed_at = utcnow()
session.flush()
return get_screening_run(
return _screening_result(
session,
principal,
run_id=run.id,
), True
created=True,
)
entries = tuple(
session.scalars(
@@ -235,11 +237,12 @@ def run_screening(
}
run.completed_at = utcnow()
session.flush()
return get_screening_run(
return _screening_result(
session,
principal,
run_id=run.id,
), True
created=True,
)
candidates = sorted(
(
@@ -297,11 +300,12 @@ def run_screening(
run.outcome = "potential" if candidates else "clear"
run.completed_at = utcnow()
session.flush()
return get_screening_run(
return _screening_result(
session,
principal,
run_id=run.id,
), True
created=True,
)
def screening_evidence_ref(run_id: str) -> str:
@@ -313,6 +317,31 @@ def screening_evidence_ref(run_id: str) -> str:
return f"{SCREENING_EVIDENCE_PREFIX}{clean_run_id}"
def _screening_result(
session: Session,
principal: ApiPrincipal,
*,
run_id: str,
created: bool,
) -> tuple[RiskScreeningRun, bool]:
run = get_screening_run(
session,
principal,
run_id=run_id,
)
if run.status == "completed":
from govoplan_risk_compliance.backend.assurance import (
record_sanctions_assurance,
)
record_sanctions_assurance(
session,
principal,
run=run,
)
return run, created
def assess_screening_freshness(
session: Session,
principal: ApiPrincipal,