mirror of
https://github.com/GSA/notifications-api.git
synced 2025-12-17 10:42:25 -05:00
- Refactor version 1 of post notificaitons to use the common persist_notificaiton and send_notification_to_queue methods.
- It would be nice to refactor the send_sms and send_email tasks to use these common functions as well, that way I can get rid of the new Notifications.from_v2_api_request method. - Still not happy with the format of the errors. Would like to find a happy place, where the message is descript enough that we do not need external documentation to explain the error. Perhaps we still only need documentation to explain the trial mode concept.
This commit is contained in:
@@ -18,18 +18,15 @@ def check_template_is_for_notification_type(notification_type, template_type):
|
||||
if notification_type != template_type:
|
||||
raise BadRequestError(
|
||||
message="{0} template is not suitable for {1} notification".format(template_type,
|
||||
notification_type),
|
||||
fields=[{"template": "{0} template is not suitable for {1} notification".format(template_type,
|
||||
notification_type)}])
|
||||
notification_type))
|
||||
|
||||
|
||||
def check_template_is_active(template):
|
||||
if template.archived:
|
||||
raise BadRequestError(fields=[{"template": "has been deleted"}],
|
||||
message="Template has been deleted")
|
||||
raise BadRequestError(message="Template has been deleted")
|
||||
|
||||
|
||||
def service_can_send_to_recipient(send_to, key_type, service, recipient_type):
|
||||
def service_can_send_to_recipient(send_to, key_type, service):
|
||||
if not service_allowed_to_send_to(send_to, service, key_type):
|
||||
if key_type == KEY_TYPE_TEAM:
|
||||
message = 'Can’t send to this recipient using a team-only API key'
|
||||
@@ -38,9 +35,7 @@ def service_can_send_to_recipient(send_to, key_type, service, recipient_type):
|
||||
'Can’t send to this recipient when service is in trial mode '
|
||||
'– see https://www.notifications.service.gov.uk/trial-mode'
|
||||
)
|
||||
raise BadRequestError(
|
||||
fields={recipient_type: [message]}
|
||||
)
|
||||
raise BadRequestError(message=message)
|
||||
|
||||
|
||||
def check_sms_content_char_count(content_count):
|
||||
@@ -48,6 +43,5 @@ def check_sms_content_char_count(content_count):
|
||||
if (
|
||||
content_count > char_count_limit
|
||||
):
|
||||
message = 'Content has a character count greater than the limit of {}'.format(char_count_limit)
|
||||
errors = {'content': [message]}
|
||||
raise BadRequestError(fields=errors)
|
||||
message = 'Content for template has a character count greater than the limit of {}'.format(char_count_limit)
|
||||
raise BadRequestError(message=message)
|
||||
|
||||
Reference in New Issue
Block a user