mirror of
https://github.com/GSA/notifications-api.git
synced 2025-12-23 00:41:35 -05:00
All services can send files by email if they have set contact_link
This commit is contained in:
@@ -85,7 +85,13 @@ def service_has_permission(notify_type, permissions):
|
||||
def check_service_has_permission(notify_type, permissions):
|
||||
if not service_has_permission(notify_type, permissions):
|
||||
raise BadRequestError(message="Service is not allowed to send {}".format(
|
||||
get_public_notify_type_text(notify_type, plural=True)))
|
||||
get_public_notify_type_text(notify_type, plural=True)
|
||||
))
|
||||
|
||||
|
||||
def check_if_service_can_send_files_by_email(service_contact_link):
|
||||
if not service_contact_link:
|
||||
raise BadRequestError(message="Go to Service Settings to turn on sending files by email")
|
||||
|
||||
|
||||
def check_service_can_schedule_notification(permissions, scheduled_for):
|
||||
|
||||
@@ -16,7 +16,6 @@ from app.models import (
|
||||
SMS_TYPE,
|
||||
EMAIL_TYPE,
|
||||
LETTER_TYPE,
|
||||
UPLOAD_DOCUMENT,
|
||||
PRIORITY,
|
||||
KEY_TYPE_TEST,
|
||||
KEY_TYPE_TEAM,
|
||||
@@ -35,13 +34,14 @@ from app.notifications.process_notifications import (
|
||||
simulated_recipient
|
||||
)
|
||||
from app.notifications.validators import (
|
||||
validate_and_format_recipient,
|
||||
check_if_service_can_send_files_by_email,
|
||||
check_rate_limiting,
|
||||
check_service_can_schedule_notification,
|
||||
check_service_has_permission,
|
||||
validate_template,
|
||||
check_service_email_reply_to_id,
|
||||
check_service_sms_sender_id
|
||||
check_service_has_permission,
|
||||
check_service_sms_sender_id,
|
||||
validate_and_format_recipient,
|
||||
validate_template,
|
||||
)
|
||||
from app.schema_validation import validate
|
||||
from app.v2.errors import BadRequestError
|
||||
@@ -235,7 +235,7 @@ def process_document_uploads(personalisation_data, service, simulated=False):
|
||||
|
||||
personalisation_data = personalisation_data.copy()
|
||||
|
||||
check_service_has_permission(UPLOAD_DOCUMENT, authenticated_service.permissions)
|
||||
check_if_service_can_send_files_by_email(authenticated_service.contact_link)
|
||||
|
||||
for key in file_keys:
|
||||
if simulated:
|
||||
|
||||
@@ -8,6 +8,7 @@ from app.dao import templates_dao
|
||||
from app.models import SMS_TYPE, EMAIL_TYPE, LETTER_TYPE
|
||||
from app.notifications.process_notifications import create_content_for_notification
|
||||
from app.notifications.validators import (
|
||||
check_if_service_can_send_files_by_email,
|
||||
check_notification_content_is_not_empty,
|
||||
check_service_over_daily_message_limit,
|
||||
check_template_is_for_notification_type,
|
||||
@@ -528,3 +529,15 @@ def test_check_reply_to_sms_type(sample_service):
|
||||
def test_check_reply_to_letter_type(sample_service):
|
||||
letter_contact = create_letter_contact(service=sample_service, contact_block='123456')
|
||||
assert check_reply_to(sample_service.id, letter_contact.id, LETTER_TYPE) == '123456'
|
||||
|
||||
|
||||
def test_check_if_service_can_send_files_by_email_raises_if_no_contact_link_set(sample_service):
|
||||
with pytest.raises(BadRequestError) as e:
|
||||
check_if_service_can_send_files_by_email(sample_service.contact_link)
|
||||
assert e.value.status_code == 400
|
||||
assert e.value.message == "Go to Service Settings to turn on sending files by email"
|
||||
|
||||
|
||||
def test_check_if_service_can_send_files_by_email_passes_if_contact_link_set(sample_service):
|
||||
sample_service.contact_link = 'contact.me@gov.uk'
|
||||
check_if_service_can_send_files_by_email(sample_service.contact_link)
|
||||
|
||||
@@ -11,7 +11,6 @@ from app.models import (
|
||||
NOTIFICATION_CREATED,
|
||||
SCHEDULE_NOTIFICATIONS,
|
||||
SMS_TYPE,
|
||||
UPLOAD_DOCUMENT,
|
||||
INTERNATIONAL_SMS_TYPE
|
||||
)
|
||||
from flask import json, current_app
|
||||
@@ -775,7 +774,8 @@ def test_post_email_notification_with_archived_reply_to_id_returns_400(client, s
|
||||
|
||||
|
||||
def test_post_notification_with_document_upload(client, notify_db_session, mocker):
|
||||
service = create_service(service_permissions=[EMAIL_TYPE, UPLOAD_DOCUMENT])
|
||||
service = create_service(service_permissions=[EMAIL_TYPE])
|
||||
service.contact_link = 'contact.me@gov.uk'
|
||||
template = create_template(
|
||||
service=service,
|
||||
template_type='email',
|
||||
@@ -822,7 +822,8 @@ def test_post_notification_with_document_upload(client, notify_db_session, mocke
|
||||
|
||||
|
||||
def test_post_notification_with_document_upload_simulated(client, notify_db_session, mocker):
|
||||
service = create_service(service_permissions=[EMAIL_TYPE, UPLOAD_DOCUMENT])
|
||||
service = create_service(service_permissions=[EMAIL_TYPE])
|
||||
service.contact_link = 'contact.me@gov.uk'
|
||||
template = create_template(
|
||||
service=service,
|
||||
template_type='email',
|
||||
|
||||
Reference in New Issue
Block a user