Allow test key to send irrespective of trial mode

When you use a simulate API key it should behave like a live service,
except for actually sending the messages. There should be no limits even
if the service is in trial mode.

This commit removes the restriction on sending messages to peole outside
your team when you’re in trial mode.
This commit is contained in:
Chris Hill-Scott
2016-08-30 10:47:27 +01:00
parent 287d32c037
commit 5eaec8c235
2 changed files with 46 additions and 7 deletions

View File

@@ -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,
@@ -259,12 +259,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 = 'Cant send to this recipient using a team-only API key'
else: