From 1c730604749f0b13ee2cbcdfa162d4578e29a58e Mon Sep 17 00:00:00 2001 From: Chris Heathcote Date: Tue, 22 Dec 2015 11:19:06 +0000 Subject: [PATCH 1/4] add 2 test email templates --- app/main/views/index.py | 10 +++ app/templates/email/email_template_1.html | 85 ++++++++++++++++++++ app/templates/email/email_template_2.html | 95 +++++++++++++++++++++++ 3 files changed, 190 insertions(+) create mode 100644 app/templates/email/email_template_1.html create mode 100644 app/templates/email/email_template_2.html diff --git a/app/main/views/index.py b/app/main/views/index.py index f1525d4cd..abba59bff 100644 --- a/app/main/views/index.py +++ b/app/main/views/index.py @@ -119,3 +119,13 @@ def managetemplates(): @main.route("/edit-template") def edittemplate(): return render_template('views/edit-template.html') + + +@main.route("/email-template-1") +def emailtemplate(): + return render_template('email/email_template_1.html') + + +@main.route("/email-template-2") +def emailtemplate(): + return render_template('email/email_template_2.html') diff --git a/app/templates/email/email_template_1.html b/app/templates/email/email_template_1.html new file mode 100644 index 000000000..39f42bd1e --- /dev/null +++ b/app/templates/email/email_template_1.html @@ -0,0 +1,85 @@ + + + + + + + Page title + + + + + + + +
+ + + + +
+ + GOV.UK +
+
+ + + + + +
+ + + + + +
+ +

+ This is the page title +

+ +

+ Dear A Name, +

+ +

+ This is the first paragraph. +

+ +

+ This is the second paragraph. It is longer than the first and wraps on to two lines. +

+ +

+ This paragraph includes a line-break:
+ This is the line after the line-break. +

+ +

+ This is an inset paragraph used for data or callouts
+ Application reference: 123456789
+ Date received: 15 March 2015
+

+ +

+ Second level heading

+

+ Third level heading +

+

+ Intro before a url: + + www.gov.uk/service-start-page +

+ +

+ Department or agency name +

+ +
 
+
+ + + + \ No newline at end of file diff --git a/app/templates/email/email_template_2.html b/app/templates/email/email_template_2.html new file mode 100644 index 000000000..731959d11 --- /dev/null +++ b/app/templates/email/email_template_2.html @@ -0,0 +1,95 @@ + + + + + + Page title + + + + + + + + + + + +
+ + + + +
+ + GOV.UK +
+
+ + + + + + +
+

+ This is the page title +

+ +

+ Dear A Name, +

+ +

+ This is the first paragraph. +

+ +

+ This is the second paragraph. It is longer than the first and wraps on to two lines. +

+ +

+ This paragraph includes a line-break:
+ This is the line after the line-break. +

+ +

+ This is an inset paragraph used for data or callouts
+ Application reference: 123456789
+ Date received: 15 March 2015
+

+ +

+ Second level heading

+

+ Third level heading +

+

+ Intro before a url: + + www.gov.uk/service-start-page +

+ +

+ Department or agency name +

