Update config to use logo cdn

This commit is contained in:
Ken Tsang
2017-07-21 16:06:12 +01:00
parent 3878ece9ea
commit 3e6e75998b
3 changed files with 16 additions and 37 deletions

View File

@@ -115,7 +115,6 @@ class Config(object):
PAGE_SIZE = 50
API_PAGE_SIZE = 250
SMS_CHAR_COUNT_LIMIT = 495
BRANDING_PATH = '/images/email-template/crests/'
TEST_MESSAGE_FILENAME = 'Test message'
ONE_OFF_MESSAGE_FILENAME = 'Report'
MAX_VERIFY_CODE_COUNT = 10

View File

@@ -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)
def get_logo_url(base_url, branding_path, 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})
"""
def get_logo_url(base_url, logo_file):
base_url = parse.urlparse(base_url)
netloc = base_url.netloc
# covers both preview and staging
if base_url.netloc.startswith('localhost') or 'notify.works' in base_url.netloc:
path = '/static' + branding_path + logo_file
else:
if base_url.netloc.startswith('www'):
# strip "www."
netloc = base_url.netloc[4:]
if base_url.netloc.startswith('localhost'):
netloc = 'notify.tools'
elif base_url.netloc.startswith('www'):
# strip "www."
netloc = base_url.netloc[4:]
netloc = 'static.' + netloc
path = branding_path + logo_file
netloc = 'static-logos.' + netloc
logo_url = parse.ParseResult(
scheme=base_url.scheme,
netloc=netloc,
path=path,
path=logo_file,
params=base_url.params,
query=base_url.query,
fragment=base_url.fragment
@@ -185,7 +173,6 @@ def get_html_email_options(service):
if service.organisation:
logo_url = get_logo_url(
current_app.config['ADMIN_BASE_URL'],
current_app.config['BRANDING_PATH'],
service.organisation.logo
)