From 809d40942dfef33b84a29f15bc220c7e56afd54e Mon Sep 17 00:00:00 2001 From: davelopez <46503462+davelopez@users.noreply.github.com> Date: Mon, 27 Nov 2023 18:02:32 +0100 Subject: [PATCH 1/2] Add test to check notification input times --- test/integration/test_notifications.py | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/test/integration/test_notifications.py b/test/integration/test_notifications.py index fb254a2b9e42..412fab3e2a82 100644 --- a/test/integration/test_notifications.py +++ b/test/integration/test_notifications.py @@ -268,6 +268,16 @@ def test_admins_get_all_broadcasted_even_inactive(self): assert "Scheduled" in subjects assert "Expired" in subjects + def test_notification_input_dates_consider_timezone(self): + payload = notification_broadcast_test_data(subject="Test", message="Test") + payload["publication_time"] = "2021-01-01T12:00:00+02:00" + payload["expiration_time"] = "2021-01-01T12:00:00Z" + response = self._post("notifications/broadcast", data=payload, admin=True, json=True) + self._assert_status_code_is_ok(response) + notification = response.json()["notification"] + assert notification["publication_time"] == "2021-01-01T10:00:00" + assert notification["expiration_time"] == "2021-01-01T12:00:00" + def test_sharing_items_creates_notifications_when_expected(self): user1 = self._create_test_user() user2 = self._create_test_user() From 9b1fb5eb7a0a84f999e1a0a532114d67956c611d Mon Sep 17 00:00:00 2001 From: davelopez <46503462+davelopez@users.noreply.github.com> Date: Mon, 27 Nov 2023 18:03:55 +0100 Subject: [PATCH 2/2] Fix notification input timestamps: consider timezone --- lib/galaxy/schema/notifications.py | 9 +++++---- lib/galaxy/webapps/galaxy/api/notifications.py | 4 ++-- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/lib/galaxy/schema/notifications.py b/lib/galaxy/schema/notifications.py index 30bb8c1aa1a9..3a903de737d0 100644 --- a/lib/galaxy/schema/notifications.py +++ b/lib/galaxy/schema/notifications.py @@ -22,6 +22,7 @@ EncodedDatabaseIdField, ) from galaxy.schema.schema import Model +from galaxy.schema.types import OffsetNaiveDatetime class NotificationVariant(str, Enum): @@ -244,12 +245,12 @@ class NotificationCreateData(Model): category: NotificationCategory = NotificationCategoryField variant: NotificationVariant = NotificationVariantField content: AnyNotificationContent - publication_time: Optional[datetime] = Field( + publication_time: Optional[OffsetNaiveDatetime] = Field( None, title="Publication time", description="The time when the notification should be published. Notifications can be created and then scheduled to be published at a later time.", ) - expiration_time: Optional[datetime] = Field( + expiration_time: Optional[OffsetNaiveDatetime] = Field( None, title="Expiration time", description="The time when the notification should expire. By default it will expire after 6 months. Expired notifications will be permanently deleted.", @@ -349,12 +350,12 @@ class NotificationBroadcastUpdateRequest(NotificationUpdateRequest): title="Variant", description="The variant of the notification. Used to express the importance of the notification.", ) - publication_time: Optional[datetime] = Field( + publication_time: Optional[OffsetNaiveDatetime] = Field( None, title="Publication time", description="The time when the notification should be published. Notifications can be created and then scheduled to be published at a later time.", ) - expiration_time: Optional[datetime] = Field( + expiration_time: Optional[OffsetNaiveDatetime] = Field( None, title="Expiration time", description="The time when the notification should expire. By default it will expire after 6 months. Expired notifications will be permanently deleted.", diff --git a/lib/galaxy/webapps/galaxy/api/notifications.py b/lib/galaxy/webapps/galaxy/api/notifications.py index c6e7aa1775a5..0439ddf1d672 100644 --- a/lib/galaxy/webapps/galaxy/api/notifications.py +++ b/lib/galaxy/webapps/galaxy/api/notifications.py @@ -3,7 +3,6 @@ """ import logging -from datetime import datetime from typing import Optional from fastapi import ( @@ -33,6 +32,7 @@ UserNotificationsBatchUpdateRequest, UserNotificationUpdateRequest, ) +from galaxy.schema.types import OffsetNaiveDatetime from galaxy.webapps.galaxy.services.notifications import NotificationService from . import ( depends, @@ -56,7 +56,7 @@ class FastAPINotifications: def get_notifications_status( self, trans: ProvidesUserContext = DependsOnTrans, - since: datetime = Query(), + since: OffsetNaiveDatetime = Query(), ) -> NotificationStatusSummary: """Anonymous users cannot receive personal notifications, only broadcasted notifications.""" return self.service.get_notifications_status(trans, since)