mirror of
https://github.com/galaxyproject/galaxy.git
synced 2026-09-24 16:30:27 +08:00
Merge pull request #17088 from davelopez/23.1_fix_notifications_input_datetimes
[23.1] Fix input dates in notifications: consider timezone offset
This commit is contained in:
@@ -22,6 +22,7 @@ from galaxy.schema.fields import (
|
||||
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.",
|
||||
|
||||
@@ -3,7 +3,6 @@ API operations on Notification objects.
|
||||
"""
|
||||
|
||||
import logging
|
||||
from datetime import datetime
|
||||
from typing import Optional
|
||||
|
||||
from fastapi import (
|
||||
@@ -33,6 +32,7 @@ from galaxy.schema.notifications import (
|
||||
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)
|
||||
|
||||
@@ -268,6 +268,16 @@ class TestNotificationsIntegration(IntegrationTestCase):
|
||||
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()
|
||||
|
||||
Reference in New Issue
Block a user