diff --git a/backend/api_app/monitoring/tasks.py b/backend/api_app/monitoring/tasks.py index be33c2a..19327c2 100644 --- a/backend/api_app/monitoring/tasks.py +++ b/backend/api_app/monitoring/tasks.py @@ -38,8 +38,8 @@ def call_smart_contract_function(self, monitoring_task_id): def send_webhook(self, notification_id): notification = Notification.objects.filter(id=notification_id).first() - if not notification: - error_msg = f"Notification with id {notification_id} not found" + if (not notification) and (notification.alert.active is False): + error_msg = f"Active notification with id {notification_id} not found" logger.error(error_msg) raise Exception(error_msg) diff --git a/backend/api_app/monitoring/urls.py b/backend/api_app/monitoring/urls.py index d595311..88a4a22 100644 --- a/backend/api_app/monitoring/urls.py +++ b/backend/api_app/monitoring/urls.py @@ -4,6 +4,7 @@ AlertCreateAPIView, AlertRetrieveAPIView, AlertUpdateAPIView, + AlertDeleteAPIView, NotificationListViewSet, OrganizationAlertListViewSet, OverviewDataAPIView, @@ -19,6 +20,7 @@ path("alerts/", AlertRetrieveAPIView.as_view(), name="alert-retrieve"), path("alerts", AlertCreateAPIView.as_view(), name="alert-create"), path("alerts/update/", AlertUpdateAPIView.as_view(), name="alert-update"), + path("alerts/delete/", AlertDeleteAPIView.as_view(), name="alert-delete"), path("notifications", NotificationListViewSet.as_view(), name="notification-list"), path("pre-written-alerts", get_pre_written_alerts, name="pre-written-alerts"), path( diff --git a/backend/api_app/monitoring/views.py b/backend/api_app/monitoring/views.py index cddb43f..195e003 100644 --- a/backend/api_app/monitoring/views.py +++ b/backend/api_app/monitoring/views.py @@ -294,6 +294,15 @@ def post(self, request, *args, **kwargs): serializer.save() return Response(serializer.data, status=status.HTTP_201_CREATED) +class AlertDeleteAPIView(DestroyAPIView): + queryset = Alerts.objects.all() + permission_classes = [AlertCanBeAccessedPermissions] + + def destroy(self, request, *args, **kwargs): + instance = self.get_object() + self.perform_destroy(instance) + return Response(status=status.HTTP_204_NO_CONTENT) + class AlertUpdateAPIView(UpdateAPIView): serializer_class = AlertUpdateSerializer permission_classes = [AlertCanBeAccessedPermissions]