mirror of
https://github.com/GSA/notifications-admin.git
synced 2026-09-06 09:28:26 -04:00
Merge pull request #1392 from alphagov/ken-update-org-logos-use-s3
Update org logos to use logo CDN
This commit is contained in:
@@ -54,6 +54,7 @@ from app.notify_client.provider_client import ProviderClient
|
|||||||
from app.notify_client.organisations_client import OrganisationsClient
|
from app.notify_client.organisations_client import OrganisationsClient
|
||||||
from app.notify_client.models import AnonymousUser
|
from app.notify_client.models import AnonymousUser
|
||||||
from app.notify_client.letter_jobs_client import LetterJobsClient
|
from app.notify_client.letter_jobs_client import LetterJobsClient
|
||||||
|
from app.utils import get_cdn_domain
|
||||||
|
|
||||||
from app.utils import gmt_timezones
|
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:;"
|
"script-src 'self' *.google-analytics.com 'unsafe-inline' 'unsafe-eval' data:;"
|
||||||
"object-src 'self';"
|
"object-src 'self';"
|
||||||
"font-src 'self' data:;"
|
"font-src 'self' data:;"
|
||||||
"img-src 'self' *.google-analytics.com *.notifications.service.gov.uk data:;"
|
"img-src 'self' *.google-analytics.com *.notifications.service.gov.uk {} data:;"
|
||||||
"frame-src www.youtube.com;"
|
"frame-src www.youtube.com;".format(get_cdn_domain())
|
||||||
))
|
))
|
||||||
if 'Cache-Control' in response.headers:
|
if 'Cache-Control' in response.headers:
|
||||||
del response.headers['Cache-Control']
|
del response.headers['Cache-Control']
|
||||||
|
|||||||
@@ -22,7 +22,7 @@ from notifications_python_client.errors import HTTPError
|
|||||||
|
|
||||||
from app import service_api_client
|
from app import service_api_client
|
||||||
from app.main import main
|
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 (
|
from app.main.forms import (
|
||||||
ConfirmPasswordForm,
|
ConfirmPasswordForm,
|
||||||
ServiceNameForm,
|
ServiceNameForm,
|
||||||
@@ -464,7 +464,7 @@ def get_branding_as_value_and_label(organisations):
|
|||||||
def get_branding_as_dict(organisations):
|
def get_branding_as_dict(organisations):
|
||||||
return {
|
return {
|
||||||
organisation['id']: {
|
organisation['id']: {
|
||||||
'logo': '/static/images/email-template/crests/{}'.format(organisation['logo']),
|
'logo': 'https://{}/{}'.format(get_cdn_domain(), organisation['logo']),
|
||||||
'colour': organisation['colour']
|
'colour': organisation['colour']
|
||||||
} for organisation in organisations
|
} for organisation in organisations
|
||||||
}
|
}
|
||||||
|
|||||||
13
app/utils.py
13
app/utils.py
@@ -5,6 +5,7 @@ from io import StringIO
|
|||||||
from os import path
|
from os import path
|
||||||
from functools import wraps
|
from functools import wraps
|
||||||
import unicodedata
|
import unicodedata
|
||||||
|
from urllib.parse import urlparse
|
||||||
from collections import namedtuple
|
from collections import namedtuple
|
||||||
from datetime import datetime, timedelta, timezone
|
from datetime import datetime, timedelta, timezone
|
||||||
from dateutil import parser
|
from dateutil import parser
|
||||||
@@ -364,3 +365,15 @@ def gmt_timezones(date):
|
|||||||
date = dateutil.parser.parse(date)
|
date = dateutil.parser.parse(date)
|
||||||
forced_utc = date.replace(tzinfo=pytz.utc)
|
forced_utc = date.replace(tzinfo=pytz.utc)
|
||||||
return forced_utc.astimezone(pytz.timezone('Europe/London'))
|
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)
|
||||||
|
|||||||
@@ -1,6 +1,8 @@
|
|||||||
|
def test_owasp_useful_headers_set(client, mocker):
|
||||||
|
mocker.patch('app.get_cdn_domain', return_value='static-logos.test.com')
|
||||||
|
|
||||||
def test_owasp_useful_headers_set(client):
|
|
||||||
response = client.get('/')
|
response = client.get('/')
|
||||||
|
|
||||||
assert response.status_code == 200
|
assert response.status_code == 200
|
||||||
assert response.headers['X-Frame-Options'] == 'deny'
|
assert response.headers['X-Frame-Options'] == 'deny'
|
||||||
assert response.headers['X-Content-Type-Options'] == 'nosniff'
|
assert response.headers['X-Content-Type-Options'] == 'nosniff'
|
||||||
@@ -10,6 +12,6 @@ def test_owasp_useful_headers_set(client):
|
|||||||
"script-src 'self' *.google-analytics.com 'unsafe-inline' 'unsafe-eval' data:;"
|
"script-src 'self' *.google-analytics.com 'unsafe-inline' 'unsafe-eval' data:;"
|
||||||
"object-src 'self';"
|
"object-src 'self';"
|
||||||
"font-src 'self' data:;"
|
"font-src 'self' data:;"
|
||||||
"img-src 'self' *.google-analytics.com *.notifications.service.gov.uk data:;"
|
"img-src 'self' *.google-analytics.com *.notifications.service.gov.uk static-logos.test.com data:;"
|
||||||
"frame-src www.youtube.com;"
|
"frame-src www.youtube.com;"
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -1,11 +1,10 @@
|
|||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
from io import StringIO
|
from io import StringIO
|
||||||
|
from collections import OrderedDict
|
||||||
from csv import DictReader
|
from csv import DictReader
|
||||||
|
|
||||||
import pytest
|
|
||||||
|
|
||||||
from collections import OrderedDict
|
|
||||||
from freezegun import freeze_time
|
from freezegun import freeze_time
|
||||||
|
import pytest
|
||||||
|
|
||||||
from app.utils import (
|
from app.utils import (
|
||||||
email_safe,
|
email_safe,
|
||||||
@@ -14,10 +13,9 @@ from app.utils import (
|
|||||||
generate_next_dict,
|
generate_next_dict,
|
||||||
Spreadsheet,
|
Spreadsheet,
|
||||||
get_letter_timings,
|
get_letter_timings,
|
||||||
|
get_cdn_domain
|
||||||
)
|
)
|
||||||
|
|
||||||
from tests import notification_json, single_notification_json
|
|
||||||
|
|
||||||
|
|
||||||
def _get_notifications_csv(
|
def _get_notifications_csv(
|
||||||
service_id,
|
service_id,
|
||||||
@@ -290,3 +288,15 @@ def test_get_estimated_delivery_date_for_letter(
|
|||||||
assert timings.is_printed == is_printed
|
assert timings.is_printed == is_printed
|
||||||
assert timings.earliest_delivery.strftime('%A %Y-%m-%d') == expected_earliest
|
assert timings.earliest_delivery.strftime('%A %Y-%m-%d') == expected_earliest
|
||||||
assert timings.latest_delivery.strftime('%A %Y-%m-%d') == expected_latest
|
assert timings.latest_delivery.strftime('%A %Y-%m-%d') == expected_latest
|
||||||
|
|
||||||
|
|
||||||
|
def test_get_cdn_domain_on_localhost(client, mocker):
|
||||||
|
mocker.patch.dict('app.current_app.config', values={'ADMIN_BASE_URL': 'http://localhost:6012'})
|
||||||
|
domain = get_cdn_domain()
|
||||||
|
assert domain == 'static-logos.notify.tools'
|
||||||
|
|
||||||
|
|
||||||
|
def test_get_cdn_domain_on_non_localhost(client, mocker):
|
||||||
|
mocker.patch.dict('app.current_app.config', values={'ADMIN_BASE_URL': 'https://some.admintest.com'})
|
||||||
|
domain = get_cdn_domain()
|
||||||
|
assert domain == 'static-logos.admintest.com'
|
||||||
|
|||||||
Reference in New Issue
Block a user