Skip to content

Commit bb99c31

Browse files
author
ferzunzu
committed
Validate that the start date is earlier than the maximum year of the library datetime.
1 parent f0eb001 commit bb99c31

File tree

2 files changed

+21
-0
lines changed

2 files changed

+21
-0
lines changed

taiga/projects/milestones/models.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,10 @@ def __repr__(self):
7272
return "<Milestone {0}>".format(self.id)
7373

7474
def clean(self):
75+
76+
if self.estimated_start and self.estimated_start.year == datetime.MAXYEAR:
77+
raise ValidationError(_("Invalid estimated start year, it must be less than 9999."))
78+
7579
# Don't allow draft entries to have a pub_date.
7680
if self.estimated_start and self.estimated_finish and self.estimated_start >= self.estimated_finish:
7781
raise ValidationError(_('The estimated start must be previous to the estimated finish.'))

tests/integration/resources_permissions/test_milestones_resources.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -295,6 +295,23 @@ def test_milestone_create(client, data):
295295
assert results == [401, 403, 403, 451, 451]
296296

297297

298+
def test_milestone_create_invalid_dates(client, data):
299+
url = reverse('milestones-list')
300+
301+
user = data.project_owner
302+
create_data = json.dumps({
303+
"name": "test",
304+
"estimated_start": "9999-12-10",
305+
"estimated_finish": "9999-12-24",
306+
"project": data.public_project.pk,
307+
})
308+
309+
client.login(user)
310+
311+
response = client.post(url, create_data, content_type="application/json")
312+
assert response.status_code == 400
313+
assert response.data["__all__"][0] == "Invalid estimated start year, it must be less than 9999."
314+
298315
def test_milestone_patch(client, data):
299316
public_url = reverse('milestones-detail', kwargs={"pk": data.public_milestone.pk})
300317
private_url1 = reverse('milestones-detail', kwargs={"pk": data.private_milestone1.pk})

0 commit comments

Comments
 (0)