mirror of
https://github.com/GSA/notifications-api.git
synced 2026-02-01 07:35:34 -05:00
Refactored code to use new service permissions only
This commit is contained in:
@@ -23,7 +23,7 @@ from app.celery.statistics_tasks import record_initial_job_statistics, create_in
|
||||
|
||||
def send_sms_to_provider(notification):
|
||||
service = notification.service
|
||||
|
||||
print('send')
|
||||
if not service.active:
|
||||
technical_failure(notification=notification)
|
||||
return
|
||||
|
||||
@@ -16,7 +16,7 @@ from app.errors import (
|
||||
InvalidRequest
|
||||
)
|
||||
from app.models import KEY_TYPE_TEAM, PRIORITY
|
||||
from app.models import SMS_TYPE
|
||||
from app.models import INTERNATIONAL_SMS_TYPE, SMS_TYPE
|
||||
from app.notifications.process_notifications import (
|
||||
persist_notification,
|
||||
send_notification_to_queue,
|
||||
@@ -165,7 +165,8 @@ def get_notification_return_data(notification_id, notification, template):
|
||||
def _service_can_send_internationally(service, number):
|
||||
international_phone_info = get_international_phone_info(number)
|
||||
|
||||
if international_phone_info.international and 'international_sms' not in service.permissions:
|
||||
if international_phone_info.international and \
|
||||
INTERNATIONAL_SMS_TYPE not in [p.permission for p in service.permissions]:
|
||||
raise InvalidRequest(
|
||||
{'to': ["Cannot send to international mobile numbers"]},
|
||||
status_code=400
|
||||
|
||||
@@ -8,7 +8,7 @@ from notifications_utils.recipients import (
|
||||
from notifications_utils.clients.redis import rate_limit_cache_key, daily_limit_cache_key
|
||||
|
||||
from app.dao import services_dao, templates_dao
|
||||
from app.models import KEY_TYPE_TEST, KEY_TYPE_TEAM, SMS_TYPE, SCHEDULE_NOTIFICATIONS
|
||||
from app.models import INTERNATIONAL_SMS_TYPE, KEY_TYPE_TEST, KEY_TYPE_TEAM, SMS_TYPE, SCHEDULE_NOTIFICATIONS
|
||||
from app.service.utils import service_allowed_to_send_to
|
||||
from app.v2.errors import TooManyRequestsError, BadRequestError, RateLimitError
|
||||
from app import redis_store
|
||||
@@ -76,7 +76,8 @@ def validate_and_format_recipient(send_to, key_type, service, notification_type)
|
||||
if notification_type == SMS_TYPE:
|
||||
international_phone_info = get_international_phone_info(send_to)
|
||||
|
||||
if international_phone_info.international and 'international_sms' not in service.permissions:
|
||||
if international_phone_info.international and \
|
||||
INTERNATIONAL_SMS_TYPE not in [p.permission for p in service.permissions]:
|
||||
raise BadRequestError(message="Cannot send to international mobile numbers")
|
||||
|
||||
return validate_and_format_phone_number(
|
||||
|
||||
@@ -142,7 +142,6 @@ def update_service(service_id):
|
||||
service_going_live = fetched_service.restricted and not request.get_json().get('restricted', True)
|
||||
|
||||
current_data = dict(service_schema.dump(fetched_service).data.items())
|
||||
service_schema.set_override_flag(request.get_json().get('permissions') is not None)
|
||||
current_data.update(request.get_json())
|
||||
update_dict = service_schema.load(current_data).data
|
||||
dao_update_service(update_dict)
|
||||
|
||||
Reference in New Issue
Block a user