From 4a75ae9869ab78b6b5246ee5f6f36021f3ef74ec Mon Sep 17 00:00:00 2001 From: Ryan Petrello Date: Tue, 3 Nov 2020 11:09:30 -0500 Subject: [PATCH] allow deleting NotificationTemplates w/ old pending notifications see: https://github.com/ansible/awx/issues/8525 --- awx/api/views/__init__.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/awx/api/views/__init__.py b/awx/api/views/__init__.py index df138b8a6d..87a12a7d51 100644 --- a/awx/api/views/__init__.py +++ b/awx/api/views/__init__.py @@ -4257,7 +4257,9 @@ class NotificationTemplateDetail(RetrieveUpdateDestroyAPIView): obj = self.get_object() if not request.user.can_access(self.model, 'delete', obj): return Response(status=status.HTTP_404_NOT_FOUND) - if obj.notifications.filter(status='pending').exists(): + + hours_old = now() - dateutil.relativedelta.relativedelta(hours=8) + if obj.notifications.filter(status='pending', created__gt=hours_old).exists(): return Response({"error": _("Delete not allowed while there are pending notifications")}, status=status.HTTP_405_METHOD_NOT_ALLOWED) return super(NotificationTemplateDetail, self).delete(request, *args, **kwargs)