mirror of
https://github.com/GSA/notifications-admin.git
synced 2026-07-10 03:14:58 -04:00
_The code for this is quite hacky and light on tests. But I’d really like to get it in the app for the research tomorrow to see how well the feature works._ This commit changes the tour from being a set of static screens to some help which guides you through the process of sending your first test message. The theory behind this is that what users are really struggling with is the concept of a variable, rather than the relationship between the placeholders and the column headers. And like learning to program, the best way to learn is by taking an example and modifying it to your own needs. This means that when someone adds their first service we set them up an example email template and an example text message template. Then there is a guided, three step process where _all_ the user can do is send a test message to themselves. Once the message is sent, the user still has the example templates which they can edit, rather than having to remember what they’re supposed to be doing.
76 lines
2.8 KiB
Python
76 lines
2.8 KiB
Python
from flask import (
|
||
render_template,
|
||
redirect,
|
||
session,
|
||
url_for,
|
||
current_app)
|
||
|
||
from flask_login import login_required
|
||
|
||
from app.main import main
|
||
from app.main.forms import AddServiceForm
|
||
from app.notify_client.models import InvitedUser
|
||
|
||
from app import (
|
||
invite_api_client,
|
||
user_api_client,
|
||
service_api_client
|
||
)
|
||
from app.utils import email_safe
|
||
|
||
|
||
@main.route("/add-service", methods=['GET', 'POST'])
|
||
@login_required
|
||
def add_service():
|
||
invited_user = session.get('invited_user')
|
||
if invited_user:
|
||
invitation = InvitedUser(**invited_user)
|
||
# if invited user add to service and redirect to dashboard
|
||
user = user_api_client.get_user(session['user_id'])
|
||
service_id = invited_user['service']
|
||
user_api_client.add_user_to_service(service_id, user.id, invitation.permissions)
|
||
invite_api_client.accept_invite(service_id, invitation.id)
|
||
return redirect(url_for('main.service_dashboard', service_id=service_id))
|
||
|
||
form = AddServiceForm(service_api_client.find_all_service_email_from)
|
||
heading = 'Which service do you want to set up notifications for?'
|
||
if form.validate_on_submit():
|
||
email_from = email_safe(form.name.data)
|
||
service_id = service_api_client.create_service(service_name=form.name.data,
|
||
active=False,
|
||
message_limit=current_app.config['DEFAULT_SERVICE_LIMIT'],
|
||
restricted=True,
|
||
user_id=session['user_id'],
|
||
email_from=email_from)
|
||
session['service_id'] = service_id
|
||
|
||
if (len(service_api_client.get_services({'user_id': session['user_id']}).get('data', [])) > 1):
|
||
return redirect(url_for('main.service_dashboard', service_id=service_id))
|
||
|
||
example_sms_template = service_api_client.create_service_template(
|
||
'Example text message template',
|
||
'sms',
|
||
'Hey ((name)), I’m trying out Notify. Today is ((day of week)) and my favourite colour is ((colour)).',
|
||
service_id
|
||
)
|
||
example_email_template = service_api_client.create_service_template(
|
||
'Example email template',
|
||
'email',
|
||
'Hey ((name)),\n\nI’m trying out Notify. Today is ((day of week)) and my favourite colour is ((colour)).',
|
||
service_id,
|
||
'Trying out Notify'
|
||
)
|
||
|
||
return redirect(url_for(
|
||
'main.send_test',
|
||
service_id=service_id,
|
||
template_id=example_sms_template['data']['id'],
|
||
help=1
|
||
))
|
||
else:
|
||
return render_template(
|
||
'views/add-service.html',
|
||
form=form,
|
||
heading=heading
|
||
)
|