fix(campaigns): filter existing-test picker to draft + not in any campaign
Some checks failed
Aegis CI / lint-and-test (push) Has been cancelled
Some checks failed
Aegis CI / lint-and-test (push) Has been cancelled
Backend: add not_in_any_campaign filter to list_tests (subquery on CampaignTest) and expose it as a query param on GET /tests. Frontend: the 'Existing Test' tab now requests only state=draft & not_in_any_campaign=true so tests already linked to any campaign or not in draft state are never shown. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -90,6 +90,9 @@ def list_tests(
|
||||
pending_validation_side: Optional[str] = Query(
|
||||
None, description="Filter in_review tests pending validation on 'red' or 'blue' side"
|
||||
),
|
||||
not_in_any_campaign: bool = Query(
|
||||
False, description="Only return tests not linked to any campaign"
|
||||
),
|
||||
offset: int = Query(0, ge=0),
|
||||
limit: int = Query(50, ge=1, le=200),
|
||||
db: Session = Depends(get_db),
|
||||
@@ -103,6 +106,7 @@ def list_tests(
|
||||
platform=platform,
|
||||
created_by=created_by,
|
||||
pending_validation_side=pending_validation_side,
|
||||
not_in_any_campaign=not_in_any_campaign,
|
||||
offset=offset,
|
||||
limit=limit,
|
||||
)
|
||||
|
||||
@@ -19,6 +19,7 @@ from app.models.enums import TestState
|
||||
from app.models.technique import Technique
|
||||
from app.models.test import Test
|
||||
from app.models.test_template import TestTemplate
|
||||
from app.models.campaign import CampaignTest
|
||||
from app.models.audit import AuditLog
|
||||
from app.utils import escape_like
|
||||
|
||||
@@ -31,6 +32,7 @@ def list_tests(
|
||||
platform: str | None = None,
|
||||
created_by: uuid.UUID | None = None,
|
||||
pending_validation_side: str | None = None,
|
||||
not_in_any_campaign: bool = False,
|
||||
offset: int = 0,
|
||||
limit: int = 50,
|
||||
) -> list[Test]:
|
||||
@@ -55,6 +57,9 @@ def list_tests(
|
||||
Test.state == TestState.in_review,
|
||||
Test.blue_validation_status.in_(["pending", None]),
|
||||
)
|
||||
if not_in_any_campaign:
|
||||
linked = db.query(CampaignTest.test_id).distinct().subquery()
|
||||
query = query.filter(~Test.id.in_(linked))
|
||||
|
||||
return query.order_by(Test.created_at.desc()).offset(offset).limit(limit).all()
|
||||
|
||||
|
||||
Reference in New Issue
Block a user