Normalise broadcast content before validating length

This changes the content length validation of the internal API to match
the validation of the public broadcast API[1].

This removes the length check from JSONSchema, which isn’t sophisticated
enough to deal with things like normalising newlines or handling
different encodings.

The admin app should catch these errors before they’re raised here, but
it’s best to be belt and braces.

1.7ab0403ae7/app/v2/broadcast/post_broadcast.py (L53-L63)
This commit is contained in:
Chris Hill-Scott
2021-04-22 14:42:54 +01:00
parent 7ab0403ae7
commit 7c6ae40034
3 changed files with 49 additions and 1 deletions

View File

@@ -15,7 +15,7 @@ create_broadcast_message_schema = {
'finishes_at': {'type': 'string', 'format': 'datetime'},
'areas': {"type": "array", "items": {"type": "string"}},
'simple_polygons': {"type": "array", "items": {"type": "array"}},
'content': {'type': 'string', 'minLength': 1, 'maxLength': 1395},
'content': {'type': 'string', 'minLength': 1},
'reference': {'type': 'string', 'minLength': 1, 'maxLength': 255},
},
'required': ['service_id', 'created_by'],