feat(campaigns): start_date for threat-actor-generated campaigns
Some checks failed
Aegis CI / lint-and-test (push) Has been cancelled

Backend:
- campaign_service.generate_campaign_from_threat_actor: accept optional
  start_date kwarg and set it on the Campaign model
- campaigns router: new GenerateFromActorPayload schema, /from-threat-actor
  endpoint now accepts optional body with start_date

Frontend:
- generateCampaignFromThreatActor API: accept optional options param
- Generate Campaign modal: date picker + warning message, same UX as the
  manual create form

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
kitos
2026-06-04 13:37:40 +02:00
parent 498536f3f1
commit f8418bc7ea
4 changed files with 48 additions and 3 deletions

View File

@@ -395,9 +395,14 @@ def get_campaign_progress_endpoint(
# POST /campaigns/from-threat-actor/{actor_id} — Auto-generate campaign
# ---------------------------------------------------------------------------
class GenerateFromActorPayload(BaseModel):
start_date: Optional[str] = None # ISO date YYYY-MM-DD
@router.post("/from-threat-actor/{actor_id}", status_code=201)
def generate_campaign_from_actor(
actor_id: str,
payload: GenerateFromActorPayload = GenerateFromActorPayload(),
db: Session = Depends(get_db),
current_user: User = Depends(require_any_role("red_lead", "blue_lead")),
):
@@ -406,10 +411,14 @@ def generate_campaign_from_actor(
Creates tests from the best available templates and orders them
by kill chain phase.
"""
start_date_parsed = (
datetime.fromisoformat(payload.start_date) if payload.start_date else None
)
campaign = generate_campaign_from_threat_actor(
db,
uuid.UUID(actor_id),
current_user,
start_date=start_date_parsed,
)
with UnitOfWork(db) as uow:

View File

@@ -7,6 +7,7 @@ threat actors, and progress calculation.
import logging
import uuid
from datetime import datetime
from typing import Optional
from sqlalchemy.orm import Session
@@ -106,6 +107,8 @@ def generate_campaign_from_threat_actor(
db: Session,
actor_id: uuid.UUID,
user: User,
*,
start_date: Optional[datetime] = None,
) -> Campaign:
"""Auto-generate a campaign from a threat actor's uncovered techniques.
@@ -146,6 +149,7 @@ def generate_campaign_from_threat_actor(
status="draft",
created_by=user.id,
tags=[actor.name, "auto-generated"],
start_date=start_date,
)
db.add(campaign)
db.flush() # Get campaign.id