diff --git a/.travis.yml b/.travis.yml index 50eecec26..030da3e0c 100644 --- a/.travis.yml +++ b/.travis.yml @@ -41,6 +41,27 @@ deploy: deployment_group: notifications_admin_deployment_group region: eu-west-1 on: *2 +- provider: s3 + access_key_id: AKIAJ5MKF6G3P2JQP4QQ + secret_access_key: &1 + secure: xfjg4kNBvU0B9xhRETr14mB0bCpVonlAKqGnKL2AoqpnF19yihqGNA8sv/pOGUFpeWZO3cW2GA3anyL2gGG1X0K3f81649mneVJkSHaZ2fiG/S1eKtS0Ws5XblSqLmKTPC7H9ndUxT8r+r2wLg62netBE5g8tAxw2QwN/gVz2fK/68owiyeD/jl6gw/iQ47F+mmGdAY/eFe8sUuGR4Oxj2xNAYARaDQOmHpQF/IG3M69FO5uOJtck8fUWnpd0rWxsyWBOVwwIRQHL6cWOyodeIK7YvLmzviCi1GojBPKQwQbjJu89LHfMJJTW1625drj5CNounuENTFte0Pip8zp90bg090VA8OlTXNWcyFjBQD1vNIE59vyQ/hCh90NK1nlTXdnNOwL0VZTMxQ/zYulXoMqwDLfDozhQbmnkXmexJl6BF4/dz+XmwDu7st5A/PI6U5zCK86ST/6g3MklGSseFi5Rkt6kmJrdlRIhiLnoaab8YgI0FPWjzHBC6B98ZtgIUiUk7Ng5ZTM8Sjq1HCC7mUDrDL0c7aerZA5bq2hQiKGhvjBXFU17iHZ0eEDZ8kO+jumeMwmpW6NbjlS0PuDx+lHywMSG7r+YVmkjxq5gwrTVl3evRxhHe8H/lU18y2dOKpIyX5UEZpXRq9kAWuQruCDBwoDe3Y3QP+Rg7HVGBU= + local_dir: dpl_cd_upload + skip_cleanup: true + on: &2 + repo: alphagov/notifications-admin + branch: live + bucket: live-notifications-api-codedeploy + region: eu-west-1 +- provider: codedeploy + access_key_id: AKIAJ5MKF6G3P2JQP4QQ + secret_access_key: *1 + bucket: live-notifications-api-codedeploy + key: notifications-admin-$TRAVIS_BRANCH-$TRAVIS_BUILD_NUMBER-$TRAVIS_COMMIT.zip + bundle_type: zip + application: notifications-admin + deployment_group: live_notifications_admin_deployment_group + region: eu-west-1 + on: *2 - provider: s3 access_key_id: AKIAJQPPNM6P6V53SWKA secret_access_key: &1 diff --git a/app.py b/app.py index 445f95cd5..1710069ca 100644 --- a/app.py +++ b/app.py @@ -3,7 +3,7 @@ from flask.ext.script import Manager, Server from app import create_app -application = create_app(os.getenv('NOTIFICATIONS_ADMIN_ENVIRONMENT') or 'development') +application = create_app() manager = Manager(application) port = int(os.environ.get('PORT', 6012)) manager.add_command("runserver", Server(host='0.0.0.0', port=port)) diff --git a/app/__init__.py b/app/__init__.py index 48ba1ed19..c355f065f 100644 --- a/app/__init__.py +++ b/app/__init__.py @@ -2,7 +2,8 @@ import os import re import dateutil -from flask import (Flask, session, Markup, escape, render_template, make_response) +import urllib +from flask import (Flask, session, Markup, escape, render_template, make_response, current_app) from flask._compat import string_types from flask_login import LoginManager from flask_wtf import CsrfProtect @@ -19,6 +20,7 @@ from app.notify_client.job_api_client import JobApiClient from app.notify_client.notification_api_client import NotificationApiClient from app.notify_client.status_api_client import StatusApiClient from app.notify_client.invite_api_client import InviteApiClient +from app.notify_client.statistics_api_client import StatisticsApiClient from app.its_dangerous_session import ItsdangerousSessionInterface from app.asset_fingerprinter import AssetFingerprinter from utils.recipients import validate_phone_number, InvalidPhoneError @@ -36,15 +38,16 @@ job_api_client = JobApiClient() notification_api_client = NotificationApiClient() status_api_client = StatusApiClient() invite_api_client = InviteApiClient() +statistics_api_client = StatisticsApiClient() asset_fingerprinter = AssetFingerprinter() -def create_app(config_name, config_overrides=None): +def create_app(): application = Flask(__name__) - application.config['NOTIFY_ADMIN_ENVIRONMENT'] = config_name - application.config.from_object(configs[config_name]) - init_app(application, config_overrides) + application.config.from_object(os.environ['NOTIFY_ADMIN_ENVIRONMENT']) + + init_app(application) logging.init_app(application) init_csrf(application) @@ -55,6 +58,7 @@ def create_app(config_name, config_overrides=None): notification_api_client.init_app(application) status_api_client.init_app(application) invite_api_client.init_app(application) + statistics_api_client.init_app(application) login_manager.init_app(application) login_manager.login_view = 'main.sign_in' @@ -75,6 +79,7 @@ def create_app(config_name, config_overrides=None): application.add_template_filter(format_time) application.add_template_filter(syntax_highlight_json) application.add_template_filter(valid_phone_number) + application.add_template_filter(linkable_name) application.after_request(useful_headers_after_request) register_errorhandlers(application) @@ -101,22 +106,12 @@ def init_csrf(application): abort(400, reason) -def init_app(app, config_overrides): - - if config_overrides: - for key in app.config.keys(): - if key in config_overrides: - app.config[key] = config_overrides[key] - - for key, value in app.config.items(): - if key in os.environ: - app.config[key] = convert_to_boolean(os.environ[key]) - - @app.context_processor +def init_app(application): + @application.context_processor def inject_global_template_variables(): return { 'asset_path': '/static/', - 'header_colour': app.config['HEADER_COLOUR'], + 'header_colour': application.config['HEADER_COLOUR'], 'asset_url': asset_fingerprinter.get_url } @@ -139,6 +134,10 @@ def nl2br(value): return Markup(result) +def linkable_name(value): + return urllib.parse.quote_plus(value) + + def syntax_highlight_json(code): return Markup(highlight(code, JavascriptLexer(), HtmlFormatter(noclasses=True))) @@ -203,7 +202,7 @@ def register_errorhandlers(application): @application.errorhandler(Exception) def handle_bad_request(error): - from flask import current_app - if current_app.config.get('DEBUG'): - print(error) + # We want the Flask in browser stacktrace + if current_app.config.get('DEBUG', None): + raise error return _error_response(500) diff --git a/app/assets/images/tick-black.png b/app/assets/images/tick-black.png new file mode 100644 index 000000000..dd050c6c7 Binary files /dev/null and b/app/assets/images/tick-black.png differ diff --git a/app/assets/javascripts/highlightTags.js b/app/assets/javascripts/highlightTags.js index a1ecf2f37..ca4359111 100644 --- a/app/assets/javascripts/highlightTags.js +++ b/app/assets/javascripts/highlightTags.js @@ -20,8 +20,9 @@