mirror of
https://github.com/GSA/notifications-api.git
synced 2025-12-18 16:12:32 -05:00
Update config to use logo cdn
This commit is contained in:
@@ -115,7 +115,6 @@ class Config(object):
|
|||||||
PAGE_SIZE = 50
|
PAGE_SIZE = 50
|
||||||
API_PAGE_SIZE = 250
|
API_PAGE_SIZE = 250
|
||||||
SMS_CHAR_COUNT_LIMIT = 495
|
SMS_CHAR_COUNT_LIMIT = 495
|
||||||
BRANDING_PATH = '/images/email-template/crests/'
|
|
||||||
TEST_MESSAGE_FILENAME = 'Test message'
|
TEST_MESSAGE_FILENAME = 'Test message'
|
||||||
ONE_OFF_MESSAGE_FILENAME = 'Report'
|
ONE_OFF_MESSAGE_FILENAME = 'Report'
|
||||||
MAX_VERIFY_CODE_COUNT = 10
|
MAX_VERIFY_CODE_COUNT = 10
|
||||||
|
|||||||
@@ -145,34 +145,22 @@ def provider_to_use(notification_type, notification_id, international=False):
|
|||||||
return clients.get_client_by_name_and_type(active_providers_in_order[0].identifier, notification_type)
|
return clients.get_client_by_name_and_type(active_providers_in_order[0].identifier, notification_type)
|
||||||
|
|
||||||
|
|
||||||
def get_logo_url(base_url, branding_path, logo_file):
|
def get_logo_url(base_url, logo_file):
|
||||||
"""
|
|
||||||
Get the complete URL for a given logo.
|
|
||||||
|
|
||||||
We have to convert the base_url into a static url. Our hosted environments all have their own cloudfront instances,
|
|
||||||
found at the static subdomain (eg https://static.notifications.service.gov.uk).
|
|
||||||
|
|
||||||
If running locally (dev environment), don't try and use cloudfront - just stick to the actual underlying source
|
|
||||||
({URL}/static/{PATH})
|
|
||||||
"""
|
|
||||||
base_url = parse.urlparse(base_url)
|
base_url = parse.urlparse(base_url)
|
||||||
netloc = base_url.netloc
|
netloc = base_url.netloc
|
||||||
|
|
||||||
# covers both preview and staging
|
if base_url.netloc.startswith('localhost'):
|
||||||
if base_url.netloc.startswith('localhost') or 'notify.works' in base_url.netloc:
|
netloc = 'notify.tools'
|
||||||
path = '/static' + branding_path + logo_file
|
elif base_url.netloc.startswith('www'):
|
||||||
else:
|
# strip "www."
|
||||||
if base_url.netloc.startswith('www'):
|
netloc = base_url.netloc[4:]
|
||||||
# strip "www."
|
|
||||||
netloc = base_url.netloc[4:]
|
|
||||||
|
|
||||||
netloc = 'static.' + netloc
|
netloc = 'static-logos.' + netloc
|
||||||
path = branding_path + logo_file
|
|
||||||
|
|
||||||
logo_url = parse.ParseResult(
|
logo_url = parse.ParseResult(
|
||||||
scheme=base_url.scheme,
|
scheme=base_url.scheme,
|
||||||
netloc=netloc,
|
netloc=netloc,
|
||||||
path=path,
|
path=logo_file,
|
||||||
params=base_url.params,
|
params=base_url.params,
|
||||||
query=base_url.query,
|
query=base_url.query,
|
||||||
fragment=base_url.fragment
|
fragment=base_url.fragment
|
||||||
@@ -185,7 +173,6 @@ def get_html_email_options(service):
|
|||||||
if service.organisation:
|
if service.organisation:
|
||||||
logo_url = get_logo_url(
|
logo_url = get_logo_url(
|
||||||
current_app.config['ADMIN_BASE_URL'],
|
current_app.config['ADMIN_BASE_URL'],
|
||||||
current_app.config['BRANDING_PATH'],
|
|
||||||
service.organisation.logo
|
service.organisation.logo
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|||||||
@@ -435,29 +435,22 @@ def test_get_html_email_renderer_prepends_logo_path(notify_api):
|
|||||||
|
|
||||||
renderer = send_to_providers.get_html_email_options(service)
|
renderer = send_to_providers.get_html_email_options(service)
|
||||||
|
|
||||||
assert renderer['brand_logo'] == 'http://localhost:6012/static/images/email-template/crests/justice-league.png'
|
assert renderer['brand_logo'] == 'http://static-logos.notify.tools/justice-league.png'
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.parametrize('base_url, expected_url', [
|
@pytest.mark.parametrize('base_url, expected_url', [
|
||||||
# don't change localhost to prevent errors when testing locally
|
# don't change localhost to prevent errors when testing locally
|
||||||
('http://localhost:6012', 'http://localhost:6012/static/sub-path/filename.png'),
|
('http://localhost:6012', 'http://static-logos.notify.tools/filename.png'),
|
||||||
# on other environments, replace www with staging
|
('https://www.notifications.service.gov.uk', 'https://static-logos.notifications.service.gov.uk/filename.png'),
|
||||||
('https://www.notifications.service.gov.uk', 'https://static.notifications.service.gov.uk/sub-path/filename.png'),
|
('https://notify.works', 'https://static-logos.notify.works/filename.png'),
|
||||||
|
('https://staging-notify.works', 'https://static-logos.staging-notify.works/filename.png'),
|
||||||
# staging and preview do not have cloudfront running, so should act as localhost
|
('https://www.notify.works', 'https://static-logos.notify.works/filename.png'),
|
||||||
pytest.mark.xfail(('https://www.notify.works', 'https://static.notify.works/sub-path/filename.png')),
|
('https://www.staging-notify.works', 'https://static-logos.staging-notify.works/filename.png'),
|
||||||
pytest.mark.xfail(('https://www.staging-notify.works', 'https://static.notify.works/sub-path/filename.png')),
|
|
||||||
pytest.mark.xfail(('https://notify.works', 'https://static.notify.works/sub-path/filename.png')),
|
|
||||||
pytest.mark.xfail(('https://staging-notify.works', 'https://static.notify.works/sub-path/filename.png')),
|
|
||||||
# these tests should be removed when cloudfront works on staging/preview
|
|
||||||
('https://www.notify.works', 'https://www.notify.works/static/sub-path/filename.png'),
|
|
||||||
('https://www.staging-notify.works', 'https://www.staging-notify.works/static/sub-path/filename.png'),
|
|
||||||
])
|
])
|
||||||
def test_get_logo_url_works_for_different_environments(base_url, expected_url):
|
def test_get_logo_url_works_for_different_environments(base_url, expected_url):
|
||||||
branding_path = '/sub-path/'
|
|
||||||
logo_file = 'filename.png'
|
logo_file = 'filename.png'
|
||||||
|
|
||||||
logo_url = send_to_providers.get_logo_url(base_url, branding_path, logo_file)
|
logo_url = send_to_providers.get_logo_url(base_url, logo_file)
|
||||||
|
|
||||||
assert logo_url == expected_url
|
assert logo_url == expected_url
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user