Slightly changed to only unlimited the live services.

Logic:
- live services don't check days limit for now
- restricted services check limits
(caveat) simulate keys aren't checking day limit even in restricted mode.
This commit is contained in:
Martyn Inglis
2016-09-06 14:21:36 +01:00
parent d6a8780515
commit 259fb0cb62
2 changed files with 108 additions and 2 deletions

View File

@@ -196,6 +196,12 @@ def send_notification(notification_type):
sms_template_notification_schema if notification_type == SMS_TYPE else email_notification_schema
).load(request.get_json())
if all((api_user.key_type != KEY_TYPE_TEST, service.restricted)):
service_stats = sum(row.count for row in dao_fetch_todays_stats_for_service(service.id))
if service_stats >= service.message_limit:
error = 'Exceeded send limits ({}) for today'.format(service.message_limit)
raise InvalidRequest(error, status_code=429)
if errors:
raise InvalidRequest(errors, status_code=400)
@@ -224,8 +230,8 @@ def send_notification(notification_type):
raise InvalidRequest(errors, status_code=400)
if (
template_object.template_type == SMS_TYPE and
template_object.replaced_content_count > current_app.config.get('SMS_CHAR_COUNT_LIMIT')
template_object.template_type == SMS_TYPE and
template_object.replaced_content_count > current_app.config.get('SMS_CHAR_COUNT_LIMIT')
):
char_count = current_app.config.get('SMS_CHAR_COUNT_LIMIT')
message = 'Content has a character count greater than the limit of {}'.format(char_count)