Merge branch 'master' into master

This commit is contained in:
Chris Hill-Scott
2018-01-19 12:18:17 +00:00
committed by GitHub
10 changed files with 149 additions and 207 deletions

View File

@@ -25,6 +25,7 @@ from functools import partial
from notifications_python_client.errors import HTTPError
from notifications_utils import logging, request_helper, formatters
from notifications_utils.clients import DeskproClient
from notifications_utils.clients.statsd.statsd_client import StatsdClient
from notifications_utils.recipients import (
validate_phone_number,
@@ -73,6 +74,7 @@ provider_client = ProviderClient()
organisations_client = OrganisationsClient()
asset_fingerprinter = AssetFingerprinter()
statsd_client = StatsdClient()
deskpro_client = DeskproClient()
letter_jobs_client = LetterJobsClient()
inbound_number_client = InboundNumberClient()
billing_api_client = BillingAPIClient()
@@ -90,6 +92,7 @@ def create_app(application):
init_app(application)
statsd_client.init_app(application)
deskpro_client.init_app(application)
logging.init_app(application, statsd_client)
csrf.init_app(application)
request_helper.init_app(application)

View File

@@ -1,12 +1,14 @@
import requests
import pytz
from flask import render_template, url_for, redirect, current_app, abort, request, session
from flask import render_template, url_for, redirect, abort, request, session
from flask_login import current_user
from app import convert_to_boolean, current_service, service_api_client
from notifications_utils.clients import DeskproError
from app import convert_to_boolean, current_service, service_api_client, deskpro_client
from app.main import main
from app.main.forms import SupportType, Feedback, Problem, Triage
from datetime import datetime
QUESTION_TICKET_TYPE = 'ask-question-give-feedback'
PROBLEM_TICKET_TYPE = "report-problem"
@@ -113,31 +115,17 @@ def feedback(ticket_type):
'' if user_email else '{} (no email address supplied)'.format(form.name.data),
form.feedback.data
)
data = {
'person_email': user_email or current_app.config.get('DESKPRO_PERSON_EMAIL'),
'person_name': user_name,
'department_id': current_app.config.get('DESKPRO_DEPT_ID'),
'agent_team_id': current_app.config.get('DESKPRO_ASSIGNED_AGENT_TEAM_ID'),
'subject': 'Notify feedback {}'.format(user_name),
'message': feedback_msg,
'label': ticket_type,
'urgency': 10 if urgent else 1,
}
headers = {
"X-DeskPRO-API-Key": current_app.config.get('DESKPRO_API_KEY'),
'Content-Type': "application/x-www-form-urlencoded"
}
resp = requests.post(
current_app.config.get('DESKPRO_API_HOST') + '/api/tickets',
data=data,
headers=headers)
if resp.status_code != 201:
current_app.logger.error(
"Deskpro create ticket request failed with {} '{}'".format(
resp.status_code,
resp.json()
)
try:
deskpro_client.create_ticket(
subject='Notify feedback {}'.format(user_name),
message=feedback_msg,
ticket_type=ticket_type,
urgency=10 if urgent else 1,
user_email=user_email,
user_name=user_name
)
except DeskproError:
abort(500, "Feedback submission failed")
return redirect(url_for('.thanks', urgent=urgent, anonymous=anonymous))
@@ -191,25 +179,40 @@ def is_weekend(time):
def is_bank_holiday(time):
return time.strftime('%d/%m/%Y') in {
# taken from
# https://github.com/alphagov/calendars/blob/7f6512b0a95d77aa22accef105860074c19f1ec0/lib/data/bank-holidays.json
"01/01/2016",
"25/03/2016",
"28/03/2016",
"02/05/2016",
"30/05/2016",
"29/08/2016",
"26/12/2016",
"27/12/2016",
"02/01/2017",
"14/04/2017",
"17/04/2017",
"01/05/2017",
"29/05/2017",
"28/08/2017",
"25/12/2017",
"26/12/2017",
return time.strftime('%Y-%m-%d') in {
# taken from https://www.gov.uk/bank-holidays.json
"2016-01-01",
"2016-03-25",
"2016-03-28",
"2016-05-02",
"2016-05-30",
"2016-08-29",
"2016-12-26",
"2016-12-27",
"2017-01-02",
"2017-04-14",
"2017-04-17",
"2017-05-01",
"2017-05-29",
"2017-08-28",
"2017-12-25",
"2017-12-26",
"2018-01-01",
"2018-03-30",
"2018-04-02",
"2018-05-07",
"2018-05-28",
"2018-08-27",
"2018-12-25",
"2018-12-26",
"2019-01-01",
"2019-04-19",
"2019-04-22",
"2019-05-06",
"2019-05-27",
"2019-08-26",
"2019-12-25",
"2019-12-26",
}

View File

@@ -1,4 +1,3 @@
import requests
from flask import (
render_template,
redirect,
@@ -7,7 +6,6 @@ from flask import (
session,
flash,
abort,
current_app
)
from flask_login import (
@@ -16,9 +14,10 @@ from flask_login import (
)
from notifications_utils.field import Field
from notifications_utils.clients import DeskproError
from notifications_python_client.errors import HTTPError
from app import service_api_client
from app import service_api_client, deskpro_client
from app.main import main
from app.utils import user_has_permissions, email_safe, get_cdn_domain
from app.main.forms import (
@@ -153,56 +152,40 @@ def service_request_to_go_live(service_id):
form = RequestToGoLiveForm()
if form.validate_on_submit():
data = {
'person_email': current_user.email_address,
'person_name': current_user.name,
'department_id': current_app.config.get('DESKPRO_DEPT_ID'),
'agent_team_id': current_app.config.get('DESKPRO_ASSIGNED_AGENT_TEAM_ID'),
'subject': 'Request to go live - {}'.format(current_service['name']),
'message': (
'On behalf of {} ({})\n'
'\n---'
'\nOrganisation type: {}'
'\nMOU in place: {}'
'\nChannel: {}\nStart date: {}\nStart volume: {}'
'\nPeak volume: {}'
'\nFeatures: {}'
).format(
current_service['name'],
url_for('main.service_dashboard', service_id=current_service['id'], _external=True),
current_service['organisation_type'],
form.mou.data,
formatted_list(filter(None, (
'email' if form.channel_email.data else None,
'text messages' if form.channel_sms.data else None,
'letters' if form.channel_letter.data else None,
)), before_each='', after_each=''),
form.start_date.data,
form.start_volume.data,
form.peak_volume.data,
formatted_list(filter(None, (
'one off' if form.method_one_off.data else None,
'file upload' if form.method_upload.data else None,
'API' if form.method_api.data else None,
)), before_each='', after_each='')
)
}
headers = {
"X-DeskPRO-API-Key": current_app.config.get('DESKPRO_API_KEY'),
'Content-Type': "application/x-www-form-urlencoded"
}
resp = requests.post(
current_app.config.get('DESKPRO_API_HOST') + '/api/tickets',
data=data,
headers=headers
)
if resp.status_code != 201:
current_app.logger.error(
"Deskpro create ticket request failed with {} '{}'".format(
resp.status_code,
resp.json())
try:
deskpro_client.create_ticket(
subject='Request to go live - {}'.format(current_service['name']),
message=(
'On behalf of {} ({})\n'
'\n---'
'\nOrganisation type: {}'
'\nMOU in place: {}'
'\nChannel: {}\nStart date: {}\nStart volume: {}'
'\nPeak volume: {}'
'\nFeatures: {}'
).format(
current_service['name'],
url_for('main.service_dashboard', service_id=current_service['id'], _external=True),
current_service['organisation_type'],
form.mou.data,
formatted_list(filter(None, (
'email' if form.channel_email.data else None,
'text messages' if form.channel_sms.data else None,
'letters' if form.channel_letter.data else None,
)), before_each='', after_each=''),
form.start_date.data,
form.start_volume.data,
form.peak_volume.data,
formatted_list(filter(None, (
'one off' if form.method_one_off.data else None,
'file upload' if form.method_upload.data else None,
'API' if form.method_api.data else None,
)), before_each='', after_each='')
),
user_email=current_user.email_address,
user_name=current_user.name
)
except DeskproError:
abort(500, "Request to go live submission failed")
flash('Weve received your request to go live', 'default')

View File

@@ -71,6 +71,9 @@
<dt>{{ key }}:</dt>
<dd class="api-notifications-item-data-item">{{ notification[key] }}</dd>
{% endfor %}
{% if notification['notification_type'] == 'letter' %}
<a href="{{ url_for('.view_notification', service_id=current_service.id, notification_id=notification.id) }}">View letter</a>
{% endif %}
</dl>
</div>
</details>

View File

@@ -47,11 +47,6 @@
<input type="hidden" name="csrf_token" value="{{ csrf_token() }}"/>
</form>
{% endif %}
<p class="bottom-gutter">
<a href="{{ download_link }}" download="download" class="heading-small">Download this report</a>
&emsp;
Data available for 7 days
</p>
{{ ajax_block(
partials,
url_for('.get_notifications_as_json', service_id=current_service.id, message_type=message_type, status=status, page=page),

View File

@@ -2,7 +2,7 @@
{% from "components/page-footer.html" import page_footer %}
{% block per_page_title %}
Email verification
{{ title }}
{% endblock %}
{% block maincolumn_content %}
@@ -10,7 +10,8 @@
<div class="grid-row">
<div class="column-two-thirds">
<h1 class="heading-large">{{ title }}</h1>
<p> Weve sent you an email with your login link</p>
<p>Weve emailed you a link to sign in to Notify.</p>
<p>Clicking the link will open Notify in a new browser window, so you can close this one.</p>
{{ page_footer(
secondary_link=url_for('main.email_not_received'),
secondary_link_text='Not received an email?'
@@ -18,4 +19,4 @@
</div>
</div>
{% endblock %}
{% endblock %}