From bd2c7e824a3f99a2082c14b8640cffbe34b37f25 Mon Sep 17 00:00:00 2001 From: F-G Fernandez <26927750+frgfm@users.noreply.github.com> Date: Fri, 17 Jan 2025 11:25:29 +0100 Subject: [PATCH] feat(detections): restrict webhook and telegram to sequence creation --- src/app/api/api_v1/endpoints/detections.py | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/src/app/api/api_v1/endpoints/detections.py b/src/app/api/api_v1/endpoints/detections.py index 41d8eb12..4e052a16 100644 --- a/src/app/api/api_v1/endpoints/detections.py +++ b/src/app/api/api_v1/endpoints/detections.py @@ -120,20 +120,20 @@ async def create_detection( ) ) # Update the detection with the sequence ID - await detections.update(det.id, DetectionSequence(sequence_id=sequence_.id)) + det = await detections.update(det.id, DetectionSequence(sequence_id=sequence_.id)) for det_ in dets_: await detections.update(det_.id, DetectionSequence(sequence_id=sequence_.id)) - # Webhooks - whs = await webhooks.fetch_all() - if any(whs): - for webhook in await webhooks.fetch_all(): - background_tasks.add_task(dispatch_webhook, webhook.url, det) - # Telegram notifications - if telegram_client.is_enabled: - org = cast(Organization, await organizations.get(token_payload.organization_id, strict=True)) - if org.telegram_id: - background_tasks.add_task(telegram_client.notify, org.telegram_id, det.model_dump_json()) + # Webhooks + whs = await webhooks.fetch_all() + if any(whs): + for webhook in await webhooks.fetch_all(): + background_tasks.add_task(dispatch_webhook, webhook.url, det) + # Telegram notifications + if telegram_client.is_enabled: + org = cast(Organization, await organizations.get(token_payload.organization_id, strict=True)) + if org.telegram_id: + background_tasks.add_task(telegram_client.notify, org.telegram_id, det.model_dump_json()) return det