Skip to content

Commit

Permalink
fix expiry on event update
Browse files Browse the repository at this point in the history
it gets set from ingest based on current time + provider config,
which might be before the event actually happens

SDCP-744
  • Loading branch information
petrjasek committed Mar 13, 2024
1 parent 3f640b1 commit 6932542
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 4 deletions.
14 changes: 10 additions & 4 deletions server/planning/events/events.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"]:
Expand Down Expand Up @@ -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):
Expand Down
24 changes: 24 additions & 0 deletions server/planning/tests/events_test.py
Original file line number Diff line number Diff line change
@@ -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)

0 comments on commit 6932542

Please sign in to comment.