FIX: Prevent setting access time after start time

Cherry pick of d274ea4606. Will close #405.
This commit is contained in:
2020-05-25 01:16:26 +01:00
parent 544b6df35c
commit e6d06db2a1
2 changed files with 35 additions and 1 deletions

View File

@@ -463,6 +463,12 @@ class Event(models.Model, RevisionMixin):
hasStartAndEnd = self.has_start_time and self.has_end_time
if startEndSameDay and hasStartAndEnd and self.start_time > self.end_time:
raise ValidationError('Unless you\'ve invented time travel, the event can\'t finish before it has started.')
if self.access_at is not None:
if self.access_at.date() > self.start_date:
raise ValidationError('Regardless of what some clients might think, access time cannot be after the event has started.')
elif self.start_time is not None and self.start_date == self.access_at.date() and self.access_at.time() > self.start_time:
raise ValidationError('Regardless of what some clients might think, access time cannot be after the event has started.')
def save(self, *args, **kwargs):
"""Call :meth:`full_clean` before saving."""

View File

@@ -203,6 +203,33 @@ class TestEventCreate(BaseRigboardTest):
# Should work
self.page.submit()
self.assertTrue(self.page.success)
def test_access_validation(self):
self.select_event_type("Rig")
self.page.person_selector.toggle()
self.assertTrue(self.page.person_selector.is_open)
self.page.person_selector.search(self.client.name)
self.page.person_selector.set_option(self.client.name, True)
# TODO This should not be necessary, normally closes automatically
self.page.person_selector.toggle()
self.assertFalse(self.page.person_selector.is_open)
self.page.name = "Access Validation Test"
self.page.start_date = datetime.date(2020, 1, 1)
self.page.access_at = datetime.datetime(2020, 1, 5, 10)
self.page.submit()
self.assertFalse(self.page.success)
self.assertIn("access time cannot be after the event has started.", self.page.errors["General form errors"][0])
#Fix it
self.page.access_at = datetime.datetime(2020, 1, 1, 10)
# Should work
self.page.submit()
self.assertTrue(self.page.success)
def test_event_item_creation(self):
self.select_event_type("Rig")
@@ -217,7 +244,8 @@ class TestEventCreate(BaseRigboardTest):
self.page.person_selector.toggle()
self.assertFalse(self.page.person_selector.is_open)
self.page.start_date = datetime.date(1984, 1, 1)
# Note to self, don't set dates before 2014, which is the beginning of VAT as far as the tests are concerned...
self.page.start_date = datetime.date(2084, 1, 1)
modal = self.page.add_event_item()
self.wait.until(animation_is_finished())