mirror of
https://github.com/ansible/awx.git
synced 2026-05-08 01:47:35 -02:30
Merge pull request #1160 from ryanpetrello/fix-old-rrule-dtstart
add a few schedule RRULE parsing improvements
This commit is contained in:
@@ -3887,6 +3887,7 @@ class SchedulePreviewSerializer(BaseSerializer):
|
|||||||
# - BYYEARDAY
|
# - BYYEARDAY
|
||||||
# - BYWEEKNO
|
# - BYWEEKNO
|
||||||
# - Multiple DTSTART or RRULE elements
|
# - Multiple DTSTART or RRULE elements
|
||||||
|
# - Can't contain both COUNT and UNTIL
|
||||||
# - COUNT > 999
|
# - COUNT > 999
|
||||||
def validate_rrule(self, value):
|
def validate_rrule(self, value):
|
||||||
rrule_value = value
|
rrule_value = value
|
||||||
@@ -3921,6 +3922,8 @@ class SchedulePreviewSerializer(BaseSerializer):
|
|||||||
raise serializers.ValidationError(_("BYYEARDAY not supported."))
|
raise serializers.ValidationError(_("BYYEARDAY not supported."))
|
||||||
if 'byweekno' in rrule_value.lower():
|
if 'byweekno' in rrule_value.lower():
|
||||||
raise serializers.ValidationError(_("BYWEEKNO not supported."))
|
raise serializers.ValidationError(_("BYWEEKNO not supported."))
|
||||||
|
if 'COUNT' in rrule_value and 'UNTIL' in rrule_value:
|
||||||
|
raise serializers.ValidationError(_("RRULE may not contain both COUNT and UNTIL"))
|
||||||
if match_count:
|
if match_count:
|
||||||
count_val = match_count.groups()[0].strip().split("=")
|
count_val = match_count.groups()[0].strip().split("=")
|
||||||
if int(count_val[1]) > 999:
|
if int(count_val[1]) > 999:
|
||||||
|
|||||||
@@ -150,14 +150,13 @@ class Schedule(CommonModel, LaunchTimeConfig):
|
|||||||
# > UTC time.
|
# > UTC time.
|
||||||
raise ValueError('RRULE UNTIL values must be specified in UTC')
|
raise ValueError('RRULE UNTIL values must be specified in UTC')
|
||||||
|
|
||||||
try:
|
if 'MINUTELY' in rrule or 'HOURLY' in rrule:
|
||||||
first_event = x[0]
|
try:
|
||||||
if first_event < now() - datetime.timedelta(days=365 * 5):
|
first_event = x[0]
|
||||||
# For older DTSTART values, if there are more than 1000 recurrences...
|
if first_event < now() - datetime.timedelta(days=365 * 5):
|
||||||
if len(x[:1001]) > 1000:
|
raise ValueError('RRULE values with more than 1000 events are not allowed.')
|
||||||
raise ValueError('RRULE values that yield more than 1000 events are not allowed.')
|
except IndexError:
|
||||||
except IndexError:
|
pass
|
||||||
pass
|
|
||||||
return x
|
return x
|
||||||
|
|
||||||
def __unicode__(self):
|
def __unicode__(self):
|
||||||
|
|||||||
@@ -66,6 +66,7 @@ def test_valid_survey_answer(post, admin_user, project, inventory, survey_spec_f
|
|||||||
("DTSTART:20300308T050000Z RRULE:FREQ=YEARLY;INTERVAL=1;BYWEEKNO=20", "BYWEEKNO not supported"),
|
("DTSTART:20300308T050000Z RRULE:FREQ=YEARLY;INTERVAL=1;BYWEEKNO=20", "BYWEEKNO not supported"),
|
||||||
("DTSTART:20300308T050000Z RRULE:FREQ=DAILY;INTERVAL=1;COUNT=2000", "COUNT > 999 is unsupported"), # noqa
|
("DTSTART:20300308T050000Z RRULE:FREQ=DAILY;INTERVAL=1;COUNT=2000", "COUNT > 999 is unsupported"), # noqa
|
||||||
("DTSTART:20300308T050000Z RRULE:FREQ=REGULARLY;INTERVAL=1", "rrule parsing failed validation: invalid 'FREQ': REGULARLY"), # noqa
|
("DTSTART:20300308T050000Z RRULE:FREQ=REGULARLY;INTERVAL=1", "rrule parsing failed validation: invalid 'FREQ': REGULARLY"), # noqa
|
||||||
|
("DTSTART:20030925T104941Z RRULE:FREQ=DAILY;INTERVAL=10;COUNT=500;UNTIL=20040925T104941Z", "RRULE may not contain both COUNT and UNTIL"), # noqa
|
||||||
("DTSTART;TZID=America/New_York:20300308T050000Z RRULE:FREQ=DAILY;INTERVAL=1", "rrule parsing failed validation"),
|
("DTSTART;TZID=America/New_York:20300308T050000Z RRULE:FREQ=DAILY;INTERVAL=1", "rrule parsing failed validation"),
|
||||||
("DTSTART:20300308T050000 RRULE:FREQ=DAILY;INTERVAL=1", "DTSTART cannot be a naive datetime"),
|
("DTSTART:20300308T050000 RRULE:FREQ=DAILY;INTERVAL=1", "DTSTART cannot be a naive datetime"),
|
||||||
("DTSTART:19700101T000000Z RRULE:FREQ=MINUTELY;INTERVAL=1", "more than 1000 events are not allowed"), # noqa
|
("DTSTART:19700101T000000Z RRULE:FREQ=MINUTELY;INTERVAL=1", "more than 1000 events are not allowed"), # noqa
|
||||||
|
|||||||
Reference in New Issue
Block a user