2020-07-20 09:27:44 +01:00
|
|
|
from flask import (
|
|
|
|
|
abort,
|
|
|
|
|
flash,
|
|
|
|
|
jsonify,
|
|
|
|
|
redirect,
|
|
|
|
|
render_template,
|
|
|
|
|
request,
|
|
|
|
|
url_for,
|
|
|
|
|
)
|
2020-07-06 10:53:14 +01:00
|
|
|
|
|
|
|
|
from app import current_service
|
|
|
|
|
from app.main import main
|
2020-07-16 10:49:21 +01:00
|
|
|
from app.main.forms import (
|
|
|
|
|
BroadcastAreaForm,
|
2020-07-31 16:20:37 +01:00
|
|
|
BroadcastAreaFormWithSelectAll,
|
2020-11-20 15:42:52 +00:00
|
|
|
BroadcastTemplateForm,
|
|
|
|
|
NewBroadcastForm,
|
2020-07-16 10:49:21 +01:00
|
|
|
SearchByNameForm,
|
|
|
|
|
)
|
2020-07-09 15:48:56 +01:00
|
|
|
from app.models.broadcast_message import BroadcastMessage, BroadcastMessages
|
2020-07-06 10:53:14 +01:00
|
|
|
from app.utils import service_has_permission, user_has_permissions
|
|
|
|
|
|
|
|
|
|
|
2020-08-03 13:37:34 +01:00
|
|
|
@main.route('/services/<uuid:service_id>/broadcast-tour/<int:step_index>')
|
|
|
|
|
@user_has_permissions()
|
|
|
|
|
@service_has_permission('broadcast')
|
|
|
|
|
def broadcast_tour(service_id, step_index):
|
2020-09-21 09:41:19 +01:00
|
|
|
if step_index not in (1, 2, 3, 4, 5, 6):
|
2020-08-03 13:37:34 +01:00
|
|
|
abort(404)
|
|
|
|
|
return render_template(
|
|
|
|
|
f'views/broadcast/tour/{step_index}.html'
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
2020-10-13 11:42:32 +01:00
|
|
|
@main.route('/services/<uuid:service_id>/current-alerts')
|
2020-07-08 11:34:16 +01:00
|
|
|
@user_has_permissions()
|
|
|
|
|
@service_has_permission('broadcast')
|
|
|
|
|
def broadcast_dashboard(service_id):
|
|
|
|
|
return render_template(
|
|
|
|
|
'views/broadcast/dashboard.html',
|
2020-07-17 08:07:40 +01:00
|
|
|
partials=get_broadcast_dashboard_partials(current_service.id),
|
2020-07-14 13:39:29 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
2020-10-13 11:40:20 +01:00
|
|
|
@main.route('/services/<uuid:service_id>/previous-alerts')
|
|
|
|
|
@user_has_permissions()
|
|
|
|
|
@service_has_permission('broadcast')
|
|
|
|
|
def broadcast_dashboard_previous(service_id):
|
|
|
|
|
return render_template(
|
|
|
|
|
'views/broadcast/previous-broadcasts.html',
|
|
|
|
|
broadcasts=BroadcastMessages(service_id).with_status('cancelled', 'completed'),
|
|
|
|
|
empty_message='You do not have any previous alerts',
|
2020-10-26 11:09:13 +00:00
|
|
|
view_broadcast_endpoint='.view_previous_broadcast',
|
2020-10-13 11:40:20 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
2020-07-14 13:39:29 +01:00
|
|
|
@main.route('/services/<uuid:service_id>/broadcast-dashboard.json')
|
|
|
|
|
@user_has_permissions()
|
|
|
|
|
@service_has_permission('broadcast')
|
|
|
|
|
def broadcast_dashboard_updates(service_id):
|
|
|
|
|
return jsonify(get_broadcast_dashboard_partials(current_service.id))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def get_broadcast_dashboard_partials(service_id):
|
|
|
|
|
broadcast_messages = BroadcastMessages(service_id)
|
|
|
|
|
return dict(
|
2020-10-26 11:18:30 +00:00
|
|
|
current_broadcasts=render_template(
|
2020-07-17 08:07:40 +01:00
|
|
|
'views/broadcast/partials/dashboard-table.html',
|
2020-10-26 11:18:30 +00:00
|
|
|
broadcasts=broadcast_messages.with_status('pending-approval', 'broadcasting'),
|
|
|
|
|
empty_message='You do not have any current alerts',
|
2020-10-26 11:09:13 +00:00
|
|
|
view_broadcast_endpoint='.view_current_broadcast',
|
2020-07-14 13:39:29 +01:00
|
|
|
),
|
2020-07-08 11:34:16 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
2020-11-20 15:42:52 +00:00
|
|
|
@main.route('/services/<uuid:service_id>/new-broadcast', methods=['GET', 'POST'])
|
|
|
|
|
@user_has_permissions('send_messages')
|
|
|
|
|
@service_has_permission('broadcast')
|
|
|
|
|
def new_broadcast(service_id):
|
|
|
|
|
form = NewBroadcastForm()
|
|
|
|
|
|
|
|
|
|
if form.validate_on_submit():
|
|
|
|
|
if form.use_template:
|
|
|
|
|
return redirect(url_for(
|
|
|
|
|
'.choose_template',
|
|
|
|
|
service_id=current_service.id,
|
|
|
|
|
))
|
|
|
|
|
return redirect(url_for(
|
|
|
|
|
'.write_new_broadcast',
|
|
|
|
|
service_id=current_service.id,
|
|
|
|
|
))
|
|
|
|
|
|
|
|
|
|
return render_template(
|
|
|
|
|
'views/broadcast/new-broadcast.html',
|
|
|
|
|
form=form,
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@main.route('/services/<uuid:service_id>/write-new-broadcast', methods=['GET', 'POST'])
|
|
|
|
|
@user_has_permissions('send_messages')
|
|
|
|
|
@service_has_permission('broadcast')
|
|
|
|
|
def write_new_broadcast(service_id):
|
|
|
|
|
form = BroadcastTemplateForm()
|
|
|
|
|
|
|
|
|
|
if form.validate_on_submit():
|
|
|
|
|
broadcast_message = BroadcastMessage.create_from_content(
|
|
|
|
|
service_id=current_service.id,
|
|
|
|
|
content=form.template_content.data,
|
|
|
|
|
reference=form.name.data,
|
|
|
|
|
)
|
|
|
|
|
return redirect(url_for(
|
|
|
|
|
'.preview_broadcast_areas',
|
|
|
|
|
service_id=current_service.id,
|
|
|
|
|
broadcast_message_id=broadcast_message.id,
|
|
|
|
|
))
|
|
|
|
|
|
|
|
|
|
return render_template(
|
|
|
|
|
'views/broadcast/write-new-broadcast.html',
|
|
|
|
|
form=form,
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
2020-07-10 14:06:00 +01:00
|
|
|
@main.route('/services/<uuid:service_id>/new-broadcast/<uuid:template_id>')
|
2020-07-06 10:53:14 +01:00
|
|
|
@user_has_permissions('send_messages')
|
|
|
|
|
@service_has_permission('broadcast')
|
2020-07-09 10:33:50 +01:00
|
|
|
def broadcast(service_id, template_id):
|
2020-07-06 10:53:14 +01:00
|
|
|
return redirect(url_for(
|
|
|
|
|
'.preview_broadcast_areas',
|
|
|
|
|
service_id=current_service.id,
|
2020-07-09 10:33:50 +01:00
|
|
|
broadcast_message_id=BroadcastMessage.create(
|
|
|
|
|
service_id=service_id,
|
|
|
|
|
template_id=template_id,
|
|
|
|
|
).id,
|
2020-07-06 10:53:14 +01:00
|
|
|
))
|
|
|
|
|
|
|
|
|
|
|
2020-07-09 10:33:50 +01:00
|
|
|
@main.route('/services/<uuid:service_id>/broadcast/<uuid:broadcast_message_id>/areas')
|
2020-07-06 10:53:14 +01:00
|
|
|
@user_has_permissions('send_messages')
|
|
|
|
|
@service_has_permission('broadcast')
|
2020-07-09 10:33:50 +01:00
|
|
|
def preview_broadcast_areas(service_id, broadcast_message_id):
|
2021-01-15 15:11:43 +00:00
|
|
|
broadcast_message = BroadcastMessage.from_id(
|
|
|
|
|
broadcast_message_id,
|
|
|
|
|
service_id=current_service.id,
|
|
|
|
|
)
|
|
|
|
|
if broadcast_message.template_id:
|
|
|
|
|
back_link = url_for(
|
|
|
|
|
'.view_template',
|
|
|
|
|
service_id=current_service.id,
|
|
|
|
|
template_id=broadcast_message.template_id,
|
|
|
|
|
)
|
|
|
|
|
else:
|
|
|
|
|
back_link = url_for(
|
|
|
|
|
'.write_new_broadcast',
|
|
|
|
|
service_id=current_service.id,
|
|
|
|
|
)
|
|
|
|
|
|
2020-07-06 10:53:14 +01:00
|
|
|
return render_template(
|
|
|
|
|
'views/broadcast/preview-areas.html',
|
2021-01-15 15:11:43 +00:00
|
|
|
broadcast_message=broadcast_message,
|
|
|
|
|
back_link=back_link,
|
2020-07-06 10:53:14 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
2020-07-09 10:33:50 +01:00
|
|
|
@main.route('/services/<uuid:service_id>/broadcast/<uuid:broadcast_message_id>/libraries')
|
2020-07-06 10:53:14 +01:00
|
|
|
@user_has_permissions('send_messages')
|
|
|
|
|
@service_has_permission('broadcast')
|
2020-07-09 10:33:50 +01:00
|
|
|
def choose_broadcast_library(service_id, broadcast_message_id):
|
2020-07-06 10:53:14 +01:00
|
|
|
return render_template(
|
|
|
|
|
'views/broadcast/libraries.html',
|
2020-07-09 10:33:50 +01:00
|
|
|
libraries=BroadcastMessage.libraries,
|
Suggest previously-used areas when adding new area
If you’re adding another area to your broadcast it’s likely to be close
to one of the areas you’ve already added.
But we make you start by choosing a library, then you have to find the
local authority again from the long list. This is clunky, and it
interrupts the task the user is trying to complete.
We thought about redirecting you somewhere deep into the hierarchy,
perhaps by sending you to either:
- the parent of the last area you’d chosen
- the common ancestor of all the areas you’d chosen
This approach would however mean you’d need a way to navigate back up
the hierarchy if we’d dropped you in the wrong place. And we don’t have
a pattern for that at the moment.
So instead this commit adds some ‘shortcuts’ to the chose library page,
giving you a choice of all the parents of the areas you’ve currently
selected. In most cases this will be one (unitary authority) or two
(county and district) choices, but it will scale to adding areas from
multiple different authorities.
It does mean an extra click compared to the redirect approach, but this
is still fewer, easier clicks compared to now.
This meant a couple of under-the-hood changes:
- making `BroadcastArea`s hashable so it’s possible to do
`set([BroadcastArea(…), BroadcastArea(…), BroadcastArea(…)])`
- making `BroadcastArea`s aware of which library they live in, so we can
link to the correct _Choose area_ page
2020-09-21 18:55:46 +01:00
|
|
|
broadcast_message=BroadcastMessage.from_id(
|
|
|
|
|
broadcast_message_id,
|
|
|
|
|
service_id=current_service.id,
|
|
|
|
|
),
|
2020-07-06 10:53:14 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
2020-07-09 10:33:50 +01:00
|
|
|
@main.route(
|
|
|
|
|
'/services/<uuid:service_id>/broadcast/<uuid:broadcast_message_id>/libraries/<library_slug>',
|
|
|
|
|
methods=['GET', 'POST'],
|
|
|
|
|
)
|
2020-07-06 10:53:14 +01:00
|
|
|
@user_has_permissions('send_messages')
|
|
|
|
|
@service_has_permission('broadcast')
|
2020-07-09 10:33:50 +01:00
|
|
|
def choose_broadcast_area(service_id, broadcast_message_id, library_slug):
|
|
|
|
|
broadcast_message = BroadcastMessage.from_id(
|
|
|
|
|
broadcast_message_id,
|
|
|
|
|
service_id=current_service.id,
|
|
|
|
|
)
|
|
|
|
|
library = BroadcastMessage.libraries.get(library_slug)
|
2020-07-31 16:20:37 +01:00
|
|
|
|
|
|
|
|
if library.is_group:
|
|
|
|
|
return render_template(
|
|
|
|
|
'views/broadcast/areas-with-sub-areas.html',
|
|
|
|
|
search_form=SearchByNameForm(),
|
|
|
|
|
show_search_form=(len(library) > 7),
|
|
|
|
|
library=library,
|
2020-08-13 17:33:58 +01:00
|
|
|
page_title=f'Choose a {library.name_singular.lower()}',
|
2020-07-31 16:20:37 +01:00
|
|
|
broadcast_message=broadcast_message,
|
|
|
|
|
)
|
|
|
|
|
|
2020-07-06 10:53:16 +01:00
|
|
|
form = BroadcastAreaForm.from_library(library)
|
|
|
|
|
if form.validate_on_submit():
|
2020-07-09 10:33:50 +01:00
|
|
|
broadcast_message.add_areas(*form.areas.data)
|
2020-07-06 10:53:16 +01:00
|
|
|
return redirect(url_for(
|
|
|
|
|
'.preview_broadcast_areas',
|
|
|
|
|
service_id=current_service.id,
|
2020-07-09 10:33:50 +01:00
|
|
|
broadcast_message_id=broadcast_message.id,
|
2020-07-06 10:53:16 +01:00
|
|
|
))
|
2020-07-06 10:53:14 +01:00
|
|
|
return render_template(
|
|
|
|
|
'views/broadcast/areas.html',
|
2020-07-06 10:53:16 +01:00
|
|
|
form=form,
|
2020-07-06 10:53:16 +01:00
|
|
|
search_form=SearchByNameForm(),
|
|
|
|
|
show_search_form=(len(form.areas.choices) > 7),
|
2020-08-13 17:33:58 +01:00
|
|
|
page_title=f'Choose {library.name.lower()}',
|
2020-07-10 09:25:17 +01:00
|
|
|
broadcast_message=broadcast_message,
|
2020-07-06 10:53:14 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
2020-09-15 13:53:38 +01:00
|
|
|
def _get_broadcast_sub_area_back_link(service_id, broadcast_message_id, library_slug):
|
|
|
|
|
prev_area_slug = request.args.get('prev_area_slug')
|
|
|
|
|
if prev_area_slug:
|
|
|
|
|
return url_for(
|
|
|
|
|
'.choose_broadcast_sub_area',
|
|
|
|
|
service_id=service_id,
|
|
|
|
|
broadcast_message_id=broadcast_message_id,
|
|
|
|
|
library_slug=library_slug,
|
|
|
|
|
area_slug=prev_area_slug,
|
|
|
|
|
)
|
|
|
|
|
else:
|
|
|
|
|
return url_for(
|
|
|
|
|
'.choose_broadcast_area',
|
|
|
|
|
service_id=service_id,
|
|
|
|
|
broadcast_message_id=broadcast_message_id,
|
|
|
|
|
library_slug=library_slug,
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
2020-07-31 16:20:37 +01:00
|
|
|
@main.route(
|
|
|
|
|
'/services/<uuid:service_id>/broadcast/<uuid:broadcast_message_id>/libraries/<library_slug>/<area_slug>',
|
|
|
|
|
methods=['GET', 'POST'],
|
|
|
|
|
)
|
|
|
|
|
@user_has_permissions('send_messages')
|
|
|
|
|
@service_has_permission('broadcast')
|
|
|
|
|
def choose_broadcast_sub_area(service_id, broadcast_message_id, library_slug, area_slug):
|
|
|
|
|
broadcast_message = BroadcastMessage.from_id(
|
|
|
|
|
broadcast_message_id,
|
|
|
|
|
service_id=current_service.id,
|
|
|
|
|
)
|
|
|
|
|
area = BroadcastMessage.libraries.get_areas(area_slug)[0]
|
|
|
|
|
|
2020-09-15 13:53:38 +01:00
|
|
|
back_link = _get_broadcast_sub_area_back_link(service_id, broadcast_message_id, library_slug)
|
|
|
|
|
|
add counties page
What was previously ward -> local authority is now a ward -> local
authority -> county. County only covers rural counties and not
metropolitan boroughs and other unitary authorities. Previously, there
was a page full of local authorities (unitary authorities and
districts), and each one of those would have a list of electoral wards.
However, now there are counties that contain a list of districts - so
this needs a new page - a checkbox for "select the county" and then a
list of links to district pages.
If you want to select multiple districts, you'll need to go into each
one of those sub-sections in turn and click select all.
Needed to tweak the query to retrieve the list of areas in a list for a
library. Previously, it just returned anything at top level (ie: didn't
have a parent). However, rural districts now have parents (the rural
counties themselves). So the query now returns "everything that isn't a
leaf node", or in more specific terms, everything that has at least
other row referring to it as a parent. So no electoral wards, since
they dont have any children, but yes to districts and counties.
2020-09-04 15:22:32 +01:00
|
|
|
is_county = any(sub_area.sub_areas for sub_area in area.sub_areas)
|
|
|
|
|
|
2020-07-31 16:20:37 +01:00
|
|
|
form = BroadcastAreaFormWithSelectAll.from_library(
|
add counties page
What was previously ward -> local authority is now a ward -> local
authority -> county. County only covers rural counties and not
metropolitan boroughs and other unitary authorities. Previously, there
was a page full of local authorities (unitary authorities and
districts), and each one of those would have a list of electoral wards.
However, now there are counties that contain a list of districts - so
this needs a new page - a checkbox for "select the county" and then a
list of links to district pages.
If you want to select multiple districts, you'll need to go into each
one of those sub-sections in turn and click select all.
Needed to tweak the query to retrieve the list of areas in a list for a
library. Previously, it just returned anything at top level (ie: didn't
have a parent). However, rural districts now have parents (the rural
counties themselves). So the query now returns "everything that isn't a
leaf node", or in more specific terms, everything that has at least
other row referring to it as a parent. So no electoral wards, since
they dont have any children, but yes to districts and counties.
2020-09-04 15:22:32 +01:00
|
|
|
[] if is_county else area.sub_areas,
|
2020-07-31 16:20:37 +01:00
|
|
|
select_all_choice=(area.id, f'All of {area.name}'),
|
|
|
|
|
)
|
|
|
|
|
if form.validate_on_submit():
|
|
|
|
|
broadcast_message.add_areas(*form.selected_areas)
|
|
|
|
|
return redirect(url_for(
|
|
|
|
|
'.preview_broadcast_areas',
|
|
|
|
|
service_id=current_service.id,
|
|
|
|
|
broadcast_message_id=broadcast_message.id,
|
|
|
|
|
))
|
add counties page
What was previously ward -> local authority is now a ward -> local
authority -> county. County only covers rural counties and not
metropolitan boroughs and other unitary authorities. Previously, there
was a page full of local authorities (unitary authorities and
districts), and each one of those would have a list of electoral wards.
However, now there are counties that contain a list of districts - so
this needs a new page - a checkbox for "select the county" and then a
list of links to district pages.
If you want to select multiple districts, you'll need to go into each
one of those sub-sections in turn and click select all.
Needed to tweak the query to retrieve the list of areas in a list for a
library. Previously, it just returned anything at top level (ie: didn't
have a parent). However, rural districts now have parents (the rural
counties themselves). So the query now returns "everything that isn't a
leaf node", or in more specific terms, everything that has at least
other row referring to it as a parent. So no electoral wards, since
they dont have any children, but yes to districts and counties.
2020-09-04 15:22:32 +01:00
|
|
|
|
|
|
|
|
if is_county:
|
|
|
|
|
# area = county. sub_areas = districts. they have wards, so link to individual district pages
|
|
|
|
|
return render_template(
|
|
|
|
|
'views/broadcast/counties.html',
|
|
|
|
|
form=form,
|
|
|
|
|
search_form=SearchByNameForm(),
|
|
|
|
|
show_search_form=(len(area.sub_areas) > 7),
|
|
|
|
|
library_slug=library_slug,
|
|
|
|
|
page_title=f'Choose an area of {area.name}',
|
|
|
|
|
broadcast_message=broadcast_message,
|
|
|
|
|
county=area,
|
2020-09-15 13:53:38 +01:00
|
|
|
back_link=back_link,
|
add counties page
What was previously ward -> local authority is now a ward -> local
authority -> county. County only covers rural counties and not
metropolitan boroughs and other unitary authorities. Previously, there
was a page full of local authorities (unitary authorities and
districts), and each one of those would have a list of electoral wards.
However, now there are counties that contain a list of districts - so
this needs a new page - a checkbox for "select the county" and then a
list of links to district pages.
If you want to select multiple districts, you'll need to go into each
one of those sub-sections in turn and click select all.
Needed to tweak the query to retrieve the list of areas in a list for a
library. Previously, it just returned anything at top level (ie: didn't
have a parent). However, rural districts now have parents (the rural
counties themselves). So the query now returns "everything that isn't a
leaf node", or in more specific terms, everything that has at least
other row referring to it as a parent. So no electoral wards, since
they dont have any children, but yes to districts and counties.
2020-09-04 15:22:32 +01:00
|
|
|
)
|
|
|
|
|
|
2020-07-31 16:20:37 +01:00
|
|
|
return render_template(
|
|
|
|
|
'views/broadcast/sub-areas.html',
|
|
|
|
|
form=form,
|
|
|
|
|
search_form=SearchByNameForm(),
|
|
|
|
|
show_search_form=(len(form.areas.choices) > 7),
|
|
|
|
|
library_slug=library_slug,
|
|
|
|
|
page_title=f'Choose an area of {area.name}',
|
|
|
|
|
broadcast_message=broadcast_message,
|
2020-09-15 13:53:38 +01:00
|
|
|
back_link=back_link,
|
2020-07-31 16:20:37 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
2020-07-09 10:33:50 +01:00
|
|
|
@main.route('/services/<uuid:service_id>/broadcast/<uuid:broadcast_message_id>/remove/<area_slug>')
|
2020-07-06 10:53:14 +01:00
|
|
|
@user_has_permissions('send_messages')
|
|
|
|
|
@service_has_permission('broadcast')
|
2020-07-09 10:33:50 +01:00
|
|
|
def remove_broadcast_area(service_id, broadcast_message_id, area_slug):
|
|
|
|
|
BroadcastMessage.from_id(
|
|
|
|
|
broadcast_message_id,
|
|
|
|
|
service_id=current_service.id,
|
|
|
|
|
).remove_area(
|
|
|
|
|
area_slug
|
|
|
|
|
)
|
2020-07-06 10:53:14 +01:00
|
|
|
return redirect(url_for(
|
|
|
|
|
'.preview_broadcast_areas',
|
|
|
|
|
service_id=current_service.id,
|
2020-07-09 10:33:50 +01:00
|
|
|
broadcast_message_id=broadcast_message_id,
|
2020-07-06 10:53:14 +01:00
|
|
|
))
|
|
|
|
|
|
|
|
|
|
|
2020-07-09 10:33:50 +01:00
|
|
|
@main.route(
|
|
|
|
|
'/services/<uuid:service_id>/broadcast/<uuid:broadcast_message_id>/preview',
|
|
|
|
|
methods=['GET', 'POST'],
|
|
|
|
|
)
|
2020-07-06 10:53:14 +01:00
|
|
|
@user_has_permissions('send_messages')
|
|
|
|
|
@service_has_permission('broadcast')
|
2020-07-09 10:33:50 +01:00
|
|
|
def preview_broadcast_message(service_id, broadcast_message_id):
|
|
|
|
|
broadcast_message = BroadcastMessage.from_id(
|
|
|
|
|
broadcast_message_id,
|
|
|
|
|
service_id=current_service.id,
|
|
|
|
|
)
|
2020-08-18 16:36:40 +01:00
|
|
|
if request.method == 'POST':
|
|
|
|
|
broadcast_message.request_approval()
|
2020-07-09 10:33:50 +01:00
|
|
|
return redirect(url_for(
|
2020-10-15 13:15:22 +01:00
|
|
|
'.view_current_broadcast',
|
2020-07-09 10:33:50 +01:00
|
|
|
service_id=current_service.id,
|
2020-08-03 15:46:23 +01:00
|
|
|
broadcast_message_id=broadcast_message.id,
|
2020-07-09 10:33:50 +01:00
|
|
|
))
|
2020-07-16 10:49:21 +01:00
|
|
|
|
2020-07-06 10:53:14 +01:00
|
|
|
return render_template(
|
|
|
|
|
'views/broadcast/preview-message.html',
|
2020-07-09 10:33:50 +01:00
|
|
|
broadcast_message=broadcast_message,
|
2020-07-06 10:53:14 +01:00
|
|
|
)
|
2020-07-10 09:16:36 +01:00
|
|
|
|
|
|
|
|
|
2020-10-15 13:15:22 +01:00
|
|
|
@main.route(
|
|
|
|
|
'/services/<uuid:service_id>/current-alerts/<uuid:broadcast_message_id>',
|
|
|
|
|
endpoint='view_current_broadcast',
|
|
|
|
|
)
|
|
|
|
|
@main.route(
|
|
|
|
|
'/services/<uuid:service_id>/previous-alerts/<uuid:broadcast_message_id>',
|
|
|
|
|
endpoint='view_previous_broadcast',
|
|
|
|
|
)
|
2020-08-10 12:13:11 +01:00
|
|
|
@user_has_permissions()
|
2020-07-10 14:06:00 +01:00
|
|
|
@service_has_permission('broadcast')
|
2020-10-15 13:15:22 +01:00
|
|
|
def view_broadcast(service_id, broadcast_message_id):
|
2020-07-10 14:06:00 +01:00
|
|
|
broadcast_message = BroadcastMessage.from_id(
|
|
|
|
|
broadcast_message_id,
|
|
|
|
|
service_id=current_service.id,
|
|
|
|
|
)
|
|
|
|
|
if broadcast_message.status == 'draft':
|
|
|
|
|
abort(404)
|
2020-10-15 13:24:57 +01:00
|
|
|
|
|
|
|
|
if (
|
|
|
|
|
broadcast_message.status in {'completed', 'cancelled', 'rejected'}
|
|
|
|
|
and request.endpoint != 'main.view_previous_broadcast'
|
|
|
|
|
):
|
|
|
|
|
return redirect(url_for(
|
|
|
|
|
'.view_previous_broadcast',
|
|
|
|
|
service_id=current_service.id,
|
|
|
|
|
broadcast_message_id=broadcast_message.id,
|
|
|
|
|
))
|
|
|
|
|
|
|
|
|
|
if (
|
|
|
|
|
broadcast_message.status in {'broadcasting', 'pending-approval'}
|
|
|
|
|
and request.endpoint != 'main.view_current_broadcast'
|
|
|
|
|
):
|
|
|
|
|
return redirect(url_for(
|
|
|
|
|
'.view_current_broadcast',
|
|
|
|
|
service_id=current_service.id,
|
|
|
|
|
broadcast_message_id=broadcast_message.id,
|
|
|
|
|
))
|
|
|
|
|
|
|
|
|
|
back_link_endpoint = {
|
|
|
|
|
'main.view_current_broadcast': '.broadcast_dashboard',
|
|
|
|
|
'main.view_previous_broadcast': '.broadcast_dashboard_previous',
|
|
|
|
|
}[request.endpoint]
|
|
|
|
|
|
2020-07-10 14:06:00 +01:00
|
|
|
return render_template(
|
|
|
|
|
'views/broadcast/view-message.html',
|
|
|
|
|
broadcast_message=broadcast_message,
|
2020-10-15 13:24:57 +01:00
|
|
|
back_link=url_for(
|
|
|
|
|
back_link_endpoint,
|
|
|
|
|
service_id=current_service.id,
|
|
|
|
|
),
|
2020-07-10 14:06:00 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
2020-10-15 13:15:22 +01:00
|
|
|
@main.route('/services/<uuid:service_id>/current-alerts/<uuid:broadcast_message_id>', methods=['POST'])
|
2020-07-17 08:07:44 +01:00
|
|
|
@user_has_permissions('send_messages')
|
|
|
|
|
@service_has_permission('broadcast')
|
|
|
|
|
def approve_broadcast_message(service_id, broadcast_message_id):
|
|
|
|
|
|
|
|
|
|
broadcast_message = BroadcastMessage.from_id(
|
|
|
|
|
broadcast_message_id,
|
|
|
|
|
service_id=current_service.id,
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
if broadcast_message.status != 'pending-approval':
|
|
|
|
|
return redirect(url_for(
|
2020-10-15 13:15:22 +01:00
|
|
|
'.view_current_broadcast',
|
2020-07-17 08:07:44 +01:00
|
|
|
service_id=current_service.id,
|
|
|
|
|
broadcast_message_id=broadcast_message.id,
|
|
|
|
|
))
|
|
|
|
|
|
|
|
|
|
broadcast_message.approve_broadcast()
|
|
|
|
|
|
2020-09-21 09:41:19 +01:00
|
|
|
if current_service.trial_mode:
|
|
|
|
|
return redirect(url_for(
|
|
|
|
|
'.broadcast_tour',
|
|
|
|
|
service_id=current_service.id,
|
|
|
|
|
step_index=6,
|
|
|
|
|
))
|
|
|
|
|
|
2020-07-17 08:07:44 +01:00
|
|
|
return redirect(url_for(
|
2020-10-15 13:15:22 +01:00
|
|
|
'.view_current_broadcast',
|
2020-07-17 08:07:44 +01:00
|
|
|
service_id=current_service.id,
|
|
|
|
|
broadcast_message_id=broadcast_message.id,
|
|
|
|
|
))
|
|
|
|
|
|
|
|
|
|
|
2020-07-17 08:07:44 +01:00
|
|
|
@main.route('/services/<uuid:service_id>/broadcast/<uuid:broadcast_message_id>/reject')
|
|
|
|
|
@user_has_permissions('send_messages')
|
|
|
|
|
@service_has_permission('broadcast')
|
|
|
|
|
def reject_broadcast_message(service_id, broadcast_message_id):
|
|
|
|
|
|
|
|
|
|
broadcast_message = BroadcastMessage.from_id(
|
|
|
|
|
broadcast_message_id,
|
|
|
|
|
service_id=current_service.id,
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
if broadcast_message.status != 'pending-approval':
|
|
|
|
|
return redirect(url_for(
|
2020-10-15 13:15:22 +01:00
|
|
|
'.view_current_broadcast',
|
2020-07-17 08:07:44 +01:00
|
|
|
service_id=current_service.id,
|
|
|
|
|
broadcast_message_id=broadcast_message.id,
|
|
|
|
|
))
|
|
|
|
|
|
|
|
|
|
broadcast_message.reject_broadcast()
|
|
|
|
|
|
|
|
|
|
return redirect(url_for(
|
|
|
|
|
'.broadcast_dashboard',
|
|
|
|
|
service_id=current_service.id,
|
|
|
|
|
))
|
|
|
|
|
|
|
|
|
|
|
2020-07-20 09:27:44 +01:00
|
|
|
@main.route(
|
|
|
|
|
'/services/<uuid:service_id>/broadcast/<uuid:broadcast_message_id>/cancel',
|
|
|
|
|
methods=['GET', 'POST'],
|
|
|
|
|
)
|
2020-07-10 09:16:36 +01:00
|
|
|
@user_has_permissions('send_messages')
|
|
|
|
|
@service_has_permission('broadcast')
|
|
|
|
|
def cancel_broadcast_message(service_id, broadcast_message_id):
|
2020-07-20 09:27:44 +01:00
|
|
|
broadcast_message = BroadcastMessage.from_id(
|
2020-07-10 09:16:36 +01:00
|
|
|
broadcast_message_id,
|
|
|
|
|
service_id=current_service.id,
|
2020-07-20 09:27:44 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
|
|
if broadcast_message.status != 'broadcasting':
|
|
|
|
|
return redirect(url_for(
|
2020-10-15 13:15:22 +01:00
|
|
|
'.view_current_broadcast',
|
2020-07-20 09:27:44 +01:00
|
|
|
service_id=current_service.id,
|
|
|
|
|
broadcast_message_id=broadcast_message.id,
|
|
|
|
|
))
|
|
|
|
|
|
|
|
|
|
if request.method == 'POST':
|
|
|
|
|
broadcast_message.cancel_broadcast()
|
|
|
|
|
return redirect(url_for(
|
2020-10-15 13:15:22 +01:00
|
|
|
'.view_previous_broadcast',
|
2020-07-20 09:27:44 +01:00
|
|
|
service_id=current_service.id,
|
|
|
|
|
broadcast_message_id=broadcast_message.id,
|
|
|
|
|
))
|
|
|
|
|
|
|
|
|
|
flash([
|
|
|
|
|
'Are you sure you want to stop this broadcast now?'
|
|
|
|
|
], 'stop broadcasting')
|
|
|
|
|
|
|
|
|
|
return render_template(
|
|
|
|
|
'views/broadcast/view-message.html',
|
|
|
|
|
broadcast_message=broadcast_message,
|
|
|
|
|
hide_stop_link=True,
|
|
|
|
|
)
|