mirror of
https://github.com/GSA/notifications-api.git
synced 2025-12-14 17:22:17 -05:00
Update validators to use is_message_too_long()
- update check_sms_content_char_count to use the SMSTemplate.is_message_too_long function, and updated the error message to align with the message returned by the admin app. - Update the the code used by version 1 of the api to use the validate_template method. - I did find a couple of services still using the old api, however, this change should not affect them as I checked the messages being sent and they are not too long. - We will be sending a message to them to see if they can upgrade. - Update the log message for authenication to include the URL - makes it easier to track if a service is using version 1 of the api.
This commit is contained in:
@@ -124,9 +124,10 @@ def validate_and_format_recipient(send_to, key_type, service, notification_type,
|
||||
return validate_and_format_email_address(email_address=send_to)
|
||||
|
||||
|
||||
def check_sms_content_char_count(content_count):
|
||||
if content_count > SMS_CHAR_COUNT_LIMIT:
|
||||
message = 'Content for template has a character count greater than the limit of {}'.format(SMS_CHAR_COUNT_LIMIT)
|
||||
def check_content_char_count(template_with_content):
|
||||
if template_with_content.is_message_too_long():
|
||||
message = f"Text messages cannot be longer than {SMS_CHAR_COUNT_LIMIT} characters. " \
|
||||
f"Your message is {template_with_content.content_count_without_prefix} characters"
|
||||
raise BadRequestError(message=message)
|
||||
|
||||
|
||||
@@ -151,9 +152,10 @@ def validate_template(template_id, personalisation, service, notification_type):
|
||||
check_template_is_active(template)
|
||||
|
||||
template_with_content = create_content_for_notification(template, personalisation)
|
||||
|
||||
check_notification_content_is_not_empty(template_with_content)
|
||||
if template.template_type == SMS_TYPE:
|
||||
check_sms_content_char_count(template_with_content.content_count)
|
||||
|
||||
check_content_char_count(template_with_content)
|
||||
|
||||
return template, template_with_content
|
||||
|
||||
|
||||
Reference in New Issue
Block a user