mirror of
https://github.com/GSA/notifications-admin.git
synced 2026-08-06 06:31:33 -04:00
Updated notifications_utils version and associated code. Added email subject formatting for placeholders.
This commit is contained in:
@@ -35,10 +35,10 @@ from app.notify_client.template_statistics_api_client import TemplateStatisticsA
|
||||
|
||||
from app.its_dangerous_session import ItsdangerousSessionInterface
|
||||
from app.asset_fingerprinter import AssetFingerprinter
|
||||
from utils.recipients import validate_phone_number, InvalidPhoneError
|
||||
from notifications_utils.recipients import validate_phone_number, InvalidPhoneError
|
||||
import app.proxy_fix
|
||||
from config import configs
|
||||
from utils import logging
|
||||
from notifications_utils import logging
|
||||
from werkzeug.local import LocalStack, LocalProxy
|
||||
from flask.globals import _lookup_req_object
|
||||
from functools import partial
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
from flask_wtf import Form
|
||||
from utils.recipients import (
|
||||
from notifications_utils.recipients import (
|
||||
validate_phone_number,
|
||||
InvalidPhoneError
|
||||
)
|
||||
|
||||
@@ -2,7 +2,7 @@ import re
|
||||
from wtforms import ValidationError
|
||||
from datetime import datetime
|
||||
from app.main.encryption import check_hash
|
||||
from utils.template import Template
|
||||
from notifications_utils.template import Template
|
||||
|
||||
|
||||
class Blacklist(object):
|
||||
|
||||
@@ -12,7 +12,7 @@ from flask import (
|
||||
)
|
||||
from flask_login import login_required
|
||||
from werkzeug.datastructures import MultiDict
|
||||
from utils.template import Template
|
||||
from notifications_utils.template import Template
|
||||
|
||||
from app import (
|
||||
job_api_client,
|
||||
|
||||
@@ -11,7 +11,7 @@ from app import user_api_client
|
||||
|
||||
@main.route('/new-password/<path:token>', methods=['GET', 'POST'])
|
||||
def new_password(token):
|
||||
from utils.url_safe_token import check_token
|
||||
from notifications_utils.url_safe_token import check_token
|
||||
try:
|
||||
token_data = check_token(token, current_app.config['SECRET_KEY'], current_app.config['DANGEROUS_SALT'],
|
||||
current_app.config['TOKEN_MAX_AGE_SECONDS'])
|
||||
|
||||
@@ -17,8 +17,8 @@ from flask import (
|
||||
)
|
||||
|
||||
from flask_login import login_required, current_user
|
||||
from utils.template import Template
|
||||
from utils.recipients import RecipientCSV, first_column_heading, validate_and_format_phone_number
|
||||
from notifications_utils.template import Template
|
||||
from notifications_utils.recipients import RecipientCSV, first_column_heading, validate_and_format_phone_number
|
||||
|
||||
from app.main import main
|
||||
from app.main.forms import CsvUploadForm
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
from flask import render_template, current_app, abort
|
||||
from flask_wtf import Form
|
||||
from wtforms import StringField, PasswordField, TextAreaField, FileField, validators
|
||||
from utils.template import Template
|
||||
from notifications_utils.template import Template
|
||||
from app.main import main
|
||||
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
from flask import request, render_template, redirect, url_for, flash, abort
|
||||
from flask_login import login_required
|
||||
|
||||
from utils.template import Template
|
||||
from notifications_utils.template import Template
|
||||
|
||||
from app.main import main
|
||||
from app.utils import user_has_permissions
|
||||
|
||||
@@ -15,6 +15,7 @@ from itsdangerous import SignatureExpired
|
||||
from flask_login import login_user
|
||||
|
||||
from notifications_python_client.errors import HTTPError
|
||||
from notifications_utils.url_safe_token import check_token
|
||||
|
||||
from app.main import main
|
||||
from app.main.forms import TwoFactorForm
|
||||
@@ -47,7 +48,6 @@ def verify():
|
||||
|
||||
@main.route('/verify-email/<token>')
|
||||
def verify_email(token):
|
||||
from utils.url_safe_token import check_token
|
||||
try:
|
||||
token_data = check_token(token,
|
||||
current_app.config['SECRET_KEY'],
|
||||
|
||||
@@ -46,7 +46,7 @@
|
||||
|
||||
{% if 'email' == template.template_type %}
|
||||
{{ email_message(
|
||||
template.subject,
|
||||
template.formatted_subject_as_markup,
|
||||
template.formatted_as_markup if errors else template.replaced,
|
||||
from_address='{}@notifications.service.gov.uk'.format(current_service.email_from),
|
||||
from_name=current_service.name
|
||||
|
||||
@@ -23,7 +23,7 @@
|
||||
</div>
|
||||
{% elif 'email' == template.template_type %}
|
||||
{{ email_message(
|
||||
template.subject,
|
||||
template.formatted_subject_as_markup,
|
||||
template.formatted_as_markup,
|
||||
from_address='{}@notifications.service.gov.uk'.format(current_service.email_from),
|
||||
from_name=current_service.name
|
||||
|
||||
@@ -21,7 +21,7 @@
|
||||
</div>
|
||||
{% elif 'email' == template.template_type %}
|
||||
{{ email_message(
|
||||
template.subject,
|
||||
template.formatted_subject_as_markup,
|
||||
template.formatted_as_markup,
|
||||
from_address='{}@notifications.service.gov.uk'.format(current_service.email_from),
|
||||
from_name=current_service.name
|
||||
|
||||
@@ -15,4 +15,4 @@ Babel==2.3.3
|
||||
|
||||
git+https://github.com/alphagov/notifications-python-client.git@0.3.1#egg=notifications-python-client==0.3.1
|
||||
|
||||
git+https://github.com/alphagov/notifications-utils.git@3.3.0#egg=notifications-utils==3.3.0
|
||||
git+https://github.com/alphagov/notifications-utils.git@4.1.3#egg=notifications-utils==4.1.3
|
||||
|
||||
@@ -45,14 +45,22 @@ def service_json(id_, name, users, message_limit=1000, active=False, restricted=
|
||||
}
|
||||
|
||||
|
||||
def template_json(service_id, id_, name="sample template", type_="sms", content="template content"):
|
||||
return {
|
||||
def template_json(service_id,
|
||||
id_,
|
||||
name="sample template",
|
||||
type_="sms",
|
||||
content="template content",
|
||||
subject=None):
|
||||
template = {
|
||||
'id': id_,
|
||||
'name': name,
|
||||
'template_type': type_,
|
||||
'content': content,
|
||||
'service': service_id
|
||||
}
|
||||
if subject is not None:
|
||||
template['subject'] = subject
|
||||
return template
|
||||
|
||||
|
||||
def api_key_json(id_, name, expiry_date=None):
|
||||
|
||||
@@ -2,7 +2,7 @@ import json
|
||||
from datetime import datetime
|
||||
|
||||
from flask import url_for
|
||||
from utils.url_safe_token import generate_token
|
||||
from notifications_utils.url_safe_token import generate_token
|
||||
|
||||
|
||||
def test_should_render_new_password_template(app_,
|
||||
|
||||
@@ -76,7 +76,7 @@ def test_verify_email_redirects_to_verify_if_token_valid(app_,
|
||||
mock_check_verify_code):
|
||||
import json
|
||||
token_data = {"user_id": api_user_pending.id, "secret_code": 12345}
|
||||
mocker.patch('utils.url_safe_token.check_token', return_value=json.dumps(token_data))
|
||||
mocker.patch('app.main.views.verify.check_token', return_value=json.dumps(token_data))
|
||||
|
||||
with app_.test_request_context():
|
||||
with app_.test_client() as client:
|
||||
@@ -94,7 +94,7 @@ def test_verify_email_redirects_to_email_sent_if_token_expired(app_,
|
||||
api_user_pending,
|
||||
mock_check_verify_code):
|
||||
from itsdangerous import SignatureExpired
|
||||
mocker.patch('utils.url_safe_token.check_token', side_effect=SignatureExpired('expired'))
|
||||
mocker.patch('app.main.views.verify.check_token', side_effect=SignatureExpired('expired'))
|
||||
|
||||
with app_.test_request_context():
|
||||
with app_.test_client() as client:
|
||||
@@ -114,7 +114,7 @@ def test_verify_email_redirects_to_email_sent_if_token_used(app_,
|
||||
mock_send_verify_code,
|
||||
mock_check_verify_code_code_expired):
|
||||
from itsdangerous import SignatureExpired
|
||||
mocker.patch('utils.url_safe_token.check_token', side_effect=SignatureExpired('expired'))
|
||||
mocker.patch('app.main.views.verify.check_token', side_effect=SignatureExpired('expired'))
|
||||
|
||||
with app_.test_request_context():
|
||||
with app_.test_client() as client:
|
||||
@@ -135,7 +135,7 @@ def test_verify_email_redirects_to_sign_in_if_user_active(app_,
|
||||
mock_check_verify_code):
|
||||
import json
|
||||
token_data = {"user_id": api_user_active.id, "secret_code": 12345}
|
||||
mocker.patch('utils.url_safe_token.check_token', return_value=json.dumps(token_data))
|
||||
mocker.patch('app.main.views.verify.check_token', return_value=json.dumps(token_data))
|
||||
|
||||
with app_.test_request_context():
|
||||
with app_.test_client() as client:
|
||||
|
||||
@@ -180,7 +180,11 @@ def mock_get_service_template(mocker):
|
||||
def mock_get_service_email_template(mocker):
|
||||
def _create(service_id, template_id):
|
||||
template = template_json(
|
||||
service_id, template_id, "Two week reminder", "email", "Your vehicle tax is about to expire")
|
||||
service_id,
|
||||
template_id,
|
||||
"Two week reminder",
|
||||
"email",
|
||||
"Your vehicle tax is about to expire", "Subject")
|
||||
return {'data': template}
|
||||
|
||||
return mocker.patch(
|
||||
|
||||
Reference in New Issue
Block a user