feat(manager): allow manager to create auto-approved campaigns and tests from templates
Aegis CI / lint-and-test (push) Has been cancelled
Snyk Security Scan / Python vulnerabilities (backend) (push) Has been cancelled
Snyk Security Scan / npm vulnerabilities (frontend) (push) Has been cancelled
Snyk Security Scan / Docker image vulnerabilities (backend) (push) Has been cancelled

A manager organizes and validates work, so their own campaigns skip the
draft -> submit -> pending_approval queue and go straight to active with
the start_date they provide (they're the same role that would otherwise
approve it). Manager can also now create tests from the catalog, same as
red_lead/blue_lead.
This commit is contained in:
kitos
2026-07-16 12:57:20 +02:00
parent c753797019
commit 4809c4a662
8 changed files with 212 additions and 13 deletions
+18 -1
View File
@@ -281,8 +281,20 @@ def create_campaign(
tags: Optional[list[str]] = None,
# Entry: scheduled_at
scheduled_at: Optional[str] = None,
# A manager's own campaign is auto-approved on creation instead of
# going through the draft -> submit -> pending_approval queue (a
# manager is the same role that would otherwise approve it).
auto_approve: bool = False,
start_date: Optional[str] = None,
approver_id: Optional[uuid.UUID] = None,
) -> dict:
"""Create a new campaign. Does not commit; caller commits."""
"""Create a new campaign. Does not commit; caller commits.
Raises BusinessRuleViolation if auto_approve is set without a start_date.
"""
if auto_approve and not start_date:
raise BusinessRuleViolation("start_date is required to auto-approve a campaign")
# Assign campaign = Campaign(
campaign = Campaign(
# Keyword argument: name
@@ -302,6 +314,11 @@ def create_campaign(
# Keyword argument: scheduled_at
scheduled_at=datetime.fromisoformat(scheduled_at) if scheduled_at else None,
)
if auto_approve:
campaign.start_date = datetime.fromisoformat(start_date)
campaign.status = "active"
campaign.approved_by = approver_id
campaign.approved_at = datetime.utcnow()
# Stage new record(s) for database insertion
db.add(campaign)
# Flush changes to DB without committing the transaction