mirror of
https://github.com/GSA/notifications-admin.git
synced 2026-02-06 03:13:42 -05:00
Put a form on the request to go live page
This commit: - moves things around a bit on the request to go live page - sticks a textbox in there So when someone click the big green button, we will get a support ticket that looks something like: ``` From Test User <test@user.gov.uk> on behalf of Test Service (6ce466d0-fd6a-11e5-82f5-e0accb9d11a6) --- We’ll send about 1000 text messages in the first month, and then 10,000 text messages per month after that. Usage of our service is about 50% higher in March, at the end of the tax year. ```
This commit is contained in:
@@ -313,3 +313,10 @@ class Feedback(Form):
|
||||
name = StringField('Name')
|
||||
email_address = StringField('Email address')
|
||||
feedback = TextAreaField(u'', validators=[DataRequired(message="Can’t be empty")])
|
||||
|
||||
|
||||
class RequestToGoLiveForm(Form):
|
||||
usage = TextAreaField(
|
||||
'',
|
||||
validators=[DataRequired(message="Can’t be empty")]
|
||||
)
|
||||
|
||||
@@ -39,4 +39,4 @@ def feedback():
|
||||
flash("Your feedback has been submitted")
|
||||
return redirect(url_for('.feedback'))
|
||||
|
||||
return render_template('views/feedback.html', form=form)
|
||||
return render_template('views/feedback.html', form=form)
|
||||
|
||||
@@ -1,10 +1,13 @@
|
||||
import requests
|
||||
from flask import (
|
||||
render_template,
|
||||
redirect,
|
||||
request,
|
||||
url_for,
|
||||
session,
|
||||
flash
|
||||
flash,
|
||||
abort,
|
||||
current_app
|
||||
)
|
||||
|
||||
from flask_login import (
|
||||
@@ -16,7 +19,7 @@ from notifications_python_client.errors import HTTPError
|
||||
from app import service_api_client
|
||||
from app.main import main
|
||||
from app.utils import user_has_permissions, email_safe
|
||||
from app.main.forms import ConfirmPasswordForm, ServiceNameForm
|
||||
from app.main.forms import ConfirmPasswordForm, ServiceNameForm, RequestToGoLiveForm
|
||||
from app import user_api_client
|
||||
from app import current_service
|
||||
|
||||
@@ -86,15 +89,45 @@ def service_name_change_confirm(service_id):
|
||||
@login_required
|
||||
@user_has_permissions('manage_settings', admin_override=True)
|
||||
def service_request_to_go_live(service_id):
|
||||
if request.method == 'GET':
|
||||
return render_template(
|
||||
'views/service-settings/request-to-go-live.html'
|
||||
|
||||
form = RequestToGoLiveForm()
|
||||
|
||||
if form.validate_on_submit():
|
||||
|
||||
data = {
|
||||
'person_email': current_app.config.get('DESKPRO_PERSON_EMAIL'),
|
||||
'department_id': current_app.config.get('DESKPRO_TEAM_ID'),
|
||||
'subject': 'Request to go live',
|
||||
'message': "From {} <{}> on behalf of {} ({})\n\nUsage estimate\n---\n\n{}".format(
|
||||
current_user.name,
|
||||
current_user.email_address,
|
||||
current_service['name'],
|
||||
current_service['id'],
|
||||
form.usage.data
|
||||
)
|
||||
}
|
||||
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
|
||||
)
|
||||
elif request.method == 'POST':
|
||||
flash('Thanks your request to go live is being processed', 'default')
|
||||
# TODO implement whatever this action would do in the real world
|
||||
if resp.status_code != 201:
|
||||
current_app.logger.error(
|
||||
"Deskpro create ticket request failed with {} '{}'".format(
|
||||
resp.status_code,
|
||||
resp.json())
|
||||
)
|
||||
abort(500, "Request to go live submission failed")
|
||||
|
||||
flash('We’ve received your request to go live', 'default')
|
||||
return redirect(url_for('.service_settings', service_id=service_id))
|
||||
|
||||
return render_template('views/service-settings/request-to-go-live.html', form=form)
|
||||
|
||||
|
||||
@main.route("/services/<service_id>/service-settings/switch-live")
|
||||
@login_required
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
{% macro textbox(
|
||||
field,
|
||||
label=None,
|
||||
hint=False,
|
||||
highlight_tags=False,
|
||||
autofocus=False,
|
||||
@@ -12,7 +13,11 @@
|
||||
) %}
|
||||
<div class="form-group{% if field.errors %} error{% endif %}" {% if autofocus %}data-module="autofocus"{% endif %}>
|
||||
<label class="form-label" for="{{ field.name }}">
|
||||
{{ field.label }}
|
||||
{% if label %}
|
||||
{{ label }}
|
||||
{% else %}
|
||||
{{ field.label }}
|
||||
{% endif %}
|
||||
{% if hint %}
|
||||
<span class="form-hint">
|
||||
{{ hint }}
|
||||
|
||||
@@ -15,7 +15,7 @@
|
||||
'link': url_for('.service_name_change', service_id=current_service.id)
|
||||
},
|
||||
{
|
||||
'title': 'Request to go live and turn off sending restrictions',
|
||||
'title': 'Request to go live and turn off trial mode',
|
||||
'link': url_for('.service_request_to_go_live', service_id=current_service.id),
|
||||
'hint': 'A live service can send notifications to any phone number or email address',
|
||||
} if current_service.restricted else {
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
{% extends "withnav_template.html" %}
|
||||
{% from "components/textbox.html" import textbox %}
|
||||
{% from "components/page-footer.html" import page_footer %}
|
||||
|
||||
{% block page_title %}
|
||||
@@ -10,17 +11,54 @@
|
||||
<div class="grid-row">
|
||||
<div class="column-three-quarters">
|
||||
|
||||
<h1 class="heading-large">Request to go live</h1>
|
||||
<h1 class="heading-large">Request to go live</h1>
|
||||
|
||||
<p>GOV.UK Notify is invite-only during the beta.</p>
|
||||
<p>
|
||||
You’ll need to:
|
||||
</p>
|
||||
<ul class="list list-bullet">
|
||||
<li>
|
||||
agree to our <a href="{{ url_for('.terms') }}">terms of use</a>
|
||||
</li>
|
||||
<li>
|
||||
agree to pay for what you use if you send more than 250,000 text messages per year
|
||||
(<a href="{{ url_for("main.pricing") }}">see our pricing</a>)
|
||||
</li>
|
||||
</ul>
|
||||
|
||||
<p><a href="{{ url_for('main.feedback') }}">Contact us</a> to request an invite:</p>
|
||||
<form method="post">
|
||||
|
||||
<ul class="list list-bullet">
|
||||
<li>You’ll need to agree to our terms of use</li>
|
||||
<li>If you plan to send more than 250,000 text messages per year, you’ll need to agree to pay for what you use – take a look at our <a href="{{ url_for("main.pricing") }}">pricing</a></li>
|
||||
<li>We’ll check your templates to make sure they’re consistent with our design patterns, style guide and information security principles</li>
|
||||
</ul>
|
||||
{{ textbox(
|
||||
form.usage,
|
||||
label='Estimate how many notifications you’ll send each month',
|
||||
hint='If your estimate is likely to change, tell us how ',
|
||||
width='1-1',
|
||||
rows=5
|
||||
) }}
|
||||
|
||||
<p>
|
||||
We will:
|
||||
</p>
|
||||
<ul class="list list-bullet">
|
||||
<li>
|
||||
check that your templates follow our
|
||||
<a href="https://designpatterns.hackpad.com/Notifications-5vuitmNqIjZ" rel="external">design patterns</a>,
|
||||
<a href="https://www.gov.uk/topic/government-digital-guidance/content-publishing" rel="external">style guide</a>
|
||||
and
|
||||
<a href="https://docs.google.com/document/d/15-OjaEqDBy31uDU7nLZCpYIQOnzSCJR63-cp3cQI9G8" rel="external">information security guidelines</a>
|
||||
</li>
|
||||
<li>
|
||||
check that you have more than one
|
||||
<a href="{{ url_for('main.manage_users', service_id=current_service.id) }}">team member</a>
|
||||
in case you go on holiday
|
||||
</li>
|
||||
<li>
|
||||
make your service live or get back to you within one working day
|
||||
</li>
|
||||
</ul>
|
||||
|
||||
{{ page_footer('Request to go live') }}
|
||||
</form>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -1,10 +1,12 @@
|
||||
import pytest
|
||||
from flask import url_for
|
||||
|
||||
import app
|
||||
from app.utils import email_safe
|
||||
from tests import validate_route_permission
|
||||
from bs4 import BeautifulSoup
|
||||
from unittest.mock import ANY
|
||||
from unittest.mock import ANY, Mock
|
||||
from werkzeug.exceptions import InternalServerError
|
||||
|
||||
|
||||
def test_should_show_overview(app_,
|
||||
@@ -212,36 +214,74 @@ def test_should_show_request_to_go_live(app_,
|
||||
assert mock_get_service.called
|
||||
|
||||
|
||||
def test_should_redirect_after_request_to_go_live(app_,
|
||||
api_user_active,
|
||||
mock_get_service,
|
||||
mock_get_user,
|
||||
mock_get_user_by_email,
|
||||
mock_login,
|
||||
mock_has_permissions,
|
||||
fake_uuid):
|
||||
def test_should_redirect_after_request_to_go_live(
|
||||
app_,
|
||||
api_user_active,
|
||||
mock_get_user,
|
||||
mock_get_service,
|
||||
mock_has_permissions,
|
||||
mocker
|
||||
):
|
||||
mock_post = mocker.patch(
|
||||
'app.main.views.feedback.requests.post',
|
||||
return_value=Mock(status_code=201))
|
||||
with app_.test_request_context():
|
||||
with app_.test_client() as client:
|
||||
client.login(api_user_active)
|
||||
service_id = fake_uuid
|
||||
response = client.post(url_for(
|
||||
'main.service_request_to_go_live', service_id=service_id))
|
||||
|
||||
assert response.status_code == 302
|
||||
settings_url = url_for(
|
||||
'main.service_settings', service_id=service_id, _external=True)
|
||||
assert settings_url == response.location
|
||||
assert mock_get_service.called
|
||||
|
||||
with app_.test_client() as client:
|
||||
client.login(api_user_active)
|
||||
service_id = fake_uuid
|
||||
response = client.post(url_for(
|
||||
'main.service_request_to_go_live', service_id=service_id), follow_redirects=True)
|
||||
response = client.post(
|
||||
url_for('main.service_request_to_go_live', service_id='6ce466d0-fd6a-11e5-82f5-e0accb9d11a6'),
|
||||
data={'usage': "One million messages"},
|
||||
follow_redirects=True
|
||||
)
|
||||
assert response.status_code == 200
|
||||
mock_post.assert_called_with(
|
||||
ANY,
|
||||
data={
|
||||
'subject': 'Request to go live',
|
||||
'department_id': ANY,
|
||||
'message': 'From Test User <test@user.gov.uk> on behalf of Test Service (6ce466d0-fd6a-11e5-82f5-e0accb9d11a6)\n\nUsage estimate\n---\n\nOne million messages', # noqa
|
||||
'person_email': ANY
|
||||
},
|
||||
headers=ANY
|
||||
)
|
||||
|
||||
page = BeautifulSoup(response.data.decode('utf-8'), 'html.parser')
|
||||
flash_banner = page.find('div', class_='banner-default').string.strip()
|
||||
assert flash_banner == 'Thanks your request to go live is being processed'
|
||||
h1 = page.find('h1').string.strip()
|
||||
assert flash_banner == 'We’ve received your request to go live'
|
||||
assert h1 == 'Settings'
|
||||
|
||||
|
||||
def test_log_error_on_request_to_go_live(
|
||||
app_,
|
||||
api_user_active,
|
||||
mock_get_user,
|
||||
mock_get_service,
|
||||
mock_has_permissions,
|
||||
mocker
|
||||
):
|
||||
mock_post = mocker.patch(
|
||||
'app.main.views.service_settings.requests.post',
|
||||
return_value=Mock(
|
||||
status_code=401,
|
||||
json=lambda: {
|
||||
'error_code': 'invalid_auth',
|
||||
'error_message': 'Please provide a valid API key or token'
|
||||
}
|
||||
)
|
||||
)
|
||||
with app_.test_request_context():
|
||||
mock_logger = mocker.patch.object(app_.logger, 'error')
|
||||
with app_.test_client() as client:
|
||||
client.login(api_user_active)
|
||||
with pytest.raises(InternalServerError):
|
||||
resp = client.post(
|
||||
url_for('main.service_request_to_go_live', service_id='6ce466d0-fd6a-11e5-82f5-e0accb9d11a6'),
|
||||
data={'usage': 'blah'}
|
||||
)
|
||||
mock_logger.assert_called_with(
|
||||
"Deskpro create ticket request failed with {} '{}'".format(mock_post().status_code, mock_post().json())
|
||||
)
|
||||
|
||||
|
||||
def test_should_show_status_page(app_,
|
||||
|
||||
Reference in New Issue
Block a user