From d73910c5400753d4b6921b13d6eedba3a375c631 Mon Sep 17 00:00:00 2001 From: F-G Fernandez <26927750+frgfm@users.noreply.github.com> Date: Wed, 24 Jan 2024 11:24:01 +0100 Subject: [PATCH] fix: Fixes typo --- src/app/api/endpoints/alerts.py | 4 ++-- src/app/api/endpoints/notifications.py | 19 +++++++++++-------- 2 files changed, 13 insertions(+), 10 deletions(-) diff --git a/src/app/api/endpoints/alerts.py b/src/app/api/endpoints/alerts.py index 2f41ba44..eeff74db 100644 --- a/src/app/api/endpoints/alerts.py +++ b/src/app/api/endpoints/alerts.py @@ -14,7 +14,7 @@ from app.api.crud.authorizations import check_group_read, is_admin_access from app.api.crud.groups import get_entity_group_id from app.api.deps import get_current_access, get_current_device, get_current_user, get_db -from app.api.endpoints.notifications import send_notification +from app.api.endpoints.notifications import _send_notification from app.api.endpoints.recipients import fetch_recipients_for_group from app.api.external import post_request from app.db import alerts, devices, events, media @@ -53,7 +53,7 @@ async def alert_notification(payload: AlertOut): subject: str = Template(recipient.subject_template).safe_substitute(**info) message: str = Template(recipient.message_template).safe_substitute(**info) notification = NotificationIn(alert_id=payload.id, recipient_id=recipient.id, subject=subject, message=message) - await send_notification(notification) + await _send_notification(notification) async def _create_alert(payload: AlertIn, background_tasks: BackgroundTasks) -> AlertOut: diff --git a/src/app/api/endpoints/notifications.py b/src/app/api/endpoints/notifications.py index 234e28fb..822d4435 100644 --- a/src/app/api/endpoints/notifications.py +++ b/src/app/api/endpoints/notifications.py @@ -19,6 +19,16 @@ router = APIRouter(dependencies=[Security(get_current_access, scopes=[AccessType.admin])]) +async def _send_notification(payload: NotificationIn) -> NotificationOut: + recipient = RecipientOut(**(await get_recipient(recipient_id=payload.recipient_id))) + if recipient.notification_type == NotificationType.telegram: + send_telegram_msg(recipient.address, payload.message) + else: + raise HTTPException(status_code=status.HTTP_400_BAD_REQUEST, detail="Invalid NotificationType, not treated") + + return NotificationOut(**(await crud.create_entry(notifications, payload))) + + @router.post("/", status_code=status.HTTP_201_CREATED, summary="Send and log notification") async def send_notification( payload: NotificationIn, @@ -31,14 +41,7 @@ async def send_notification( or "Example Value" to get a concrete idea of arguments """ telemetry_client.capture(user.id, event="notifications-send", properties={"recipient_id": payload.recipient_id}) - recipient = RecipientOut(**(await get_recipient(recipient_id=payload.recipient_id))) - if recipient.notification_type == NotificationType.telegram: - send_telegram_msg(recipient.address, payload.message) - else: - raise HTTPException(status_code=status.HTTP_400_BAD_REQUEST, detail="Invalid NotificationType, not treated") - - notification: NotificationOut = NotificationOut(**(await crud.create_entry(notifications, payload))) - return notification + return _send_notification(payload) @router.get(