diff --git a/server/planning/events/events.py b/server/planning/events/events.py index 59bfc53b4..3ccf3f1d0 100644 --- a/server/planning/events/events.py +++ b/server/planning/events/events.py @@ -422,6 +422,8 @@ def on_update(self, updates, original): print(lock_user, str_user_id) raise SuperdeskApiError.forbiddenError("The item was locked by another user") + overwrite_event_expiry_date(updates, original) + # If only the `recurring_rule` was provided, then fill in the rest from the original # This can happen, for example, when converting a single Event to a series of Recurring Events if list(updates.get("dates") or {}) == ["recurring_rule"]: @@ -861,10 +863,14 @@ def setRecurringMode(event): event["dates"]["recurring_rule"]["count"] = None -def overwrite_event_expiry_date(event): - if "expiry" in event: - expiry_minutes = app.settings.get("PLANNING_EXPIRY_MINUTES", None) - event["expiry"] = event["dates"]["end"] + timedelta(minutes=expiry_minutes or 0) +def overwrite_event_expiry_date(updates, original=None): + if "expiry" in updates: + if original is None: + original = {} + updated = original.copy() + updated.update(updates) + expiry_minutes = app.config.get("PLANNING_EXPIRY_MINUTES", None) + updates["expiry"] = updated["dates"]["end"] + timedelta(minutes=expiry_minutes or 0) def generate_recurring_events(event): diff --git a/server/planning/tests/events_test.py b/server/planning/tests/events_test.py new file mode 100644 index 000000000..f0dcf46af --- /dev/null +++ b/server/planning/tests/events_test.py @@ -0,0 +1,24 @@ +import unittest.mock as mock + +from . import TestCase + +from datetime import datetime + +from planning.events.events import overwrite_event_expiry_date + + +class EventsExpiryTestCase(TestCase): + def test_expiry(self): + with mock.patch.dict(self.app.config, {"PLANNING_EXPIRY_MINUTES": 20}): + with self.app.app_context(): + item = {"dates": {"end": datetime(2050, 1, 1, 10, 0)}, "expiry": datetime.now()} + overwrite_event_expiry_date(item) + assert item["expiry"] == datetime(2050, 1, 1, 10, 20) + + updates = {"expiry": datetime.now()} + overwrite_event_expiry_date(updates, item) + assert updates["expiry"] == datetime(2050, 1, 1, 10, 20) + + updates = {"expiry": datetime.now(), "dates": {"end": datetime(2060, 1, 1, 10, 0)}} + overwrite_event_expiry_date(updates, item) + assert updates["expiry"] == datetime(2060, 1, 1, 10, 20)