manager: forbid event recurrence end date too far in the future (#60553)
This commit is contained in:
parent
961862593b
commit
049b1e9db0
|
@ -211,6 +211,17 @@ class NewEventForm(forms.ModelForm):
|
|||
return None
|
||||
return recurrence_days
|
||||
|
||||
def clean_recurrence_end_date(self):
|
||||
recurrence_end_date = self.cleaned_data['recurrence_end_date']
|
||||
if recurrence_end_date and recurrence_end_date > now().date() + datetime.timedelta(days=3 * 365):
|
||||
raise ValidationError(
|
||||
_(
|
||||
'Recurrence end date cannot be more than 3 years from now. '
|
||||
'If the end date is not known, this field can simply be left blank.'
|
||||
)
|
||||
)
|
||||
return recurrence_end_date
|
||||
|
||||
def save(self, *args, **kwargs):
|
||||
with transaction.atomic():
|
||||
event = super().save(*args, **kwargs)
|
||||
|
|
|
@ -97,6 +97,11 @@ def test_add_recurring_event(app, admin_user):
|
|||
assert event.recurrence_days == [1]
|
||||
assert Event.objects.filter(primary_event=event).count() == 5
|
||||
|
||||
# add recurring event with end date in a very long time
|
||||
resp.form['recurrence_end_date'] = '2030-01-01'
|
||||
resp = resp.form.submit()
|
||||
assert 'Recurrence end date cannot be more than 3 years from now' in resp.text
|
||||
|
||||
|
||||
def test_add_event_on_missing_agenda(app, admin_user):
|
||||
app = login(app)
|
||||
|
|
Loading…
Reference in New Issue