feat(campaigns): timeline endpoint, admin-only manual activation, remove lead-set dates
This commit is contained in:
@@ -281,7 +281,6 @@ def create_campaign(
|
||||
tags: Optional[list[str]] = None,
|
||||
# Entry: scheduled_at
|
||||
scheduled_at: Optional[str] = None,
|
||||
start_date: Optional[str] = None,
|
||||
) -> dict:
|
||||
"""Create a new campaign. Does not commit; caller commits."""
|
||||
# Assign campaign = Campaign(
|
||||
@@ -302,7 +301,6 @@ def create_campaign(
|
||||
created_by=creator_id,
|
||||
# Keyword argument: scheduled_at
|
||||
scheduled_at=datetime.fromisoformat(scheduled_at) if scheduled_at else None,
|
||||
start_date=datetime.fromisoformat(start_date) if start_date else None,
|
||||
)
|
||||
# Stage new record(s) for database insertion
|
||||
db.add(campaign)
|
||||
@@ -459,8 +457,6 @@ def update_campaign(
|
||||
if "scheduled_at" in fields and fields["scheduled_at"]:
|
||||
# Assign fields["scheduled_at"] = datetime.fromisoformat(fields["scheduled_at"])
|
||||
fields["scheduled_at"] = datetime.fromisoformat(fields["scheduled_at"])
|
||||
if "start_date" in fields and fields["start_date"]:
|
||||
fields["start_date"] = datetime.fromisoformat(fields["start_date"])
|
||||
|
||||
# Iterate over fields.items()
|
||||
for field, value in fields.items():
|
||||
@@ -679,7 +675,7 @@ def activate_campaign(db: Session, campaign_id: str) -> Campaign:
|
||||
Does not commit; caller commits.
|
||||
"""
|
||||
# Assign campaign = db.query(Campaign).filter(Campaign.id == campaign_id).first()
|
||||
campaign = db.query(Campaign).filter(Campaign.id == campaign_id).first()
|
||||
campaign = db.query(Campaign).filter(Campaign.id == uuid.UUID(campaign_id)).first()
|
||||
# Check: not campaign
|
||||
if not campaign:
|
||||
# Raise EntityNotFoundError
|
||||
@@ -691,7 +687,7 @@ def activate_campaign(db: Session, campaign_id: str) -> Campaign:
|
||||
raise BusinessRuleViolation("Only draft campaigns can be activated")
|
||||
|
||||
# Assign test_count = db.query(CampaignTest).filter(CampaignTest.campaign_id == campaign_...
|
||||
test_count = db.query(CampaignTest).filter(CampaignTest.campaign_id == campaign_id).count()
|
||||
test_count = db.query(CampaignTest).filter(CampaignTest.campaign_id == campaign.id).count()
|
||||
# Check: test_count == 0
|
||||
if test_count == 0:
|
||||
# Raise BusinessRuleViolation
|
||||
|
||||
@@ -8,7 +8,6 @@ threat actors, and progress calculation.
|
||||
import logging
|
||||
import uuid
|
||||
from datetime import datetime
|
||||
from typing import Optional
|
||||
|
||||
# Import Session from sqlalchemy.orm
|
||||
from sqlalchemy.orm import Session
|
||||
@@ -179,8 +178,6 @@ def generate_campaign_from_threat_actor(
|
||||
actor_id: uuid.UUID,
|
||||
# Entry: user
|
||||
user: User,
|
||||
*,
|
||||
start_date: Optional[datetime] = None,
|
||||
) -> Campaign:
|
||||
"""Auto-generate a campaign from a threat actor's uncovered techniques.
|
||||
|
||||
@@ -238,7 +235,6 @@ def generate_campaign_from_threat_actor(
|
||||
created_by=user.id,
|
||||
# Keyword argument: tags
|
||||
tags=[actor.name, "auto-generated"],
|
||||
start_date=start_date,
|
||||
)
|
||||
# Stage new record(s) for database insertion
|
||||
db.add(campaign)
|
||||
|
||||
Reference in New Issue
Block a user