mirror of
https://github.com/GSA/notifications-api.git
synced 2026-08-16 20:48:37 -04:00
Don’t require template when content is provided
So that the admin app can create broadcasts without a template it needs to be allowed to create broadcasts from content instead.
This commit is contained in:
@@ -15,8 +15,13 @@ 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},
|
||||
},
|
||||
'required': ['template_id', 'service_id', 'created_by'],
|
||||
'required': ['service_id', 'created_by'],
|
||||
'oneOf': [
|
||||
{'required': ['template_id']},
|
||||
{'required': ['content']},
|
||||
],
|
||||
'additionalProperties': False
|
||||
}
|
||||
|
||||
|
||||
@@ -99,22 +99,30 @@ def create_broadcast_message(service_id):
|
||||
validate(data, create_broadcast_message_schema)
|
||||
service = dao_fetch_service_by_id(data['service_id'])
|
||||
user = get_user_by_id(data['created_by'])
|
||||
template = dao_get_template_by_id_and_service_id(data['template_id'], data['service_id'])
|
||||
|
||||
personalisation = data.get('personalisation', {})
|
||||
template_id = data.get('template_id')
|
||||
|
||||
if template_id:
|
||||
template = dao_get_template_by_id_and_service_id(
|
||||
template_id, data['service_id']
|
||||
)
|
||||
content = template._as_utils_template_with_personalisation(
|
||||
personalisation
|
||||
).content_with_placeholders_filled_in
|
||||
else:
|
||||
template, content = None, data['content']
|
||||
|
||||
broadcast_message = BroadcastMessage(
|
||||
service_id=service.id,
|
||||
template_id=template.id,
|
||||
template_version=template.version,
|
||||
template_id=template_id,
|
||||
template_version=template.version if template else None,
|
||||
personalisation=personalisation,
|
||||
areas={"areas": data.get("areas", []), "simple_polygons": data.get("simple_polygons", [])},
|
||||
status=BroadcastStatusType.DRAFT,
|
||||
starts_at=_parse_nullable_datetime(data.get('starts_at')),
|
||||
finishes_at=_parse_nullable_datetime(data.get('finishes_at')),
|
||||
created_by_id=user.id,
|
||||
content=template._as_utils_template_with_personalisation(
|
||||
personalisation
|
||||
).content_with_placeholders_filled_in,
|
||||
content=content,
|
||||
)
|
||||
|
||||
dao_save_object(broadcast_message)
|
||||
|
||||
Reference in New Issue
Block a user