Update emails to use logos cdn

This commit is contained in:
Ken Tsang
2017-07-24 15:20:40 +01:00
parent a60b3b4bc2
commit 35f66cae23
6 changed files with 47 additions and 6 deletions

View File

@@ -54,6 +54,7 @@ from app.notify_client.provider_client import ProviderClient
from app.notify_client.organisations_client import OrganisationsClient
from app.notify_client.models import AnonymousUser
from app.notify_client.letter_jobs_client import LetterJobsClient
from app.utils import get_cdn_domain
from app.utils import gmt_timezones
@@ -415,8 +416,8 @@ def useful_headers_after_request(response):
"script-src 'self' *.google-analytics.com 'unsafe-inline' 'unsafe-eval' data:;"
"object-src 'self';"
"font-src 'self' data:;"
"img-src 'self' *.google-analytics.com *.notifications.service.gov.uk data:;"
"frame-src www.youtube.com;"
"img-src 'self' *.google-analytics.com *.notifications.service.gov.uk {} data:;"
"frame-src www.youtube.com;".format(get_cdn_domain())
))
if 'Cache-Control' in response.headers:
del response.headers['Cache-Control']

View File

@@ -87,6 +87,8 @@ class Config(object):
r"cqc\.org\.uk",
]
LOGO_UPLOAD_BUCKET_NAME = 'local-notifications-logo-upload'
class Development(Config):
DEBUG = True
@@ -94,6 +96,7 @@ class Development(Config):
SESSION_PROTECTION = None
STATSD_ENABLED = False
CSV_UPLOAD_BUCKET_NAME = 'development-notifications-csv-upload'
LOGO_UPLOAD_BUCKET_NAME = 'development-notifications-logo-upload'
class Test(Development):
@@ -102,6 +105,7 @@ class Test(Development):
STATSD_ENABLED = True
WTF_CSRF_ENABLED = False
CSV_UPLOAD_BUCKET_NAME = 'test-notifications-csv-upload'
LOGO_UPLOAD_BUCKET_NAME = 'test-notifications-logo-upload'
NOTIFY_ENVIRONMENT = 'test'
TEMPLATE_PREVIEW_API_HOST = 'http://localhost:9999'
@@ -111,6 +115,7 @@ class Preview(Config):
HEADER_COLOUR = '#F499BE' # $baby-pink
STATSD_ENABLED = True
CSV_UPLOAD_BUCKET_NAME = 'preview-notifications-csv-upload'
LOGO_UPLOAD_BUCKET_NAME = 'preview-notifications-logo-upload'
NOTIFY_ENVIRONMENT = 'preview'
@@ -120,6 +125,7 @@ class Staging(Config):
HEADER_COLOUR = '#6F72AF' # $mauve
STATSD_ENABLED = True
CSV_UPLOAD_BUCKET_NAME = 'staging-notify-csv-upload'
LOGO_UPLOAD_BUCKET_NAME = 'staging-notifications-logo-upload'
NOTIFY_ENVIRONMENT = 'staging'
@@ -129,6 +135,7 @@ class Live(Config):
HTTP_PROTOCOL = 'https'
STATSD_ENABLED = True
CSV_UPLOAD_BUCKET_NAME = 'live-notifications-csv-upload'
LOGO_UPLOAD_BUCKET_NAME = 'live-notifications-logo-upload'
NOTIFY_ENVIRONMENT = 'live'
@@ -142,6 +149,7 @@ class Sandbox(CloudFoundryConfig):
HEADER_COLOUR = '#F499BE' # $baby-pink
STATSD_ENABLED = True
CSV_UPLOAD_BUCKET_NAME = 'cf-sandbox-notifications-csv-upload'
LOGO_UPLOAD_BUCKET_NAME = 'cf-sandbox-notifications-logo-upload'
NOTIFY_ENVIRONMENT = 'sandbox'

View File

@@ -22,7 +22,7 @@ from notifications_python_client.errors import HTTPError
from app import service_api_client
from app.main import main
from app.utils import user_has_permissions, email_safe
from app.utils import user_has_permissions, email_safe, get_cdn_domain
from app.main.forms import (
ConfirmPasswordForm,
ServiceNameForm,
@@ -464,7 +464,7 @@ def get_branding_as_value_and_label(organisations):
def get_branding_as_dict(organisations):
return {
organisation['id']: {
'logo': '/static/images/email-template/crests/{}'.format(organisation['logo']),
'logo': 'https://{}/{}'.format(get_cdn_domain(), organisation['logo']),
'colour': organisation['colour']
} for organisation in organisations
}

View File

@@ -5,6 +5,7 @@ from io import StringIO
from os import path
from functools import wraps
import unicodedata
from urllib.parse import urlparse
from collections import namedtuple
from datetime import datetime, timedelta, timezone
from dateutil import parser
@@ -364,3 +365,15 @@ def gmt_timezones(date):
date = dateutil.parser.parse(date)
forced_utc = date.replace(tzinfo=pytz.utc)
return forced_utc.astimezone(pytz.timezone('Europe/London'))
def get_cdn_domain():
parsed_uri = urlparse(current_app.config['ADMIN_BASE_URL'])
if parsed_uri.netloc.startswith('localhost'):
return 'static-logos.notify.tools'
subdomain = parsed_uri.hostname.split('.')[0]
domain = parsed_uri.netloc[len(subdomain + '.'):]
return "static-logos.{}".format(domain)