Skip to content

Commit

Permalink
Merge pull request #17088 from davelopez/23.1_fix_notifications_input…
Browse files Browse the repository at this point in the history
…_datetimes

[23.1] Fix input dates in notifications: consider timezone offset
  • Loading branch information
martenson authored Nov 27, 2023
2 parents 142ac4b + 9b1fb5e commit c3dbf7d
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 6 deletions.
9 changes: 5 additions & 4 deletions lib/galaxy/schema/notifications.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
EncodedDatabaseIdField,
)
from galaxy.schema.schema import Model
from galaxy.schema.types import OffsetNaiveDatetime


class NotificationVariant(str, Enum):
Expand Down Expand Up @@ -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.",
Expand Down Expand Up @@ -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.",
Expand Down
4 changes: 2 additions & 2 deletions lib/galaxy/webapps/galaxy/api/notifications.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
"""

import logging
from datetime import datetime
from typing import Optional

from fastapi import (
Expand Down Expand Up @@ -33,6 +32,7 @@
UserNotificationsBatchUpdateRequest,
UserNotificationUpdateRequest,
)
from galaxy.schema.types import OffsetNaiveDatetime
from galaxy.webapps.galaxy.services.notifications import NotificationService
from . import (
depends,
Expand All @@ -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)
Expand Down
10 changes: 10 additions & 0 deletions test/integration/test_notifications.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down

0 comments on commit c3dbf7d

Please sign in to comment.