Fix: Validate source_date in copy availability endpoint

Added validation to ensure source_date is within the allowed range
(tomorrow to +30 days) for consistency with target_dates validation.
This commit is contained in:
counterweight 2025-12-21 17:28:21 +01:00
parent 63cf46c230
commit 19c313767c
Signed by: counterweight
GPG key ID: 883EDBAA726BD96C
2 changed files with 17 additions and 0 deletions

View file

@ -141,6 +141,9 @@ async def copy_availability(
"""Copy availability from one day to multiple target days."""
min_date, max_date = _get_date_range_bounds()
# Validate source date is in range (for consistency, though DB query would fail anyway)
_validate_date_in_range(request.source_date, min_date, max_date)
# Validate target dates
for target_date in request.target_dates:
_validate_date_in_range(target_date, min_date, max_date)

View file

@ -524,3 +524,17 @@ class TestCopyAvailability:
assert response.status_code == 400
assert "30" in response.json()["detail"]
@pytest.mark.asyncio
async def test_copy_validates_source_date(self, client_factory, admin_user):
"""Cannot copy from a past source date."""
async with client_factory.create(cookies=admin_user["cookies"]) as client:
response = await client.post(
"/api/admin/availability/copy",
json={
"source_date": str(date.today() - timedelta(days=1)), # Yesterday
"target_dates": [str(in_days(1))],
},
)
assert response.status_code == 400
assert "past" in response.json()["detail"].lower()