mirror of
https://github.com/GSA/notifications-admin.git
synced 2026-08-24 00:07:02 -04:00
Merge pull request #4142 from alphagov/logo-cdn-domain-config
Make logo CDN domain into simple config
This commit is contained in:
@@ -129,7 +129,6 @@ from app.url_converters import (
|
|||||||
TemplateTypeConverter,
|
TemplateTypeConverter,
|
||||||
TicketTypeConverter,
|
TicketTypeConverter,
|
||||||
)
|
)
|
||||||
from app.utils import get_logo_cdn_domain
|
|
||||||
|
|
||||||
login_manager = LoginManager()
|
login_manager = LoginManager()
|
||||||
csrf = CSRFProtect()
|
csrf = CSRFProtect()
|
||||||
@@ -372,7 +371,7 @@ def useful_headers_after_request(response):
|
|||||||
" *.notifications.service.gov.uk {logo_domain} data:;"
|
" *.notifications.service.gov.uk {logo_domain} data:;"
|
||||||
"frame-src 'self' www.youtube-nocookie.com;".format(
|
"frame-src 'self' www.youtube-nocookie.com;".format(
|
||||||
asset_domain=current_app.config['ASSET_DOMAIN'],
|
asset_domain=current_app.config['ASSET_DOMAIN'],
|
||||||
logo_domain=get_logo_cdn_domain(),
|
logo_domain=current_app.config['LOGO_CDN_DOMAIN'],
|
||||||
)
|
)
|
||||||
))
|
))
|
||||||
response.headers.add('Link', (
|
response.headers.add('Link', (
|
||||||
|
|||||||
@@ -101,6 +101,7 @@ class Development(Config):
|
|||||||
CSV_UPLOAD_BUCKET_NAME = 'development-notifications-csv-upload'
|
CSV_UPLOAD_BUCKET_NAME = 'development-notifications-csv-upload'
|
||||||
CONTACT_LIST_UPLOAD_BUCKET_NAME = 'development-contact-list'
|
CONTACT_LIST_UPLOAD_BUCKET_NAME = 'development-contact-list'
|
||||||
LOGO_UPLOAD_BUCKET_NAME = 'public-logos-tools'
|
LOGO_UPLOAD_BUCKET_NAME = 'public-logos-tools'
|
||||||
|
LOGO_CDN_DOMAIN = 'static-logos.notify.tools'
|
||||||
MOU_BUCKET_NAME = 'notify.tools-mou'
|
MOU_BUCKET_NAME = 'notify.tools-mou'
|
||||||
TRANSIENT_UPLOADED_LETTERS = 'development-transient-uploaded-letters'
|
TRANSIENT_UPLOADED_LETTERS = 'development-transient-uploaded-letters'
|
||||||
PRECOMPILED_ORIGINALS_BACKUP_LETTERS = 'development-letters-precompiled-originals-backup'
|
PRECOMPILED_ORIGINALS_BACKUP_LETTERS = 'development-letters-precompiled-originals-backup'
|
||||||
@@ -125,6 +126,7 @@ class Test(Development):
|
|||||||
CSV_UPLOAD_BUCKET_NAME = 'test-notifications-csv-upload'
|
CSV_UPLOAD_BUCKET_NAME = 'test-notifications-csv-upload'
|
||||||
CONTACT_LIST_UPLOAD_BUCKET_NAME = 'test-contact-list'
|
CONTACT_LIST_UPLOAD_BUCKET_NAME = 'test-contact-list'
|
||||||
LOGO_UPLOAD_BUCKET_NAME = 'public-logos-test'
|
LOGO_UPLOAD_BUCKET_NAME = 'public-logos-test'
|
||||||
|
LOGO_CDN_DOMAIN = 'static-logos.test.com'
|
||||||
MOU_BUCKET_NAME = 'test-mou'
|
MOU_BUCKET_NAME = 'test-mou'
|
||||||
TRANSIENT_UPLOADED_LETTERS = 'test-transient-uploaded-letters'
|
TRANSIENT_UPLOADED_LETTERS = 'test-transient-uploaded-letters'
|
||||||
PRECOMPILED_ORIGINALS_BACKUP_LETTERS = 'test-letters-precompiled-originals-backup'
|
PRECOMPILED_ORIGINALS_BACKUP_LETTERS = 'test-letters-precompiled-originals-backup'
|
||||||
@@ -145,6 +147,7 @@ class Preview(Config):
|
|||||||
CSV_UPLOAD_BUCKET_NAME = 'preview-notifications-csv-upload'
|
CSV_UPLOAD_BUCKET_NAME = 'preview-notifications-csv-upload'
|
||||||
CONTACT_LIST_UPLOAD_BUCKET_NAME = 'preview-contact-list'
|
CONTACT_LIST_UPLOAD_BUCKET_NAME = 'preview-contact-list'
|
||||||
LOGO_UPLOAD_BUCKET_NAME = 'public-logos-preview'
|
LOGO_UPLOAD_BUCKET_NAME = 'public-logos-preview'
|
||||||
|
LOGO_CDN_DOMAIN = 'static-logos.notify.works'
|
||||||
MOU_BUCKET_NAME = 'notify.works-mou'
|
MOU_BUCKET_NAME = 'notify.works-mou'
|
||||||
TRANSIENT_UPLOADED_LETTERS = 'preview-transient-uploaded-letters'
|
TRANSIENT_UPLOADED_LETTERS = 'preview-transient-uploaded-letters'
|
||||||
PRECOMPILED_ORIGINALS_BACKUP_LETTERS = 'preview-letters-precompiled-originals-backup'
|
PRECOMPILED_ORIGINALS_BACKUP_LETTERS = 'preview-letters-precompiled-originals-backup'
|
||||||
@@ -163,6 +166,7 @@ class Staging(Config):
|
|||||||
CSV_UPLOAD_BUCKET_NAME = 'staging-notifications-csv-upload'
|
CSV_UPLOAD_BUCKET_NAME = 'staging-notifications-csv-upload'
|
||||||
CONTACT_LIST_UPLOAD_BUCKET_NAME = 'staging-contact-list'
|
CONTACT_LIST_UPLOAD_BUCKET_NAME = 'staging-contact-list'
|
||||||
LOGO_UPLOAD_BUCKET_NAME = 'public-logos-staging'
|
LOGO_UPLOAD_BUCKET_NAME = 'public-logos-staging'
|
||||||
|
LOGO_CDN_DOMAIN = 'static-logos.staging-notify.works'
|
||||||
MOU_BUCKET_NAME = 'staging-notify.works-mou'
|
MOU_BUCKET_NAME = 'staging-notify.works-mou'
|
||||||
TRANSIENT_UPLOADED_LETTERS = 'staging-transient-uploaded-letters'
|
TRANSIENT_UPLOADED_LETTERS = 'staging-transient-uploaded-letters'
|
||||||
PRECOMPILED_ORIGINALS_BACKUP_LETTERS = 'staging-letters-precompiled-originals-backup'
|
PRECOMPILED_ORIGINALS_BACKUP_LETTERS = 'staging-letters-precompiled-originals-backup'
|
||||||
@@ -178,6 +182,7 @@ class Live(Config):
|
|||||||
CSV_UPLOAD_BUCKET_NAME = 'live-notifications-csv-upload'
|
CSV_UPLOAD_BUCKET_NAME = 'live-notifications-csv-upload'
|
||||||
CONTACT_LIST_UPLOAD_BUCKET_NAME = 'production-contact-list'
|
CONTACT_LIST_UPLOAD_BUCKET_NAME = 'production-contact-list'
|
||||||
LOGO_UPLOAD_BUCKET_NAME = 'public-logos-production'
|
LOGO_UPLOAD_BUCKET_NAME = 'public-logos-production'
|
||||||
|
LOGO_CDN_DOMAIN = 'static-logos.notifications.service.gov.uk'
|
||||||
MOU_BUCKET_NAME = 'notifications.service.gov.uk-mou'
|
MOU_BUCKET_NAME = 'notifications.service.gov.uk-mou'
|
||||||
TRANSIENT_UPLOADED_LETTERS = 'production-transient-uploaded-letters'
|
TRANSIENT_UPLOADED_LETTERS = 'production-transient-uploaded-letters'
|
||||||
PRECOMPILED_ORIGINALS_BACKUP_LETTERS = 'production-letters-precompiled-originals-backup'
|
PRECOMPILED_ORIGINALS_BACKUP_LETTERS = 'production-letters-precompiled-originals-backup'
|
||||||
|
|||||||
@@ -11,7 +11,6 @@ from app.s3_client.s3_logo_client import (
|
|||||||
persist_logo,
|
persist_logo,
|
||||||
upload_email_logo,
|
upload_email_logo,
|
||||||
)
|
)
|
||||||
from app.utils import get_logo_cdn_domain
|
|
||||||
from app.utils.user import user_is_platform_admin
|
from app.utils.user import user_is_platform_admin
|
||||||
|
|
||||||
|
|
||||||
@@ -78,7 +77,7 @@ def update_email_branding(branding_id, logo=None):
|
|||||||
'views/email-branding/manage-branding.html',
|
'views/email-branding/manage-branding.html',
|
||||||
form=form,
|
form=form,
|
||||||
email_branding=email_branding,
|
email_branding=email_branding,
|
||||||
cdn_url=get_logo_cdn_domain(),
|
cdn_url=current_app.config['LOGO_CDN_DOMAIN'],
|
||||||
logo=logo
|
logo=logo
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -123,6 +122,6 @@ def create_email_branding(logo=None):
|
|||||||
return render_template(
|
return render_template(
|
||||||
'views/email-branding/manage-branding.html',
|
'views/email-branding/manage-branding.html',
|
||||||
form=form,
|
form=form,
|
||||||
cdn_url=get_logo_cdn_domain(),
|
cdn_url=current_app.config['LOGO_CDN_DOMAIN'],
|
||||||
logo=logo
|
logo=logo
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
from flask import (
|
from flask import (
|
||||||
abort,
|
abort,
|
||||||
|
current_app,
|
||||||
make_response,
|
make_response,
|
||||||
redirect,
|
redirect,
|
||||||
render_template,
|
render_template,
|
||||||
@@ -16,7 +17,7 @@ from app.main.views.sub_navigation_dictionaries import (
|
|||||||
features_nav,
|
features_nav,
|
||||||
using_notify_nav,
|
using_notify_nav,
|
||||||
)
|
)
|
||||||
from app.utils import get_logo_cdn_domain, hide_from_search_engines
|
from app.utils import hide_from_search_engines
|
||||||
|
|
||||||
|
|
||||||
@main.route('/')
|
@main.route('/')
|
||||||
@@ -87,7 +88,7 @@ def email_template():
|
|||||||
colour = email_branding['colour']
|
colour = email_branding['colour']
|
||||||
brand_text = email_branding['text']
|
brand_text = email_branding['text']
|
||||||
brand_colour = colour
|
brand_colour = colour
|
||||||
brand_logo = ('https://{}/{}'.format(get_logo_cdn_domain(), email_branding['logo'])
|
brand_logo = (f"https://{current_app.config['LOGO_CDN_DOMAIN']}/{email_branding['logo']}"
|
||||||
if email_branding['logo'] else None)
|
if email_branding['logo'] else None)
|
||||||
govuk_banner = branding_type in ['govuk', 'both']
|
govuk_banner = branding_type in ['govuk', 'both']
|
||||||
brand_banner = branding_type == 'org_banner'
|
brand_banner = branding_type == 'org_banner'
|
||||||
|
|||||||
@@ -25,7 +25,6 @@ from app.s3_client.s3_logo_client import (
|
|||||||
persist_logo,
|
persist_logo,
|
||||||
upload_letter_temp_logo,
|
upload_letter_temp_logo,
|
||||||
)
|
)
|
||||||
from app.utils import get_logo_cdn_domain
|
|
||||||
from app.utils.user import user_is_platform_admin
|
from app.utils.user import user_is_platform_admin
|
||||||
|
|
||||||
|
|
||||||
@@ -113,7 +112,7 @@ def update_letter_branding(branding_id, logo=None):
|
|||||||
'views/letter-branding/manage-letter-branding.html',
|
'views/letter-branding/manage-letter-branding.html',
|
||||||
file_upload_form=file_upload_form,
|
file_upload_form=file_upload_form,
|
||||||
letter_branding_details_form=letter_branding_details_form,
|
letter_branding_details_form=letter_branding_details_form,
|
||||||
cdn_url=get_logo_cdn_domain(),
|
cdn_url=current_app.config['LOGO_CDN_DOMAIN'],
|
||||||
logo=logo,
|
logo=logo,
|
||||||
is_update=True
|
is_update=True
|
||||||
)
|
)
|
||||||
@@ -169,7 +168,7 @@ def create_letter_branding(logo=None):
|
|||||||
'views/letter-branding/manage-letter-branding.html',
|
'views/letter-branding/manage-letter-branding.html',
|
||||||
file_upload_form=file_upload_form,
|
file_upload_form=file_upload_form,
|
||||||
letter_branding_details_form=letter_branding_details_form,
|
letter_branding_details_form=letter_branding_details_form,
|
||||||
cdn_url=get_logo_cdn_domain(),
|
cdn_url=current_app.config['LOGO_CDN_DOMAIN'],
|
||||||
logo=logo
|
logo=logo
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|||||||
@@ -1,8 +1,7 @@
|
|||||||
from functools import wraps
|
from functools import wraps
|
||||||
from itertools import chain
|
from itertools import chain
|
||||||
from urllib.parse import urlparse
|
|
||||||
|
|
||||||
from flask import abort, current_app, g, make_response, request
|
from flask import abort, g, make_response, request
|
||||||
from flask_login import current_user
|
from flask_login import current_user
|
||||||
from notifications_utils.field import Field
|
from notifications_utils.field import Field
|
||||||
from orderedset._orderedset import OrderedSet
|
from orderedset._orderedset import OrderedSet
|
||||||
@@ -36,18 +35,6 @@ def get_help_argument():
|
|||||||
return request.args.get('help') if request.args.get('help') in ('1', '2', '3') else None
|
return request.args.get('help') if request.args.get('help') in ('1', '2', '3') else None
|
||||||
|
|
||||||
|
|
||||||
def get_logo_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)
|
|
||||||
|
|
||||||
|
|
||||||
def parse_filter_args(filter_dict):
|
def parse_filter_args(filter_dict):
|
||||||
if not isinstance(filter_dict, MultiDict):
|
if not isinstance(filter_dict, MultiDict):
|
||||||
filter_dict = MultiDict(filter_dict)
|
filter_dict = MultiDict(filter_dict)
|
||||||
|
|||||||
@@ -6,8 +6,6 @@ def test_owasp_useful_headers_set(
|
|||||||
mock_get_service_and_organisation_counts,
|
mock_get_service_and_organisation_counts,
|
||||||
):
|
):
|
||||||
client_request.logout()
|
client_request.logout()
|
||||||
mocker.patch('app.get_logo_cdn_domain', return_value='static-logos.test.com')
|
|
||||||
|
|
||||||
response = client_request.get_response('.index')
|
response = client_request.get_response('.index')
|
||||||
|
|
||||||
assert response.headers['X-Frame-Options'] == 'deny'
|
assert response.headers['X-Frame-Options'] == 'deny'
|
||||||
@@ -36,7 +34,10 @@ def test_headers_non_ascii_characters_are_replaced(
|
|||||||
mock_get_service_and_organisation_counts,
|
mock_get_service_and_organisation_counts,
|
||||||
):
|
):
|
||||||
client_request.logout()
|
client_request.logout()
|
||||||
mocker.patch('app.get_logo_cdn_domain', return_value='static-logos۾.test.com')
|
mocker.patch.dict(
|
||||||
|
'app.current_app.config',
|
||||||
|
values={'LOGO_CDN_DOMAIN': 'static-logos۾.test.com'},
|
||||||
|
)
|
||||||
|
|
||||||
response = client_request.get_response('.index')
|
response = client_request.get_response('.index')
|
||||||
|
|
||||||
|
|||||||
@@ -1,18 +1,6 @@
|
|||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
from app.utils import get_logo_cdn_domain, merge_jsonlike
|
from app.utils import merge_jsonlike
|
||||||
|
|
||||||
|
|
||||||
def test_get_cdn_domain_on_localhost(client_request, mocker):
|
|
||||||
mocker.patch.dict('app.current_app.config', values={'ADMIN_BASE_URL': 'http://localhost:6012'})
|
|
||||||
domain = get_logo_cdn_domain()
|
|
||||||
assert domain == 'static-logos.notify.tools'
|
|
||||||
|
|
||||||
|
|
||||||
def test_get_cdn_domain_on_non_localhost(client_request, mocker):
|
|
||||||
mocker.patch.dict('app.current_app.config', values={'ADMIN_BASE_URL': 'https://some.admintest.com'})
|
|
||||||
domain = get_logo_cdn_domain()
|
|
||||||
assert domain == 'static-logos.admintest.com'
|
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.parametrize("source_object, destination_object, expected_result", [
|
@pytest.mark.parametrize("source_object, destination_object, expected_result", [
|
||||||
|
|||||||
Reference in New Issue
Block a user