+
+ + + + + \ No newline at end of file From 6616182ab359b5ddff1642d1afd003b2d72085bb Mon Sep 17 00:00:00 2001 From: Martyn Inglis Date: Fri, 19 Feb 2016 16:38:08 +0000 Subject: [PATCH 2/4] Slight changes to match new API features: - get user now throws a 404 so handle that - making a service now needs one user not many to create --- app/main/dao/users_dao.py | 13 ++++++++++--- app/main/views/register.py | 1 - app/notify_client/api_client.py | 2 +- 3 files changed, 11 insertions(+), 5 deletions(-) diff --git a/app/main/dao/users_dao.py b/app/main/dao/users_dao.py index 0a6e3e891..d2fca9d32 100644 --- a/app/main/dao/users_dao.py +++ b/app/main/dao/users_dao.py @@ -1,4 +1,5 @@ from datetime import datetime +from notifications_python_client import HTTPError from sqlalchemy.orm import load_only @@ -47,9 +48,15 @@ def activate_user(user): def is_email_unique(email_address): - if user_api_client.get_user_by_email(email_address): - return False - return True + try: + if user_api_client.get_user_by_email(email_address): + return False + return True + except HTTPError as ex: + if ex.status_code == 404: + return True + else: + raise ex def request_password_reset(user): diff --git a/app/main/views/register.py b/app/main/views/register.py index 1e9d488bf..33e71b7fa 100644 --- a/app/main/views/register.py +++ b/app/main/views/register.py @@ -26,7 +26,6 @@ def register(): return redirect(url_for('main.choose_service')) form = RegisterUserForm() - if form.validate_on_submit(): if users_dao.is_email_unique(form.email_address.data): try: diff --git a/app/notify_client/api_client.py b/app/notify_client/api_client.py index 7f9f34b52..f5f72298a 100644 --- a/app/notify_client/api_client.py +++ b/app/notify_client/api_client.py @@ -24,7 +24,7 @@ class NotificationsAdminAPIClient(NotificationsAPIClient): "name": service_name, "active": active, "limit": limit, - "users": [user_id], + "user_id": user_id, "restricted": restricted } return self.post("/service", data) From 73deae9bffe6606828f4a3362287bb3caa0727ff Mon Sep 17 00:00:00 2001 From: Chris Hill-Scott Date: Thu, 18 Feb 2016 14:54:59 +0000 Subject: [PATCH 3/4] Preview service name when adding a new service MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This commit adds a new page, which appears after a user enters the name for their new service. It shows how the service name will appear in emails and text messages. This means that the new service is not created until after they have confirmed that the name is appropriate in context. This has also involved: - visual changes to the ‘email template’ pattern, which wasn’t very refined before - removing a bunch of words from the enter service name page, because most users don’t read them, and we reckon that showing a preview is a better way of getting them to understand what is meant by service name Still to do: - validating the the generated email address for a service is unique (on the API) side - having the API return the generated email address, rather than determining it in the admin app --- app/assets/stylesheets/_grids.scss | 14 +++-- .../stylesheets/components/email-message.scss | 36 +++++++----- .../stylesheets/components/sms-message.scss | 6 ++ .../stylesheets/components/textbox.scss | 4 ++ app/main/dao/services_dao.py | 11 ++++ app/main/views/add_service.py | 30 ++++++++-- app/main/views/sms.py | 1 + app/templates/components/email-message.html | 29 ++++++++-- app/templates/components/sms-message.html | 7 ++- app/templates/components/textbox.html | 8 ++- app/templates/views/add-from-address.html | 42 ++++++++++++++ app/templates/views/add-service.html | 20 +++---- tests/app/main/views/test_add_service.py | 55 ++++++++++++++++--- 13 files changed, 213 insertions(+), 50 deletions(-) create mode 100644 app/templates/views/add-from-address.html diff --git a/app/assets/stylesheets/_grids.scss b/app/assets/stylesheets/_grids.scss index e349e22bb..7f8eb724f 100644 --- a/app/assets/stylesheets/_grids.scss +++ b/app/assets/stylesheets/_grids.scss @@ -1,11 +1,17 @@ -.column-one-quarter { - @include grid-column(1/4); -} - .column-three-quarters { @include grid-column(3/4); } + +.column-one-eighth { + @include grid-column(1/8); +} + +.column-seven-eighths { + @include grid-column(7/8); +} + .bottom-gutter { margin-bottom: $gutter; + clear: both; } diff --git a/app/assets/stylesheets/components/email-message.scss b/app/assets/stylesheets/components/email-message.scss index 2eec50050..b4771841a 100644 --- a/app/assets/stylesheets/components/email-message.scss +++ b/app/assets/stylesheets/components/email-message.scss @@ -1,24 +1,30 @@ .email-message { margin-bottom: $gutter; - border: 1px solid $border-colour; - - &-subject { - @include bold-19; - border-bottom: 1px solid $border-colour; - padding: 10px; - } - - &-body { - border-bottom: 1px solid $white; - padding: 10px; - overflow: hidden; - max-height: 103px; - } &-name { @include bold-19; - margin: 50px 0 10px 0; + margin: 20px 0 10px 0; + } + + &-subject, + &-from { + margin: 10px 0; + } + + &-from { + padding-top: 15px; + border-top: 1px solid $border-colour; + } + + &-body { + width: 100%; + box-sizing: border-box; + padding: $gutter-half 0 0 0; + margin: 0 0 $gutter 0; + clear: both; + border-top: 1px solid $border-colour; + border-bottom: 1px solid $border-colour; } } diff --git a/app/assets/stylesheets/components/sms-message.scss b/app/assets/stylesheets/components/sms-message.scss index 9fbe0b1af..898d04c24 100644 --- a/app/assets/stylesheets/components/sms-message.scss +++ b/app/assets/stylesheets/components/sms-message.scss @@ -8,6 +8,7 @@ border-radius: 5px; white-space: normal; margin: 0 0 $gutter 0; + clear: both; } .sms-message-wrapper-with-radio { @@ -53,3 +54,8 @@ } } + +.sms-message-from { + @include bold-19; + display: block; +} diff --git a/app/assets/stylesheets/components/textbox.scss b/app/assets/stylesheets/components/textbox.scss index d340dc494..efb692c27 100644 --- a/app/assets/stylesheets/components/textbox.scss +++ b/app/assets/stylesheets/components/textbox.scss @@ -85,3 +85,7 @@ .textbox-help-link { margin: 5px 0 0 0; } + +.textbox-right-aligned { + text-align: right; +} diff --git a/app/main/dao/services_dao.py b/app/main/dao/services_dao.py index 52c217679..604b2e27d 100644 --- a/app/main/dao/services_dao.py +++ b/app/main/dao/services_dao.py @@ -1,5 +1,6 @@ from flask import url_for from app import notifications_api_client +from notifications_python_client.errors import HTTPError from app.utils import BrowsableItem @@ -26,6 +27,16 @@ def get_service_by_id(id_): return notifications_api_client.get_service(id_) +def get_service_by_id_or_404(id_): + try: + return get_service_by_id(id_) + except HTTPError as e: + if e.status_code == 404: + abort(404) + else: + raise e + + def get_services(user_id=None): if user_id: return notifications_api_client.get_services({'user_id': str(user_id)}) diff --git a/app/main/views/add_service.py b/app/main/views/add_service.py index dc7a3a7d4..ad5d8f715 100644 --- a/app/main/views/add_service.py +++ b/app/main/views/add_service.py @@ -1,4 +1,6 @@ -from flask import render_template, redirect, session, url_for +import re + +from flask import render_template, request, redirect, session, url_for from flask_login import login_required, current_user from app.main import main from app.main.dao import services_dao, users_dao @@ -15,13 +17,33 @@ def add_service(): else: heading = 'Add a new service' if form.validate_on_submit(): - user = users_dao.get_user_by_id(session['user_id']) - service_id = services_dao.insert_new_service(form.name.data, user.id) session['service_name'] = form.name.data - return redirect(url_for('main.service_dashboard', service_id=service_id)) + return redirect(url_for('main.add_from_address')) else: return render_template( 'views/add-service.html', form=form, heading=heading ) + + +@main.route("/confirm-add-service", methods=['GET', 'POST']) +@login_required +def add_from_address(): + if request.method == 'POST': + user = users_dao.get_user_by_id(session['user_id']) + service_id = services_dao.insert_new_service(session['service_name'], user.id) + return redirect(url_for('main.service_dashboard', service_id=service_id)) + else: + return render_template( + 'views/add-from-address.html', + service_name=session['service_name'], + from_address="{}@notifications.service.gov.uk".format(_email_safe(session['service_name'])) + ) + + +def _email_safe(string): + return "".join([ + character.lower() if character.isalnum() or character == "." else "" + for character in re.sub("\s+", ".", string.strip()) + ]) diff --git a/app/main/views/sms.py b/app/main/views/sms.py index 0b4815d26..a135643f7 100644 --- a/app/main/views/sms.py +++ b/app/main/views/sms.py @@ -127,6 +127,7 @@ def check_sms(service_id, upload_id): template_id = upload_data.get('template_id') raw_template = templates_dao.get_service_template_or_404(service_id, template_id)['data'] upload_result = _get_rows(contents, raw_template) + print(upload_result) template = Template( raw_template, values=upload_result['rows'][0] if upload_result['valid'] else {}, diff --git a/app/templates/components/email-message.html b/app/templates/components/email-message.html index 6d9920121..b619b16fa 100644 --- a/app/templates/components/email-message.html +++ b/app/templates/components/email-message.html @@ -1,4 +1,4 @@ -{% macro email_message(subject, body, name=None, edit_link=None) %} +{% macro email_message(subject, body, name=None, edit_link=None, from_name=None, from_address=None) %} {% if name %} {% endif %}