Zulip server and web application. Open-source team chat that helps teams stay productive and focused.
webhooks/canarytoken: Use datetime_to_global_time and ISO 8601 syntax.
Niloth Pc1d35993bd69
diff --git a/zerver/webhooks/canarytoken/tests.py b/zerver/webhooks/canarytoken/tests.pyindex 9bfe61dcc01..6c7bae6f8e8 100644--- a/zerver/webhooks/canarytoken/tests.py+++ b/zerver/webhooks/canarytoken/tests.py@@ -8,7 +8,7 @@ class CanarytokensHookTests(WebhookTestCase):def test_canarytoken_new(self) -> None:expected_message = (- "**:alert: Canarytoken has been triggered on <time:2020-06-09 14:04:39Z>!**\n\n"+ "**:alert: Canarytoken has been triggered on <time:2020-06-09T14:04:39+00:00>!**\n\n""Congrats! The newly saved webhook works \n\n""[Manage this canarytoken](http://example.com/test/url/for/webhook)")@@ -22,7 +22,7 @@ class CanarytokensHookTests(WebhookTestCase):def test_canarytoken_real(self) -> None:expected_message = (- "**:alert: Canarytoken has been triggered on <time:2020-06-09 14:04:47Z>!**\n\n"+ "**:alert: Canarytoken has been triggered on <time:2020-06-09T14:04:47+00:00>!**\n\n""Canarytoken example \n\n""[Manage this canarytoken]""(https://canarytokens.org/manage?token=foo&auth=bar)"@@ -38,7 +38,7 @@ class CanarytokensHookTests(WebhookTestCase):def test_canarytoken_with_specific_topic(self) -> None:self.url = self.build_webhook_url(topic="foo")expected_message = (- "**:alert: Canarytoken has been triggered on <time:2020-06-09 14:04:47Z>!**\n\n"+ "**:alert: Canarytoken has been triggered on <time:2020-06-09T14:04:47+00:00>!**\n\n""Canarytoken example \n\n""[Manage this canarytoken]""(https://canarytokens.org/manage?token=foo&auth=bar)"diff --git a/zerver/webhooks/canarytoken/view.py b/zerver/webhooks/canarytoken/view.pyindex d45985d9fc8..a0b6919db5d 100644--- a/zerver/webhooks/canarytoken/view.py+++ b/zerver/webhooks/canarytoken/view.py@@ -1,9 +1,12 @@# Webhooks for external integrations.+from datetime import datetime+from django.http import HttpRequest, HttpResponsefrom zerver.decorator import webhook_viewfrom zerver.lib.response import json_success+from zerver.lib.timestamp import datetime_to_global_timefrom zerver.lib.typed_endpoint import JsonBodyPayload, typed_endpointfrom zerver.lib.validator import WildValue, check_stringfrom zerver.lib.webhooks.common import OptionalUserSpecifiedTopicStr, check_send_webhook_message@@ -29,9 +32,11 @@ def api_canarytoken_webhook("""topic_name = "canarytoken alert"time = message["time"].tame(check_string)- formatted_time = time.replace("(UTC)", "").strip() + "Z"+ formatted_time = datetime_to_global_time(+ datetime.fromisoformat(time.replace("(UTC)", "").strip() + "+00:00")+ )body = (- f"**:alert: Canarytoken has been triggered on <time:{formatted_time}>!**\n\n"+ f"**:alert: Canarytoken has been triggered on {formatted_time}!**\n\n"f"{message['memo'].tame(check_string)} \n\n"f"[Manage this canarytoken]({message['manage_url'].tame(check_string)})")