mirror of
https://github.com/GSA/notifications-api.git
synced 2025-12-14 17:22:17 -05:00
Merge pull request #645 from alphagov/no-restrictions-on-test-key
Remove restrictions when using simulate API key
This commit is contained in:
@@ -15,7 +15,7 @@ from notifications_utils.renderers import PassThrough
|
||||
from app.clients.email.aws_ses import get_aws_responses
|
||||
from app import api_user, encryption, create_uuid, DATETIME_FORMAT, DATE_FORMAT, statsd_client
|
||||
from app.dao.services_dao import dao_fetch_todays_stats_for_service
|
||||
from app.models import KEY_TYPE_TEAM
|
||||
from app.models import KEY_TYPE_TEAM, KEY_TYPE_TEST
|
||||
from app.dao import (
|
||||
templates_dao,
|
||||
services_dao,
|
||||
@@ -215,7 +215,10 @@ def send_notification(notification_type):
|
||||
|
||||
service_stats = sum(row.count for row in dao_fetch_todays_stats_for_service(service.id))
|
||||
|
||||
if service_stats >= service.message_limit:
|
||||
if all((
|
||||
api_user.key_type != KEY_TYPE_TEST,
|
||||
service_stats >= service.message_limit
|
||||
)):
|
||||
error = 'Exceeded send limits ({}) for today'.format(service.message_limit)
|
||||
raise InvalidRequest(error, status_code=429)
|
||||
|
||||
@@ -259,12 +262,16 @@ def send_notification(notification_type):
|
||||
errors = {'content': [message]}
|
||||
raise InvalidRequest(errors, status_code=400)
|
||||
|
||||
if (service.restricted or api_user.key_type == KEY_TYPE_TEAM) and not allowed_to_send_to(
|
||||
notification['to'],
|
||||
itertools.chain.from_iterable(
|
||||
[user.mobile_number, user.email_address] for user in service.users
|
||||
if all((
|
||||
api_user.key_type != KEY_TYPE_TEST,
|
||||
service.restricted or api_user.key_type == KEY_TYPE_TEAM,
|
||||
not allowed_to_send_to(
|
||||
notification['to'],
|
||||
itertools.chain.from_iterable(
|
||||
[user.mobile_number, user.email_address] for user in service.users
|
||||
)
|
||||
)
|
||||
):
|
||||
)):
|
||||
if (api_user.key_type == KEY_TYPE_TEAM):
|
||||
message = 'Can’t send to this recipient using a team-only API key'
|
||||
else:
|
||||
|
||||
Reference in New Issue
Block a user