From 1bbb82e16ac43d64de32bf5a16e09b78a06b5d68 Mon Sep 17 00:00:00 2001 From: Elisa Anguita Date: Mon, 25 Nov 2024 19:24:53 -0300 Subject: [PATCH 1/4] feat(webhook_logs): Display timezone in all datetimes --- cl/users/templates/includes/webhook-event-detail.html | 4 ++-- .../templates/includes/webhooks_htmx/webhook-logs-list.html | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/cl/users/templates/includes/webhook-event-detail.html b/cl/users/templates/includes/webhook-event-detail.html index 20f631fb53..2510ac729c 100644 --- a/cl/users/templates/includes/webhook-event-detail.html +++ b/cl/users/templates/includes/webhook-event-detail.html @@ -13,11 +13,11 @@

Webhook Event Details{% if webhook_event.debug %} (

{% if webhook_event.webhook.enabled %} Enabled {% else %} Disabled {% endif %}

{{ webhook_event.webhook.get_event_type_display }}

{{ webhook_event.event_id }}

-

{{ webhook_event.date_created }}

+

{{ webhook_event.date_created|date:"M. j, Y, h:m a T" }}

{% if webhook_event.status_code %}{{ webhook_event.status_code }} {{ webhook_event.get_status_code_display }} {% else %}-{% endif %}

{{ webhook_event.get_event_status_display }}

{{ webhook_event.retry_counter }}

-

{% if not webhook_event.debug %}{% if webhook_event.next_retry_date %}{{ webhook_event.next_retry_date }}{% else %}-{% endif %}{% else %}Test events will not be retried{% endif %}

+

{% if not webhook_event.debug %}{% if webhook_event.next_retry_date %}{{ webhook_event.next_retry_date|date:"M. j, Y, h:m a T" }}{% else %}-{% endif %}{% else %}Test events will not be retried{% endif %}

diff --git a/cl/users/templates/includes/webhooks_htmx/webhook-logs-list.html b/cl/users/templates/includes/webhooks_htmx/webhook-logs-list.html index dc022dff94..a43f9eeb85 100644 --- a/cl/users/templates/includes/webhooks_htmx/webhook-logs-list.html +++ b/cl/users/templates/includes/webhooks_htmx/webhook-logs-list.html @@ -21,11 +21,11 @@ {% endif %}

- {{ webhook.date_created }} + {{ webhook.date_created|date:"M. j, Y, h:m a T" }} {% if not webhook.debug %} {% if webhook.next_retry_date %} - {{ webhook.next_retry_date }} + {{ webhook.next_retry_date|date:"M. j, Y, h:m a T" }} {% else %} - {% endif %} From 39761ebc4f0e943b1ec1841f56590ce07dcac311 Mon Sep 17 00:00:00 2001 From: Elisa Anguita Date: Mon, 25 Nov 2024 19:44:40 -0300 Subject: [PATCH 2/4] fix(webhook_logs): Fix format string character --- cl/users/templates/includes/webhook-event-detail.html | 4 ++-- .../templates/includes/webhooks_htmx/webhook-logs-list.html | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/cl/users/templates/includes/webhook-event-detail.html b/cl/users/templates/includes/webhook-event-detail.html index 2510ac729c..63c5ed7920 100644 --- a/cl/users/templates/includes/webhook-event-detail.html +++ b/cl/users/templates/includes/webhook-event-detail.html @@ -13,11 +13,11 @@

Webhook Event Details{% if webhook_event.debug %} (

{% if webhook_event.webhook.enabled %} Enabled {% else %} Disabled {% endif %}

{{ webhook_event.webhook.get_event_type_display }}

{{ webhook_event.event_id }}

-

{{ webhook_event.date_created|date:"M. j, Y, h:m a T" }}

+

{{ webhook_event.date_created|date:"M. j, Y, h:i a T" }}

{% if webhook_event.status_code %}{{ webhook_event.status_code }} {{ webhook_event.get_status_code_display }} {% else %}-{% endif %}

{{ webhook_event.get_event_status_display }}

{{ webhook_event.retry_counter }}

-

{% if not webhook_event.debug %}{% if webhook_event.next_retry_date %}{{ webhook_event.next_retry_date|date:"M. j, Y, h:m a T" }}{% else %}-{% endif %}{% else %}Test events will not be retried{% endif %}

+

{% if not webhook_event.debug %}{% if webhook_event.next_retry_date %}{{ webhook_event.next_retry_date|date:"M. j, Y, h:i a T" }}{% else %}-{% endif %}{% else %}Test events will not be retried{% endif %}

diff --git a/cl/users/templates/includes/webhooks_htmx/webhook-logs-list.html b/cl/users/templates/includes/webhooks_htmx/webhook-logs-list.html index a43f9eeb85..18b19f641a 100644 --- a/cl/users/templates/includes/webhooks_htmx/webhook-logs-list.html +++ b/cl/users/templates/includes/webhooks_htmx/webhook-logs-list.html @@ -21,11 +21,11 @@ {% endif %}

- {{ webhook.date_created|date:"M. j, Y, h:m a T" }} + {{ webhook.date_created|date:"M. j, Y, h:i a T" }} {% if not webhook.debug %} {% if webhook.next_retry_date %} - {{ webhook.next_retry_date|date:"M. j, Y, h:m a T" }} + {{ webhook.next_retry_date|date:"M. j, Y, h:i a T" }} {% else %} - {% endif %} From e8c71e779126dcd74a98fce90ab8e73b85a61267 Mon Sep 17 00:00:00 2001 From: Elisa Anguita Date: Mon, 25 Nov 2024 20:58:00 -0300 Subject: [PATCH 3/4] fix(webhook_logs): Always display datetimes in UTC in webhook logs --- cl/custom_filters/templatetags/extras.py | 17 ++++++++++++++++- .../includes/webhook-event-detail.html | 5 +++-- .../webhooks_htmx/webhook-logs-list.html | 5 +++-- 3 files changed, 22 insertions(+), 5 deletions(-) diff --git a/cl/custom_filters/templatetags/extras.py b/cl/custom_filters/templatetags/extras.py index 39d535b2df..6532ca2881 100644 --- a/cl/custom_filters/templatetags/extras.py +++ b/cl/custom_filters/templatetags/extras.py @@ -1,7 +1,7 @@ import random import re import urllib.parse -from datetime import datetime +from datetime import datetime, timezone import waffle from django import template @@ -337,6 +337,21 @@ def format_date(date_str: str) -> str: return date_str +@register.filter +def datetime_in_utc(date_obj) -> str: + """Formats a datetime object in UTC with timezone displayed. + For example: 'Nov. 25, 2024, 01:28 p.m. UTC'""" + if date_obj is None: + return "" + try: + return date_filter( + date_obj.astimezone(timezone.utc), + "M. j, Y, h:i a T", + ) + except (ValueError, TypeError): + return date_obj + + @register.filter def build_docket_id_q_param(request_q: str, docket_id: str) -> str: """Build a query string that includes the docket ID and any existing query diff --git a/cl/users/templates/includes/webhook-event-detail.html b/cl/users/templates/includes/webhook-event-detail.html index 63c5ed7920..9f70262daa 100644 --- a/cl/users/templates/includes/webhook-event-detail.html +++ b/cl/users/templates/includes/webhook-event-detail.html @@ -1,4 +1,5 @@ {% extends "profile/webhooks_base.html" %} +{% load extras %} {% load static %} {% load waffle_tags %} {% load humanize %} @@ -13,11 +14,11 @@

Webhook Event Details{% if webhook_event.debug %} (

{% if webhook_event.webhook.enabled %} Enabled {% else %} Disabled {% endif %}

{{ webhook_event.webhook.get_event_type_display }}

{{ webhook_event.event_id }}

-

{{ webhook_event.date_created|date:"M. j, Y, h:i a T" }}

+

{{ webhook_event.date_created|datetime_in_utc }}

{% if webhook_event.status_code %}{{ webhook_event.status_code }} {{ webhook_event.get_status_code_display }} {% else %}-{% endif %}

{{ webhook_event.get_event_status_display }}

{{ webhook_event.retry_counter }}

-

{% if not webhook_event.debug %}{% if webhook_event.next_retry_date %}{{ webhook_event.next_retry_date|date:"M. j, Y, h:i a T" }}{% else %}-{% endif %}{% else %}Test events will not be retried{% endif %}

+

{% if not webhook_event.debug %}{% if webhook_event.next_retry_date %}{{ webhook_event.next_retry_date|datetime_in_utc }}{% else %}-{% endif %}{% else %}Test events will not be retried{% endif %}

diff --git a/cl/users/templates/includes/webhooks_htmx/webhook-logs-list.html b/cl/users/templates/includes/webhooks_htmx/webhook-logs-list.html index 18b19f641a..a9f8596832 100644 --- a/cl/users/templates/includes/webhooks_htmx/webhook-logs-list.html +++ b/cl/users/templates/includes/webhooks_htmx/webhook-logs-list.html @@ -1,3 +1,4 @@ +{% load extras %} {% load widget_tweaks %} {% if results %} {% for webhook in results %} @@ -21,11 +22,11 @@ {% endif %}

- {{ webhook.date_created|date:"M. j, Y, h:i a T" }} + {{ webhook.date_created|datetime_in_utc }} {% if not webhook.debug %} {% if webhook.next_retry_date %} - {{ webhook.next_retry_date|date:"M. j, Y, h:i a T" }} + {{ webhook.next_retry_date|datetime_in_utc }} {% else %} - {% endif %} From 877cf130e2bc7c49dc2cd446cf8d98d794e20b5e Mon Sep 17 00:00:00 2001 From: Elisa Anguita Date: Tue, 26 Nov 2024 14:27:44 -0300 Subject: [PATCH 4/4] test(webhooks): Adjust test so it's now less sensitive to trailing whitespaces Adding a {% load %} tag introduced an extra newline that was picked up by the test. Instead of counting newline chars we now only focus on whether the response contains meaningful content or not. --- cl/users/tests.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/cl/users/tests.py b/cl/users/tests.py index 89170a445c..f5e26aac09 100644 --- a/cl/users/tests.py +++ b/cl/users/tests.py @@ -3467,7 +3467,7 @@ async def test_list_webhook_events(self) -> None: response = await self.client.get(webhook_event_path_list) self.assertEqual(response.status_code, HTTPStatus.OK) # There shouldn't be results for user_1 - self.assertEqual(response.content, b"\n\n") + self.assertEqual(response.content.strip(), b"") sa_webhook = await sync_to_async(WebhookFactory)( user=self.user_1, @@ -3485,7 +3485,7 @@ async def test_list_webhook_events(self) -> None: response = await self.client.get(webhook_event_path_list) self.assertEqual(response.status_code, HTTPStatus.OK) # There should be results for user_1 - self.assertNotEqual(response.content, b"\n\n") + self.assertNotEqual(response.content.strip(), b"") async def test_get_available_webhook_versions(self) -> None: """Can we get users available versions for a webhook event type?"""