mirror of
https://github.com/GSA/notifications-admin.git
synced 2026-08-24 08:16:51 -04:00
Merge branch 'master' of github.com:alphagov/notifications-admin
This commit is contained in:
@@ -41,3 +41,10 @@
|
|||||||
@extend .table-field;
|
@extend .table-field;
|
||||||
text-align: right;
|
text-align: right;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.table-empty-message {
|
||||||
|
@include core-16;
|
||||||
|
color: $secondary-text-colour;
|
||||||
|
border-bottom: 1px solid $border-colour;
|
||||||
|
padding: 5px 0 8px 0;
|
||||||
|
}
|
||||||
|
|||||||
@@ -1,9 +1,5 @@
|
|||||||
from flask import url_for
|
from flask import url_for
|
||||||
from datetime import datetime
|
from app import notifications_api_client
|
||||||
from client.errors import HTTPError, InvalidResponse
|
|
||||||
from sqlalchemy.orm import load_only
|
|
||||||
from flask.ext.login import current_user
|
|
||||||
from app import (db, notifications_api_client)
|
|
||||||
from app.main.utils import BrowsableItem
|
from app.main.utils import BrowsableItem
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
49
app/main/dao/templates_dao.py
Normal file
49
app/main/dao/templates_dao.py
Normal file
@@ -0,0 +1,49 @@
|
|||||||
|
from flask import url_for
|
||||||
|
from app import notifications_api_client
|
||||||
|
from app.main.utils import BrowsableItem
|
||||||
|
|
||||||
|
|
||||||
|
def insert_service_template(name, type_, content, service_id):
|
||||||
|
return notifications_api_client.create_service_template(
|
||||||
|
name, type_, content, service_id)
|
||||||
|
|
||||||
|
|
||||||
|
def update_service_template(id_, name, type_, content, service_id):
|
||||||
|
return notifications_api_client.update_service_template(
|
||||||
|
id_, name, type_, content, service_id)
|
||||||
|
|
||||||
|
|
||||||
|
def get_service_templates(service_id):
|
||||||
|
return notifications_api_client.get_service_templates(service_id)
|
||||||
|
|
||||||
|
|
||||||
|
def get_service_template(service_id, template_id):
|
||||||
|
return notifications_api_client.get_service_template(
|
||||||
|
service_id, template_id)
|
||||||
|
|
||||||
|
|
||||||
|
def delete_service_template(service_id, template_id):
|
||||||
|
return notifications_api_client.delete_service_template(
|
||||||
|
service_id, template_id)
|
||||||
|
|
||||||
|
|
||||||
|
class TemplatesBrowsableItem(BrowsableItem):
|
||||||
|
|
||||||
|
@property
|
||||||
|
def title(self):
|
||||||
|
return self._item['name']
|
||||||
|
|
||||||
|
@property
|
||||||
|
def link(self):
|
||||||
|
return url_for(
|
||||||
|
'main.edit_service_template',
|
||||||
|
service_id=self._item['service'],
|
||||||
|
template_id=self._item['id'])
|
||||||
|
|
||||||
|
@property
|
||||||
|
def destructive(self):
|
||||||
|
return False
|
||||||
|
|
||||||
|
@property
|
||||||
|
def hint(self):
|
||||||
|
return "Some service template hint here"
|
||||||
@@ -6,7 +6,8 @@ from wtforms import (
|
|||||||
PasswordField,
|
PasswordField,
|
||||||
ValidationError,
|
ValidationError,
|
||||||
TextAreaField,
|
TextAreaField,
|
||||||
FileField
|
FileField,
|
||||||
|
SelectField
|
||||||
)
|
)
|
||||||
from wtforms.validators import DataRequired, Email, Length, Regexp
|
from wtforms.validators import DataRequired, Email, Length, Regexp
|
||||||
|
|
||||||
@@ -187,8 +188,13 @@ class ConfirmPasswordForm(Form):
|
|||||||
|
|
||||||
|
|
||||||
class TemplateForm(Form):
|
class TemplateForm(Form):
|
||||||
template_name = StringField(u'Template name')
|
name = StringField(
|
||||||
template_body = TextAreaField(u'Message')
|
u'Template name',
|
||||||
|
validators=[DataRequired(message="Template name cannot be empty")])
|
||||||
|
template_type = SelectField(u'Template type', choices=[('sms', 'SMS')])
|
||||||
|
content = TextAreaField(
|
||||||
|
u'Message',
|
||||||
|
validators=[DataRequired(message="Template content cannot be empty")])
|
||||||
|
|
||||||
|
|
||||||
class ForgotPasswordForm(Form):
|
class ForgotPasswordForm(Form):
|
||||||
|
|||||||
@@ -19,6 +19,6 @@ def service_dashboard(service_id):
|
|||||||
return render_template(
|
return render_template(
|
||||||
'views/service_dashboard.html',
|
'views/service_dashboard.html',
|
||||||
jobs=jobs,
|
jobs=jobs,
|
||||||
free_text_messages_remaining=560,
|
free_text_messages_remaining='25,000',
|
||||||
spent_this_month='0.00',
|
spent_this_month='0.00',
|
||||||
service_id=service_id)
|
service_id=service_id)
|
||||||
|
|||||||
@@ -50,7 +50,7 @@ messages = [
|
|||||||
def view_jobs(service_id):
|
def view_jobs(service_id):
|
||||||
return render_template(
|
return render_template(
|
||||||
'views/jobs.html',
|
'views/jobs.html',
|
||||||
jobs=jobs,
|
jobs=[], # use `jobs` for placeholder data
|
||||||
service_id=service_id
|
service_id=service_id
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|||||||
@@ -1,12 +1,21 @@
|
|||||||
from datetime import datetime, timedelta
|
from datetime import datetime, timedelta
|
||||||
|
|
||||||
from flask import render_template, redirect, session
|
from flask import (
|
||||||
|
render_template,
|
||||||
|
redirect,
|
||||||
|
session,
|
||||||
|
current_app,
|
||||||
|
abort
|
||||||
|
)
|
||||||
|
|
||||||
|
from client.errors import HTTPError
|
||||||
|
|
||||||
from app.main import main
|
from app.main import main
|
||||||
|
from app.models import User
|
||||||
from app.main.dao import users_dao
|
from app.main.dao import users_dao
|
||||||
from app.main.forms import RegisterUserForm
|
from app.main.forms import RegisterUserForm
|
||||||
from app.models import User
|
|
||||||
|
|
||||||
|
from app.notify_client.user_api_client import UserApiClient
|
||||||
|
|
||||||
# TODO how do we handle duplicate unverifed email addresses?
|
# TODO how do we handle duplicate unverifed email addresses?
|
||||||
# malicious or otherwise.
|
# malicious or otherwise.
|
||||||
@@ -18,6 +27,8 @@ def register():
|
|||||||
form = RegisterUserForm(users_dao.get_user_by_email)
|
form = RegisterUserForm(users_dao.get_user_by_email)
|
||||||
|
|
||||||
if form.validate_on_submit():
|
if form.validate_on_submit():
|
||||||
|
|
||||||
|
# TODO remove once all api integrations done
|
||||||
user = User(name=form.name.data,
|
user = User(name=form.name.data,
|
||||||
email_address=form.email_address.data,
|
email_address=form.email_address.data,
|
||||||
mobile_number=form.mobile_number.data,
|
mobile_number=form.mobile_number.data,
|
||||||
@@ -25,6 +36,21 @@ def register():
|
|||||||
created_at=datetime.now(),
|
created_at=datetime.now(),
|
||||||
role_id=1)
|
role_id=1)
|
||||||
users_dao.insert_user(user)
|
users_dao.insert_user(user)
|
||||||
|
|
||||||
|
user_api_client = UserApiClient(current_app.config['API_HOST_NAME'],
|
||||||
|
current_app.config['ADMIN_CLIENT_USER_NAME'],
|
||||||
|
current_app.config['ADMIN_CLIENT_SECRET'])
|
||||||
|
try:
|
||||||
|
user_api_client.register_user(form.name.data,
|
||||||
|
form.email_address.data,
|
||||||
|
form.mobile_number.data,
|
||||||
|
form.password.data)
|
||||||
|
except HTTPError as e:
|
||||||
|
if e.status_code == 404:
|
||||||
|
abort(404)
|
||||||
|
else:
|
||||||
|
raise e
|
||||||
|
|
||||||
# TODO possibly there should be some exception handling
|
# TODO possibly there should be some exception handling
|
||||||
# for sending sms and email codes.
|
# for sending sms and email codes.
|
||||||
# How do we report to the user there is a problem with
|
# How do we report to the user there is a problem with
|
||||||
|
|||||||
@@ -3,80 +3,99 @@ from flask_login import login_required
|
|||||||
|
|
||||||
from app.main import main
|
from app.main import main
|
||||||
from app.main.forms import TemplateForm
|
from app.main.forms import TemplateForm
|
||||||
|
from app.main.dao.services_dao import get_service_by_id
|
||||||
from ._templates import templates
|
from app.main.dao import templates_dao as dao
|
||||||
|
from client.errors import HTTPError
|
||||||
|
|
||||||
|
|
||||||
@main.route("/services/<int:service_id>/templates")
|
@main.route("/services/<int:service_id>/templates")
|
||||||
@login_required
|
@login_required
|
||||||
def manage_templates(service_id):
|
def manage_service_templates(service_id):
|
||||||
|
try:
|
||||||
|
templates = dao.get_service_templates(service_id)['data']
|
||||||
|
except HTTPError as e:
|
||||||
|
if e.status_code == 404:
|
||||||
|
abort(404)
|
||||||
|
else:
|
||||||
|
raise e
|
||||||
return render_template(
|
return render_template(
|
||||||
'views/manage-templates.html',
|
'views/manage-templates.html',
|
||||||
service_id=service_id,
|
service_id=service_id,
|
||||||
templates=templates,
|
templates=templates)
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
@main.route("/services/<int:service_id>/templates/add", methods=['GET', 'POST'])
|
@main.route("/services/<int:service_id>/templates/add", methods=['GET', 'POST'])
|
||||||
@login_required
|
@login_required
|
||||||
def add_template(service_id):
|
def add_service_template(service_id):
|
||||||
|
try:
|
||||||
|
service = dao.get_service_by_id(service_id)['data']
|
||||||
|
except HTTPError as e:
|
||||||
|
if e.status_code == 404:
|
||||||
|
abort(404)
|
||||||
|
else:
|
||||||
|
raise e
|
||||||
|
|
||||||
form = TemplateForm()
|
form = TemplateForm()
|
||||||
|
|
||||||
if request.method == 'GET':
|
if form.validate_on_submit():
|
||||||
return render_template(
|
dao.insert_service_template(
|
||||||
'views/edit-template.html',
|
form.name.data, form.template_type.data, form.content.data, service_id)
|
||||||
h1='Add template',
|
return redirect(url_for(
|
||||||
form=form,
|
'.manage_service_templates', service_id=service_id))
|
||||||
service_id=service_id
|
return render_template(
|
||||||
)
|
'views/edit-template.html',
|
||||||
elif request.method == 'POST':
|
h1='Add template',
|
||||||
return redirect(url_for('.manage_templates', service_id=service_id))
|
form=form,
|
||||||
|
service_id=service_id)
|
||||||
|
|
||||||
|
|
||||||
@main.route("/services/<int:service_id>/templates/<int:template_id>", methods=['GET', 'POST'])
|
@main.route("/services/<int:service_id>/templates/<int:template_id>", methods=['GET', 'POST'])
|
||||||
@login_required
|
@login_required
|
||||||
def edit_template(service_id, template_id):
|
def edit_service_template(service_id, template_id):
|
||||||
|
try:
|
||||||
|
template = dao.get_service_template(service_id, template_id)['data']
|
||||||
|
except HTTPError as e:
|
||||||
|
if e.status_code == 404:
|
||||||
|
abort(404)
|
||||||
|
else:
|
||||||
|
raise e
|
||||||
|
form = TemplateForm(form_data=template)
|
||||||
|
|
||||||
form = TemplateForm()
|
if form.validate_on_submit():
|
||||||
|
dao.update_service_template(
|
||||||
|
template_id, form.name.data, form.template_type.data,
|
||||||
|
form.content.data, service_id)
|
||||||
|
return redirect(url_for('.manage_service_templates', service_id=service_id))
|
||||||
|
|
||||||
form.template_name.data = templates[template_id - 1]['name']
|
return render_template(
|
||||||
form.template_body.data = templates[template_id - 1]['body']
|
'views/edit-template.html',
|
||||||
|
h1='Edit template',
|
||||||
if request.method == 'GET':
|
form=form,
|
||||||
return render_template(
|
service_id=service_id,
|
||||||
'views/edit-template.html',
|
template_id=template_id)
|
||||||
h1='Edit template',
|
|
||||||
form=form,
|
|
||||||
service_id=service_id,
|
|
||||||
template_id=template_id
|
|
||||||
)
|
|
||||||
elif request.method == 'POST':
|
|
||||||
return redirect(url_for('.manage_templates', service_id=service_id))
|
|
||||||
|
|
||||||
|
|
||||||
@main.route("/services/<int:service_id>/templates/<int:template_id>/delete", methods=['GET', 'POST'])
|
@main.route("/services/<int:service_id>/templates/<int:template_id>/delete", methods=['GET', 'POST'])
|
||||||
@login_required
|
@login_required
|
||||||
def delete_template(service_id, template_id):
|
def delete_service_template(service_id, template_id):
|
||||||
|
try:
|
||||||
form = TemplateForm()
|
template = dao.get_service_template(service_id, template_id)['data']
|
||||||
|
except HTTPError as e:
|
||||||
form.template_name.data = templates[template_id - 1]['name']
|
if e.status_code == 404:
|
||||||
form.template_body.data = templates[template_id - 1]['body']
|
abort(404)
|
||||||
|
|
||||||
if request.method == 'GET':
|
|
||||||
|
|
||||||
flash('Are you sure you want to delete ‘{}’?'.format(form.template_name.data), 'delete')
|
|
||||||
|
|
||||||
return render_template(
|
|
||||||
'views/edit-template.html',
|
|
||||||
h1='Edit template',
|
|
||||||
form=form,
|
|
||||||
service_id=service_id,
|
|
||||||
template_id=template_id
|
|
||||||
)
|
|
||||||
elif request.method == 'POST':
|
|
||||||
if request.form.get('delete'):
|
|
||||||
return redirect(url_for('.manage_templates', service_id=service_id))
|
|
||||||
else:
|
else:
|
||||||
return redirect(url_for('.manage_templates', service_id=service_id))
|
raise e
|
||||||
|
|
||||||
|
form = TemplateForm(form_data=template)
|
||||||
|
|
||||||
|
if form.validate_on_submit():
|
||||||
|
dao.delete_service_template(service_id, template_id)
|
||||||
|
return redirect(url_for('.manage_service_templates', service_id=service_id))
|
||||||
|
|
||||||
|
flash('Are you sure you want to delete ‘{}’?'.format(form.name.data), 'delete')
|
||||||
|
return render_template(
|
||||||
|
'views/edit-template.html',
|
||||||
|
h1='Edit template',
|
||||||
|
form=form,
|
||||||
|
service_id=service_id,
|
||||||
|
template_id=template_id)
|
||||||
|
|||||||
@@ -12,7 +12,7 @@ class NotificationsAdminAPIClient(NotificationsAPIClient):
|
|||||||
"secret")
|
"secret")
|
||||||
|
|
||||||
def init_app(self, application):
|
def init_app(self, application):
|
||||||
self.base_url = application.config['NOTIFY_API_URL']
|
self.base_url = application.config['API_HOST_NAME']
|
||||||
self.client_id = application.config['NOTIFY_API_CLIENT']
|
self.client_id = application.config['NOTIFY_API_CLIENT']
|
||||||
self.secret = application.config['NOTIFY_API_SECRET']
|
self.secret = application.config['NOTIFY_API_SECRET']
|
||||||
|
|
||||||
@@ -83,6 +83,20 @@ class NotificationsAdminAPIClient(NotificationsAPIClient):
|
|||||||
endpoint = "/service/{0}/template".format(service_id)
|
endpoint = "/service/{0}/template".format(service_id)
|
||||||
return self.post(endpoint, data)
|
return self.post(endpoint, data)
|
||||||
|
|
||||||
|
def update_service_template(self, id_, name, type_, content, service_id):
|
||||||
|
"""
|
||||||
|
Update a service template.
|
||||||
|
"""
|
||||||
|
data = {
|
||||||
|
'id': id_,
|
||||||
|
'name': name,
|
||||||
|
'template_type': type_,
|
||||||
|
'content': content,
|
||||||
|
'service': service_id
|
||||||
|
}
|
||||||
|
endpoint = "/service/{0}/template/{1}".format(service_id, id_)
|
||||||
|
return self.put(endpoint, data)
|
||||||
|
|
||||||
def get_service_template(self, service_id, template_id, *params):
|
def get_service_template(self, service_id, template_id, *params):
|
||||||
"""
|
"""
|
||||||
Retrieve a service template.
|
Retrieve a service template.
|
||||||
|
|||||||
18
app/notify_client/user_api_client.py
Normal file
18
app/notify_client/user_api_client.py
Normal file
@@ -0,0 +1,18 @@
|
|||||||
|
from client.notifications import BaseAPIClient
|
||||||
|
|
||||||
|
|
||||||
|
class UserApiClient(BaseAPIClient):
|
||||||
|
|
||||||
|
def __init__(self, base_url, client_id, secret):
|
||||||
|
super(self.__class__, self).__init__(base_url=base_url,
|
||||||
|
client_id=client_id,
|
||||||
|
secret=secret)
|
||||||
|
|
||||||
|
def register_user(self, name, email_address, mobile_number, password):
|
||||||
|
data = {
|
||||||
|
"name": name,
|
||||||
|
"email_address": email_address,
|
||||||
|
"mobile_number": mobile_number,
|
||||||
|
"password": password}
|
||||||
|
|
||||||
|
return self.post("/user", data)
|
||||||
@@ -23,20 +23,21 @@
|
|||||||
{%- endmacro %}
|
{%- endmacro %}
|
||||||
|
|
||||||
{% macro list_table(items, caption='', empty_message='', field_headings=[], field_headings_visible=True, caption_visible=True) -%}
|
{% macro list_table(items, caption='', empty_message='', field_headings=[], field_headings_visible=True, caption_visible=True) -%}
|
||||||
{% if items %}
|
|
||||||
{% set parent_caller = caller %}
|
{% set parent_caller = caller %}
|
||||||
{% call mapping_table(caption, field_headings, field_headings_visible, caption_visible) %}
|
{% call mapping_table(caption, field_headings, field_headings_visible, caption_visible) %}
|
||||||
{% for item in items %}
|
{% for item in items %}
|
||||||
{% call row() %}
|
{% call row() %}
|
||||||
{{ parent_caller(item) }}
|
{{ parent_caller(item) }}
|
||||||
{% endcall %}
|
{% endcall %}
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
{%- endcall %}
|
{%- endcall %}
|
||||||
{% else %}
|
{% if not items %}
|
||||||
<p class="summary-item-no-content">
|
<p class="table-empty-message">
|
||||||
{{ empty_message }}
|
{{ empty_message }}
|
||||||
</p>
|
</p>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|
||||||
{%- endmacro %}
|
{%- endmacro %}
|
||||||
|
|
||||||
{% macro row() -%}
|
{% macro row() -%}
|
||||||
|
|||||||
@@ -6,7 +6,7 @@
|
|||||||
<li><a href="{{ url_for('.send_sms', service_id=service_id) }}">Send text messages</a></li>
|
<li><a href="{{ url_for('.send_sms', service_id=service_id) }}">Send text messages</a></li>
|
||||||
<li><a href="{{ url_for('.send_email', service_id=service_id) }}">Send emails</a></li>
|
<li><a href="{{ url_for('.send_email', service_id=service_id) }}">Send emails</a></li>
|
||||||
<li><a href="{{ url_for('.view_jobs', service_id=service_id) }}">Activity</a></li>
|
<li><a href="{{ url_for('.view_jobs', service_id=service_id) }}">Activity</a></li>
|
||||||
<li><a href="{{ url_for('.manage_templates', service_id=service_id) }}">Templates</a></li>
|
<li><a href="{{ url_for('.manage_service_templates', service_id=service_id) }}">Templates</a></li>
|
||||||
</ul>
|
</ul>
|
||||||
<ul>
|
<ul>
|
||||||
<li><a href="{{ url_for('.api_keys', service_id=service_id) }}">API keys and documentation</a></li>
|
<li><a href="{{ url_for('.api_keys', service_id=service_id) }}">API keys and documentation</a></li>
|
||||||
|
|||||||
@@ -11,12 +11,12 @@ GOV.UK Notify | Edit template
|
|||||||
<h1 class="heading-xlarge">{{ h1 }}</h1>
|
<h1 class="heading-xlarge">{{ h1 }}</h1>
|
||||||
|
|
||||||
<form method="post">
|
<form method="post">
|
||||||
{{ textbox(form.template_name) }}
|
{{ textbox(form.name) }}
|
||||||
{{ textbox(form.template_body, highlight_tags=True) }}
|
{{ textbox(form.content, highlight_tags=True) }}
|
||||||
{{ page_footer(
|
{{ page_footer(
|
||||||
'Save',
|
'Save',
|
||||||
delete_link=url_for('.delete_template', service_id=service_id, template_id=template_id) if template_id or None,
|
delete_link=url_for('.delete_service_template', service_id=service_id, template_id=template_id) if template_id or None,
|
||||||
back_link=url_for('.manage_templates', service_id=service_id),
|
back_link=url_for('.manage_service_templates', service_id=service_id),
|
||||||
back_link_text='Back to templates'
|
back_link_text='Back to templates'
|
||||||
) }}
|
) }}
|
||||||
</form>
|
</form>
|
||||||
|
|||||||
@@ -38,7 +38,7 @@ GOV.UK Notify | Notifications activity
|
|||||||
</ul>
|
</ul>
|
||||||
|
|
||||||
<p>
|
<p>
|
||||||
Sent with template <a href="{{ url_for('.edit_template', service_id=service_id, template_id=1) }}">{{ template_used }}</a> at {{ uploaded_file_time }}
|
Sent with template <a href="{{ url_for('.edit_service_template', service_id=service_id, template_id=1) }}">{{ template_used }}</a> at {{ uploaded_file_time }}
|
||||||
</p>
|
</p>
|
||||||
|
|
||||||
{% call(item) list_table(
|
{% call(item) list_table(
|
||||||
|
|||||||
@@ -13,6 +13,7 @@ GOV.UK Notify | Notifications activity
|
|||||||
jobs,
|
jobs,
|
||||||
caption="Recent activity",
|
caption="Recent activity",
|
||||||
caption_visible=False,
|
caption_visible=False,
|
||||||
|
empty_message='You haven’t sent any notifications yet',
|
||||||
field_headings=['Job', 'File', 'Time', 'Status']
|
field_headings=['Job', 'File', 'Time', 'Status']
|
||||||
) %}
|
) %}
|
||||||
{% call field() %}
|
{% call field() %}
|
||||||
|
|||||||
@@ -15,21 +15,21 @@ GOV.UK Notify | Manage templates
|
|||||||
<h1 class="heading-xlarge">Templates</h1>
|
<h1 class="heading-xlarge">Templates</h1>
|
||||||
|
|
||||||
<p>
|
<p>
|
||||||
<a href="{{ url_for('.add_template', service_id=service_id) }}">Create new template</a>
|
<a href="{{ url_for('.add_service_template', service_id=service_id) }}">Create new template</a>
|
||||||
|
|
||||||
{% for template in templates %}
|
{% for template in templates %}
|
||||||
{% if template.type == 'sms' %}
|
{% if template.type == 'sms' %}
|
||||||
{{ sms_message(
|
{{ sms_message(
|
||||||
template.body,
|
template.content,
|
||||||
name=template.name,
|
name=template.name,
|
||||||
edit_link=url_for('.edit_template', service_id=service_id, template_id=loop.index)
|
edit_link=url_for('.edit_service_template', service_id=template.service, template_id=template.id)
|
||||||
) }}
|
) }}
|
||||||
{% elif template.type == 'email' %}
|
{% elif template.type == 'email' %}
|
||||||
{{ email_message(
|
{{ email_message(
|
||||||
template.subject,
|
"template subject",
|
||||||
template.body,
|
template.content,
|
||||||
name=template.name,
|
name=template.name,
|
||||||
edit_link=url_for('.edit_template', service_id=service_id, template_id=loop.index)
|
edit_link=url_for('.edit_service_template', service_id=template.service, template_id=template.id)
|
||||||
) }}
|
) }}
|
||||||
{% endif %}
|
{% endif %}
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
|
|||||||
@@ -23,7 +23,7 @@
|
|||||||
</fieldset>
|
</fieldset>
|
||||||
|
|
||||||
<p>
|
<p>
|
||||||
or <a href="{{ url_for(".add_template", service_id=service_id) }}">create a new template</a>
|
or <a href="{{ url_for('.add_service_template', service_id=service_id) }}">create a new template</a>
|
||||||
</p>
|
</p>
|
||||||
|
|
||||||
<h2 class="heading-medium">2. Add recipients</h2>
|
<h2 class="heading-medium">2. Add recipients</h2>
|
||||||
|
|||||||
@@ -24,9 +24,9 @@
|
|||||||
</ul>
|
</ul>
|
||||||
|
|
||||||
{% call(item) list_table(
|
{% call(item) list_table(
|
||||||
jobs[:3],
|
[],
|
||||||
caption="Recent text messages",
|
caption="Recent text messages",
|
||||||
empty_message="No recent text messages",
|
empty_message='You haven’t sent any text messages yet',
|
||||||
field_headings=['Job', 'File', 'Time', 'Status']
|
field_headings=['Job', 'File', 'Time', 'Status']
|
||||||
) %}
|
) %}
|
||||||
{% call field() %}
|
{% call field() %}
|
||||||
@@ -42,9 +42,5 @@
|
|||||||
{{ item.status }}
|
{{ item.status }}
|
||||||
{% endcall %}
|
{% endcall %}
|
||||||
{% endcall %}
|
{% endcall %}
|
||||||
<p>
|
|
||||||
<a href={{ url_for('.view_jobs', service_id=service_id) }}>See all notifications activity</a>
|
|
||||||
</p>
|
|
||||||
|
|
||||||
|
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|||||||
@@ -148,6 +148,21 @@
|
|||||||
{% endcall %}
|
{% endcall %}
|
||||||
{% endcall %}
|
{% endcall %}
|
||||||
|
|
||||||
|
{% call(item) list_table(
|
||||||
|
[],
|
||||||
|
caption='Jobs',
|
||||||
|
field_headings=['Job', 'Time'],
|
||||||
|
caption_visible=True,
|
||||||
|
empty_message='You haven’t scheduled any jobs yet'
|
||||||
|
) %}
|
||||||
|
{% call field() %}
|
||||||
|
{{ item.job }}
|
||||||
|
{% endcall %}
|
||||||
|
{% call field() %}
|
||||||
|
{{ item.time }}
|
||||||
|
{% endcall %}
|
||||||
|
{% endcall %}
|
||||||
|
|
||||||
<h2 class="heading-large">Textbox</h2>
|
<h2 class="heading-large">Textbox</h2>
|
||||||
{{ textbox(form.username) }}
|
{{ textbox(form.username) }}
|
||||||
{{ textbox(form.password) }}
|
{{ textbox(form.password) }}
|
||||||
|
|||||||
11
config.py
11
config.py
@@ -22,10 +22,13 @@ class Config(object):
|
|||||||
SESSION_COOKIE_HTTPONLY = True
|
SESSION_COOKIE_HTTPONLY = True
|
||||||
SESSION_COOKIE_SECURE = True
|
SESSION_COOKIE_SECURE = True
|
||||||
|
|
||||||
NOTIFY_API_URL = os.getenv('NOTIFY_API_URL', "http://localhost:6001")
|
API_HOST_NAME = os.getenv('API_HOST_NAME')
|
||||||
NOTIFY_API_SECRET = os.getenv('NOTIFY_API_SECRET', "dev-secret")
|
NOTIFY_API_SECRET = os.getenv('NOTIFY_API_SECRET', "dev-secret")
|
||||||
NOTIFY_API_CLIENT = os.getenv('NOTIFY_API_CLIENT', "admin")
|
NOTIFY_API_CLIENT = os.getenv('NOTIFY_API_CLIENT', "admin")
|
||||||
|
|
||||||
|
ADMIN_CLIENT_USER_NAME = os.getenv('ADMIN_CLIENT_USER_NAME')
|
||||||
|
ADMIN_CLIENT_SECRET = os.getenv('ADMIN_CLIENT_SECRET')
|
||||||
|
|
||||||
WTF_CSRF_ENABLED = True
|
WTF_CSRF_ENABLED = True
|
||||||
SECRET_KEY = 'secret-key'
|
SECRET_KEY = 'secret-key'
|
||||||
HTTP_PROTOCOL = 'http'
|
HTTP_PROTOCOL = 'http'
|
||||||
@@ -38,10 +41,12 @@ class Config(object):
|
|||||||
|
|
||||||
class Development(Config):
|
class Development(Config):
|
||||||
DEBUG = True
|
DEBUG = True
|
||||||
|
API_HOST_NAME = 'http://localhost:6011'
|
||||||
|
ADMIN_CLIENT_USER_NAME = 'dev-notify-admin'
|
||||||
|
ADMIN_CLIENT_SECRET = 'dev-notify-secret-key'
|
||||||
|
|
||||||
|
|
||||||
class Test(Config):
|
class Test(Development):
|
||||||
DEBUG = True
|
|
||||||
SQLALCHEMY_DATABASE_URI = 'postgresql://localhost/test_notifications_admin'
|
SQLALCHEMY_DATABASE_URI = 'postgresql://localhost/test_notifications_admin'
|
||||||
WTF_CSRF_ENABLED = False
|
WTF_CSRF_ENABLED = False
|
||||||
|
|
||||||
|
|||||||
@@ -29,6 +29,16 @@ def service_json(id_, name, users, limit=1000, active=False, restricted=True):
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
def template_json(id_, name, type_, content, service_id):
|
||||||
|
return {
|
||||||
|
'id': id_,
|
||||||
|
'name': name,
|
||||||
|
'template_type': type_,
|
||||||
|
'content': content,
|
||||||
|
'service': service_id
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
TEST_USER_EMAIL = 'test@user.gov.uk'
|
TEST_USER_EMAIL = 'test@user.gov.uk'
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -13,5 +13,4 @@ def test_should_show_recent_jobs_on_dashboard(app_,
|
|||||||
response = client.get(url_for('main.service_dashboard', service_id=123))
|
response = client.get(url_for('main.service_dashboard', service_id=123))
|
||||||
|
|
||||||
assert response.status_code == 200
|
assert response.status_code == 200
|
||||||
assert 'Test message 1' in response.get_data(as_text=True)
|
assert 'You haven’t sent any text messages yet' in response.get_data(as_text=True)
|
||||||
assert 'Asdfgg' in response.get_data(as_text=True)
|
|
||||||
|
|||||||
@@ -11,8 +11,7 @@ def test_should_return_list_of_all_jobs(app_, db_, db_session, service_one):
|
|||||||
response = client.get(url_for('main.view_jobs', service_id=101))
|
response = client.get(url_for('main.view_jobs', service_id=101))
|
||||||
|
|
||||||
assert response.status_code == 200
|
assert response.status_code == 200
|
||||||
assert 'Test message 1' in response.get_data(as_text=True)
|
assert 'You haven’t sent any notifications yet' in response.get_data(as_text=True)
|
||||||
assert 'Final reminder' in response.get_data(as_text=True)
|
|
||||||
|
|
||||||
|
|
||||||
def test_should_show_page_for_one_job(app_, db_, db_session, service_one):
|
def test_should_show_page_for_one_job(app_, db_, db_session, service_one):
|
||||||
|
|||||||
@@ -1,5 +1,7 @@
|
|||||||
from flask import url_for
|
from flask import url_for
|
||||||
|
|
||||||
|
from tests.conftest import mock_register_user
|
||||||
|
|
||||||
|
|
||||||
def test_render_register_returns_template_with_form(app_, db_, db_session):
|
def test_render_register_returns_template_with_form(app_, db_, db_session):
|
||||||
response = app_.test_client().get('/register')
|
response = app_.test_client().get('/register')
|
||||||
@@ -12,13 +14,21 @@ def test_process_register_creates_new_user(app_,
|
|||||||
db_,
|
db_,
|
||||||
db_session,
|
db_session,
|
||||||
mock_send_sms,
|
mock_send_sms,
|
||||||
mock_send_email):
|
mock_send_email,
|
||||||
|
mocker):
|
||||||
|
|
||||||
|
user_data = {
|
||||||
|
'name': 'Some One Valid',
|
||||||
|
'email_address': 'someone@example.gov.uk',
|
||||||
|
'mobile_number': '+4407700900460',
|
||||||
|
'password': 'validPassword!'
|
||||||
|
}
|
||||||
|
|
||||||
|
mock_register_user(mocker, user_data)
|
||||||
|
|
||||||
with app_.test_request_context():
|
with app_.test_request_context():
|
||||||
response = app_.test_client().post('/register',
|
response = app_.test_client().post('/register',
|
||||||
data={'name': 'Some One Valid',
|
data=user_data)
|
||||||
'email_address': 'someone@example.gov.uk',
|
|
||||||
'mobile_number': '+4407700900460',
|
|
||||||
'password': 'validPassword!'})
|
|
||||||
assert response.status_code == 302
|
assert response.status_code == 302
|
||||||
assert response.location == url_for('main.verify', _external=True)
|
assert response.location == url_for('main.verify', _external=True)
|
||||||
|
|
||||||
@@ -57,13 +67,19 @@ def test_should_add_verify_codes_on_session(app_,
|
|||||||
db_,
|
db_,
|
||||||
db_session,
|
db_session,
|
||||||
mock_send_sms,
|
mock_send_sms,
|
||||||
mock_send_email):
|
mock_send_email,
|
||||||
|
mocker):
|
||||||
|
user_data = {
|
||||||
|
'name': 'Test Codes',
|
||||||
|
'email_address': 'test@example.gov.uk',
|
||||||
|
'mobile_number': '+4407700900460',
|
||||||
|
'password': 'validPassword!'
|
||||||
|
}
|
||||||
|
|
||||||
|
mock_register_user(mocker, user_data)
|
||||||
with app_.test_client() as client:
|
with app_.test_client() as client:
|
||||||
response = client.post('/register',
|
response = client.post('/register',
|
||||||
data={'name': 'Test Codes',
|
data=user_data)
|
||||||
'email_address': 'test_codes@example.gov.uk',
|
|
||||||
'mobile_number': '+4407700900460',
|
|
||||||
'password': 'validPassword!'})
|
|
||||||
assert response.status_code == 302
|
assert response.status_code == 302
|
||||||
assert 'notify_admin_session' in response.headers.get('Set-Cookie')
|
assert 'notify_admin_session' in response.headers.get('Set-Cookie')
|
||||||
|
|
||||||
|
|||||||
@@ -1,49 +1,128 @@
|
|||||||
|
import json
|
||||||
from flask import url_for
|
from flask import url_for
|
||||||
|
|
||||||
|
|
||||||
def test_should_return_list_of_all_templates(app_, db_, db_session, active_user):
|
def test_should_return_list_of_all_templates(app_,
|
||||||
|
db_,
|
||||||
|
db_session,
|
||||||
|
active_user,
|
||||||
|
mock_get_service_templates):
|
||||||
with app_.test_request_context():
|
with app_.test_request_context():
|
||||||
with app_.test_client() as client:
|
with app_.test_client() as client:
|
||||||
client.login(active_user)
|
client.login(active_user)
|
||||||
response = client.get(url_for('.manage_templates', service_id=123))
|
service_id = 123
|
||||||
|
response = client.get(url_for(
|
||||||
|
'.manage_service_templates', service_id=service_id))
|
||||||
|
|
||||||
assert response.status_code == 200
|
assert response.status_code == 200
|
||||||
|
mock_get_service_templates.assert_called_with(service_id)
|
||||||
|
|
||||||
|
|
||||||
def test_should_show_page_for_one_templates(app_, db_, db_session, active_user):
|
def test_should_show_page_for_one_templates(app_,
|
||||||
|
db_,
|
||||||
|
db_session,
|
||||||
|
active_user,
|
||||||
|
mock_get_service_template):
|
||||||
with app_.test_request_context():
|
with app_.test_request_context():
|
||||||
with app_.test_client() as client:
|
with app_.test_client() as client:
|
||||||
client.login(active_user)
|
client.login(active_user)
|
||||||
response = client.get(url_for('.edit_template', service_id=123, template_id=1))
|
service_id = 123
|
||||||
|
template_id = 456
|
||||||
|
response = client.get(url_for(
|
||||||
|
'.edit_service_template',
|
||||||
|
service_id=service_id,
|
||||||
|
template_id=template_id))
|
||||||
|
|
||||||
assert response.status_code == 200
|
assert response.status_code == 200
|
||||||
|
mock_get_service_template.assert_called_with(
|
||||||
|
service_id, template_id)
|
||||||
|
|
||||||
|
|
||||||
def test_should_redirect_when_saving_a_template(app_, db_, db_session, active_user):
|
def test_should_redirect_when_saving_a_template(app_,
|
||||||
|
db_,
|
||||||
|
db_session,
|
||||||
|
active_user,
|
||||||
|
mock_get_service_template,
|
||||||
|
mock_update_service_template):
|
||||||
with app_.test_request_context():
|
with app_.test_request_context():
|
||||||
with app_.test_client() as client:
|
with app_.test_client() as client:
|
||||||
client.login(active_user)
|
client.login(active_user)
|
||||||
response = client.post(url_for('.edit_template', service_id=123, template_id=1))
|
service_id = 123
|
||||||
|
template_id = 456
|
||||||
|
name = "new name"
|
||||||
|
type_ = "sms"
|
||||||
|
content = "template content"
|
||||||
|
data = {
|
||||||
|
'id': template_id,
|
||||||
|
'name': name,
|
||||||
|
'template_type': type_,
|
||||||
|
"content": content,
|
||||||
|
"service": service_id
|
||||||
|
}
|
||||||
|
response = client.post(url_for(
|
||||||
|
'.edit_service_template',
|
||||||
|
service_id=service_id,
|
||||||
|
template_id=template_id), data=data)
|
||||||
|
|
||||||
assert response.status_code == 302
|
assert response.status_code == 302
|
||||||
assert response.location == url_for('.manage_templates', service_id=123, _external=True)
|
assert response.location == url_for(
|
||||||
|
'.manage_service_templates', service_id=service_id, _external=True)
|
||||||
|
mock_update_service_template.assert_called_with(
|
||||||
|
template_id, name, type_, content, service_id)
|
||||||
|
|
||||||
|
|
||||||
def test_should_show_delete_template_page(app_, db_, db_session, active_user):
|
def test_should_show_delete_template_page(app_,
|
||||||
|
db_,
|
||||||
|
db_session,
|
||||||
|
active_user,
|
||||||
|
mock_get_service_template):
|
||||||
with app_.test_request_context():
|
with app_.test_request_context():
|
||||||
with app_.test_client() as client:
|
with app_.test_client() as client:
|
||||||
client.login(active_user)
|
client.login(active_user)
|
||||||
response = client.get(url_for('.delete_template', service_id=123, template_id=1))
|
service_id = 123
|
||||||
|
template_id = 456
|
||||||
|
response = client.get(url_for(
|
||||||
|
'.delete_service_template',
|
||||||
|
service_id=service_id,
|
||||||
|
template_id=template_id))
|
||||||
|
|
||||||
assert response.status_code == 200
|
assert response.status_code == 200
|
||||||
assert 'Are you sure' in response.get_data(as_text=True)
|
assert 'Are you sure' in response.get_data(as_text=True)
|
||||||
|
mock_get_service_template.assert_called_with(
|
||||||
|
service_id, template_id)
|
||||||
|
|
||||||
|
|
||||||
def test_should_redirect_when_deleting_a_template(app_, db_, db_session, active_user):
|
def test_should_redirect_when_deleting_a_template(app_,
|
||||||
|
db_,
|
||||||
|
db_session,
|
||||||
|
active_user,
|
||||||
|
mock_get_service_template,
|
||||||
|
mock_delete_service_template):
|
||||||
with app_.test_request_context():
|
with app_.test_request_context():
|
||||||
with app_.test_client() as client:
|
with app_.test_client() as client:
|
||||||
client.login(active_user)
|
client.login(active_user)
|
||||||
response = client.post(url_for('.delete_template', service_id=123, template_id=1))
|
service_id = 123
|
||||||
|
template_id = 456
|
||||||
|
name = "new name"
|
||||||
|
type_ = "sms"
|
||||||
|
content = "template content"
|
||||||
|
data = {
|
||||||
|
'id': template_id,
|
||||||
|
'name': name,
|
||||||
|
'template_type': type_,
|
||||||
|
'content': content,
|
||||||
|
'service': service_id
|
||||||
|
}
|
||||||
|
response = client.post(url_for(
|
||||||
|
'.delete_service_template',
|
||||||
|
service_id=service_id,
|
||||||
|
template_id=template_id), data=data)
|
||||||
|
|
||||||
assert response.status_code == 302
|
assert response.status_code == 302
|
||||||
assert response.location == url_for('.manage_templates', service_id=123, _external=True)
|
assert response.location == url_for(
|
||||||
|
'.manage_service_templates',
|
||||||
|
service_id=service_id, _external=True)
|
||||||
|
mock_get_service_template.assert_called_with(
|
||||||
|
service_id, template_id)
|
||||||
|
mock_delete_service_template.assert_called_with(
|
||||||
|
service_id, template_id)
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ from flask.ext.script import Manager
|
|||||||
from sqlalchemy.schema import MetaData
|
from sqlalchemy.schema import MetaData
|
||||||
from . import (
|
from . import (
|
||||||
create_test_user, create_another_test_user, service_json, TestClient,
|
create_test_user, create_another_test_user, service_json, TestClient,
|
||||||
get_test_user)
|
get_test_user, template_json)
|
||||||
from app import create_app, db
|
from app import create_app, db
|
||||||
|
|
||||||
|
|
||||||
@@ -94,12 +94,11 @@ def mock_get_service(mocker, active_user):
|
|||||||
|
|
||||||
@pytest.fixture(scope='function')
|
@pytest.fixture(scope='function')
|
||||||
def mock_create_service(mocker):
|
def mock_create_service(mocker):
|
||||||
# TODO fix token generation
|
|
||||||
def _create(service_name, active, limit, restricted, user_id):
|
def _create(service_name, active, limit, restricted, user_id):
|
||||||
service = service_json(
|
service = service_json(
|
||||||
101, service_name, [user_id], limit=limit,
|
101, service_name, [user_id], limit=limit,
|
||||||
active=active, restricted=restricted)
|
active=active, restricted=restricted)
|
||||||
return {'data': service, 'token': 1}
|
return {'data': service}
|
||||||
mock_class = mocker.patch(
|
mock_class = mocker.patch(
|
||||||
'app.notifications_api_client.create_service', side_effect=_create)
|
'app.notifications_api_client.create_service', side_effect=_create)
|
||||||
return mock_class
|
return mock_class
|
||||||
@@ -142,3 +141,76 @@ def mock_delete_service(mocker, mock_get_service):
|
|||||||
mock_class = mocker.patch(
|
mock_class = mocker.patch(
|
||||||
'app.notifications_api_client.delete_service', side_effect=_delete)
|
'app.notifications_api_client.delete_service', side_effect=_delete)
|
||||||
return mock_class
|
return mock_class
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.fixture(scope='function')
|
||||||
|
def mock_get_service_template(mocker):
|
||||||
|
def _create(service_id, template_id):
|
||||||
|
template = template_json(
|
||||||
|
template_id, "Template Name", "sms", "template content", service_id)
|
||||||
|
return {'data': template}
|
||||||
|
return mocker.patch(
|
||||||
|
'app.notifications_api_client.get_service_template',
|
||||||
|
side_effect=_create)
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.fixture(scope='function')
|
||||||
|
def mock_create_service_template(mocker):
|
||||||
|
def _create(name, type_, content, service):
|
||||||
|
template = template_json(
|
||||||
|
101, name, type_, content, service)
|
||||||
|
return {'data': template}
|
||||||
|
mock_class = mocker.patch(
|
||||||
|
'app.notifications_api_client.create_service_template',
|
||||||
|
side_effect=_create)
|
||||||
|
return mock_class
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.fixture(scope='function')
|
||||||
|
def mock_update_service_template(mocker):
|
||||||
|
def _update(id_, name, type_, content, service):
|
||||||
|
template = template_json(
|
||||||
|
id_, name, type_, content, service)
|
||||||
|
return {'data': template}
|
||||||
|
mock_class = mocker.patch(
|
||||||
|
'app.notifications_api_client.update_service_template',
|
||||||
|
side_effect=_update)
|
||||||
|
return mock_class
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.fixture(scope='function')
|
||||||
|
def mock_get_service_templates(mocker):
|
||||||
|
def _create(service_id):
|
||||||
|
template_one = template_json(
|
||||||
|
1, "template_one", "sms", "template one content", service_id)
|
||||||
|
template_two = template_json(
|
||||||
|
2, "template_two", "sms", "template two content", service_id)
|
||||||
|
return {'data': [template_one, template_two]}
|
||||||
|
mock_class = mocker.patch(
|
||||||
|
'app.notifications_api_client.get_service_templates',
|
||||||
|
side_effect=_create)
|
||||||
|
return mock_class
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.fixture(scope='function')
|
||||||
|
def mock_delete_service_template(mocker):
|
||||||
|
def _delete(service_id, template_id):
|
||||||
|
template = template_json(
|
||||||
|
template_id, "Template to delete",
|
||||||
|
"sms", "content to be deleted", service_id)
|
||||||
|
return {'data': template}
|
||||||
|
return mocker.patch(
|
||||||
|
'app.notifications_api_client.delete_service_template', side_effect=_delete)
|
||||||
|
|
||||||
|
|
||||||
|
def mock_register_user(mocker, user_data):
|
||||||
|
data = {
|
||||||
|
"email_address": user_data['email_address'],
|
||||||
|
"failed_login_count": 0,
|
||||||
|
"mobile_number": user_data['mobile_number'],
|
||||||
|
"name": user_data['name'],
|
||||||
|
"state": "pending"
|
||||||
|
}
|
||||||
|
mock_class = mocker.patch('app.main.views.register.UserApiClient')
|
||||||
|
mock_class.register_user.return_value = data
|
||||||
|
return mock_class
|
||||||
|
|||||||
Reference in New Issue
Block a user