2019-02-18 16:56:43 +00:00
|
|
|
|
from collections import OrderedDict
|
2019-05-16 17:05:55 +01:00
|
|
|
|
from datetime import datetime
|
2018-08-30 10:46:13 +01:00
|
|
|
|
|
2016-01-18 17:35:28 +00:00
|
|
|
|
from flask import (
|
2018-02-20 11:22:17 +00:00
|
|
|
|
abort,
|
2018-03-02 10:48:59 +00:00
|
|
|
|
current_app,
|
2018-02-20 11:22:17 +00:00
|
|
|
|
flash,
|
2019-05-14 17:53:00 +01:00
|
|
|
|
jsonify,
|
2016-03-09 14:30:50 +00:00
|
|
|
|
redirect,
|
2018-02-20 11:22:17 +00:00
|
|
|
|
render_template,
|
2016-03-09 14:30:50 +00:00
|
|
|
|
request,
|
2018-02-20 11:22:17 +00:00
|
|
|
|
url_for,
|
2016-03-09 14:30:50 +00:00
|
|
|
|
)
|
2019-07-01 15:22:08 +01:00
|
|
|
|
from flask_login import current_user
|
2016-04-15 11:04:35 +01:00
|
|
|
|
from notifications_python_client.errors import HTTPError
|
2016-03-09 14:30:50 +00:00
|
|
|
|
|
2018-02-20 11:22:17 +00:00
|
|
|
|
from app import (
|
|
|
|
|
|
billing_api_client,
|
|
|
|
|
|
current_service,
|
|
|
|
|
|
inbound_number_client,
|
2019-05-09 17:55:10 +01:00
|
|
|
|
notification_api_client,
|
2023-07-12 12:09:44 -04:00
|
|
|
|
organizations_client,
|
2018-02-20 11:22:17 +00:00
|
|
|
|
service_api_client,
|
|
|
|
|
|
)
|
2021-07-08 15:20:24 +01:00
|
|
|
|
from app.event_handlers import (
|
2021-07-08 15:30:31 +01:00
|
|
|
|
create_archive_service_event,
|
2021-07-12 16:00:16 +01:00
|
|
|
|
create_resume_service_event,
|
2021-07-08 15:20:24 +01:00
|
|
|
|
create_suspend_service_event,
|
|
|
|
|
|
)
|
2021-01-06 12:12:01 +00:00
|
|
|
|
from app.formatters import email_safe
|
2016-01-07 12:29:56 +00:00
|
|
|
|
from app.main import main
|
2016-05-16 13:09:58 +01:00
|
|
|
|
from app.main.forms import (
|
2022-03-15 10:50:18 +00:00
|
|
|
|
AdminBillingDetailsForm,
|
|
|
|
|
|
AdminNotesForm,
|
|
|
|
|
|
AdminServiceAddDataRetentionForm,
|
|
|
|
|
|
AdminServiceEditDataRetentionForm,
|
|
|
|
|
|
AdminServiceInboundNumberForm,
|
|
|
|
|
|
AdminServiceMessageLimitForm,
|
|
|
|
|
|
AdminServiceRateLimitForm,
|
|
|
|
|
|
AdminServiceSMSAllowanceForm,
|
2023-07-12 12:09:44 -04:00
|
|
|
|
AdminSetOrganizationForm,
|
2017-10-04 11:49:32 +01:00
|
|
|
|
RenameServiceForm,
|
2019-02-06 17:32:13 +00:00
|
|
|
|
SearchByNameForm,
|
2018-08-09 11:59:05 +01:00
|
|
|
|
ServiceContactDetailsForm,
|
2018-02-20 11:22:17 +00:00
|
|
|
|
ServiceEditInboundNumberForm,
|
2019-02-18 16:56:43 +00:00
|
|
|
|
ServiceOnOffSettingForm,
|
2018-02-20 11:22:17 +00:00
|
|
|
|
ServiceReplyToEmailForm,
|
|
|
|
|
|
ServiceSmsSenderForm,
|
2019-01-29 14:51:31 +00:00
|
|
|
|
ServiceSwitchChannelForm,
|
2018-02-20 11:22:17 +00:00
|
|
|
|
SMSPrefixForm,
|
2017-09-26 14:05:02 +01:00
|
|
|
|
)
|
2021-06-09 13:19:05 +01:00
|
|
|
|
from app.utils import DELIVERED_STATUSES, FAILURE_STATUSES, SENDING_STATUSES
|
2022-11-28 20:39:24 -05:00
|
|
|
|
from app.utils.time import parse_naive_dt
|
2023-12-20 10:44:38 -05:00
|
|
|
|
from app.utils.user import user_has_permissions, user_is_platform_admin
|
2016-01-07 12:29:56 +00:00
|
|
|
|
|
2023-08-25 09:12:23 -07:00
|
|
|
|
PLATFORM_ADMIN_SERVICE_PERMISSIONS = OrderedDict(
|
|
|
|
|
|
[
|
|
|
|
|
|
(
|
|
|
|
|
|
"inbound_sms",
|
|
|
|
|
|
{
|
|
|
|
|
|
"title": "Receive inbound SMS",
|
|
|
|
|
|
"requires": "sms",
|
|
|
|
|
|
"endpoint": ".service_set_inbound_number",
|
|
|
|
|
|
},
|
|
|
|
|
|
),
|
|
|
|
|
|
("email_auth", {"title": "Email authentication"}),
|
|
|
|
|
|
]
|
|
|
|
|
|
)
|
2019-02-18 16:56:43 +00:00
|
|
|
|
|
|
|
|
|
|
|
2019-11-04 11:07:55 +00:00
|
|
|
|
@main.route("/services/<uuid:service_id>/service-settings")
|
2023-08-25 09:12:23 -07:00
|
|
|
|
@user_has_permissions("manage_service", "manage_api_keys")
|
2016-01-13 12:10:29 +00:00
|
|
|
|
def service_settings(service_id):
|
2019-02-18 16:56:43 +00:00
|
|
|
|
return render_template(
|
2023-08-25 09:12:23 -07:00
|
|
|
|
"views/service-settings.html",
|
2022-03-02 15:36:28 +00:00
|
|
|
|
service_permissions=PLATFORM_ADMIN_SERVICE_PERMISSIONS,
|
2019-02-18 16:56:43 +00:00
|
|
|
|
)
|
2016-01-07 12:29:56 +00:00
|
|
|
|
|
|
|
|
|
|
|
2023-08-25 09:12:23 -07:00
|
|
|
|
@main.route(
|
|
|
|
|
|
"/services/<uuid:service_id>/service-settings/name", methods=["GET", "POST"]
|
|
|
|
|
|
)
|
|
|
|
|
|
@user_has_permissions("manage_service")
|
2016-01-18 16:01:04 +00:00
|
|
|
|
def service_name_change(service_id):
|
2021-12-01 12:07:00 +00:00
|
|
|
|
form = RenameServiceForm(name=current_service.name)
|
2016-06-20 13:33:29 +01:00
|
|
|
|
|
2016-01-18 16:01:04 +00:00
|
|
|
|
if form.validate_on_submit():
|
2021-12-01 12:07:00 +00:00
|
|
|
|
try:
|
|
|
|
|
|
current_service.update(
|
|
|
|
|
|
name=form.name.data,
|
|
|
|
|
|
email_from=email_safe(form.name.data),
|
|
|
|
|
|
)
|
|
|
|
|
|
except HTTPError as http_error:
|
|
|
|
|
|
if http_error.status_code == 400 and any(
|
2023-08-25 09:12:23 -07:00
|
|
|
|
name_error_message.startswith("Duplicate service name")
|
|
|
|
|
|
for name_error_message in http_error.message["name"]
|
2021-12-01 12:07:00 +00:00
|
|
|
|
):
|
2023-08-25 09:12:23 -07:00
|
|
|
|
form.name.errors.append("This service name is already in use")
|
2021-12-01 12:07:00 +00:00
|
|
|
|
else:
|
|
|
|
|
|
raise http_error
|
|
|
|
|
|
else:
|
2023-08-25 09:12:23 -07:00
|
|
|
|
return redirect(url_for(".service_settings", service_id=service_id))
|
2016-01-18 16:01:04 +00:00
|
|
|
|
|
2023-08-25 09:12:23 -07:00
|
|
|
|
if current_service.organization_type == "local":
|
2020-07-01 14:24:27 +01:00
|
|
|
|
return render_template(
|
2023-08-25 09:12:23 -07:00
|
|
|
|
"views/service-settings/name-local.html",
|
2020-07-01 14:24:27 +01:00
|
|
|
|
form=form,
|
|
|
|
|
|
)
|
|
|
|
|
|
|
2016-01-18 16:01:04 +00:00
|
|
|
|
return render_template(
|
2023-08-25 09:12:23 -07:00
|
|
|
|
"views/service-settings/name.html",
|
2018-07-02 11:00:02 +01:00
|
|
|
|
form=form,
|
|
|
|
|
|
)
|
2016-01-07 16:24:43 +00:00
|
|
|
|
|
|
|
|
|
|
|
2023-08-25 09:12:23 -07:00
|
|
|
|
@main.route(
|
|
|
|
|
|
"/services/<uuid:service_id>/service-settings/switch-live", methods=["GET", "POST"]
|
|
|
|
|
|
)
|
2018-02-27 16:45:20 +00:00
|
|
|
|
@user_is_platform_admin
|
2016-04-14 15:38:27 +01:00
|
|
|
|
def service_switch_live(service_id):
|
2019-02-18 16:56:43 +00:00
|
|
|
|
form = ServiceOnOffSettingForm(
|
2023-08-25 09:12:23 -07:00
|
|
|
|
name="Make service live", enabled=not current_service.trial_mode
|
2016-08-11 12:32:38 +01:00
|
|
|
|
)
|
2016-04-14 15:38:27 +01:00
|
|
|
|
|
2019-02-18 16:56:43 +00:00
|
|
|
|
if form.validate_on_submit():
|
2019-04-10 17:20:51 +01:00
|
|
|
|
current_service.update_status(live=form.enabled.data)
|
2023-12-27 14:14:22 -07:00
|
|
|
|
if form.enabled.data is True:
|
|
|
|
|
|
billing_api_client.create_or_update_free_sms_fragment_limit(
|
|
|
|
|
|
service_id, 250000
|
|
|
|
|
|
)
|
|
|
|
|
|
else:
|
|
|
|
|
|
billing_api_client.create_or_update_free_sms_fragment_limit(
|
|
|
|
|
|
service_id, 40000
|
|
|
|
|
|
)
|
2023-08-25 09:12:23 -07:00
|
|
|
|
return redirect(url_for(".service_settings", service_id=service_id))
|
2016-04-14 15:38:27 +01:00
|
|
|
|
|
2019-02-18 16:56:43 +00:00
|
|
|
|
return render_template(
|
2023-08-25 09:12:23 -07:00
|
|
|
|
"views/service-settings/set-service-setting.html",
|
2019-02-18 16:56:43 +00:00
|
|
|
|
title="Make service live",
|
|
|
|
|
|
form=form,
|
|
|
|
|
|
)
|
2016-10-26 16:56:51 +01:00
|
|
|
|
|
|
|
|
|
|
|
2023-08-25 09:12:23 -07:00
|
|
|
|
@main.route(
|
|
|
|
|
|
"/services/<uuid:service_id>/service-settings/switch-count-as-live",
|
|
|
|
|
|
methods=["GET", "POST"],
|
|
|
|
|
|
)
|
2019-03-25 14:46:42 +00:00
|
|
|
|
@user_is_platform_admin
|
|
|
|
|
|
def service_switch_count_as_live(service_id):
|
|
|
|
|
|
form = ServiceOnOffSettingForm(
|
|
|
|
|
|
name="Count in list of live services",
|
|
|
|
|
|
enabled=current_service.count_as_live,
|
2023-08-25 09:12:23 -07:00
|
|
|
|
truthy="Yes",
|
|
|
|
|
|
falsey="No",
|
2019-03-25 14:46:42 +00:00
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
if form.validate_on_submit():
|
2019-07-08 14:32:18 +01:00
|
|
|
|
current_service.update_count_as_live(form.enabled.data)
|
2023-08-25 09:12:23 -07:00
|
|
|
|
return redirect(url_for(".service_settings", service_id=service_id))
|
2019-03-25 14:46:42 +00:00
|
|
|
|
|
|
|
|
|
|
return render_template(
|
2023-08-25 09:12:23 -07:00
|
|
|
|
"views/service-settings/set-service-setting.html",
|
2019-03-25 14:46:42 +00:00
|
|
|
|
title="Count in list of live services",
|
|
|
|
|
|
form=form,
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
|
2023-08-25 09:12:23 -07:00
|
|
|
|
@main.route(
|
|
|
|
|
|
"/services/<uuid:service_id>/service-settings/permissions/<permission>",
|
|
|
|
|
|
methods=["GET", "POST"],
|
|
|
|
|
|
)
|
2018-02-27 16:45:20 +00:00
|
|
|
|
@user_is_platform_admin
|
2019-02-18 16:56:43 +00:00
|
|
|
|
def service_set_permission(service_id, permission):
|
|
|
|
|
|
if permission not in PLATFORM_ADMIN_SERVICE_PERMISSIONS:
|
|
|
|
|
|
abort(404)
|
|
|
|
|
|
|
2023-08-25 09:12:23 -07:00
|
|
|
|
title = PLATFORM_ADMIN_SERVICE_PERMISSIONS[permission]["title"]
|
2019-02-18 16:56:43 +00:00
|
|
|
|
form = ServiceOnOffSettingForm(
|
2023-08-25 09:12:23 -07:00
|
|
|
|
name=title, enabled=current_service.has_permission(permission)
|
2019-02-18 16:56:43 +00:00
|
|
|
|
)
|
2017-10-27 11:44:40 +01:00
|
|
|
|
|
2019-02-18 16:56:43 +00:00
|
|
|
|
if form.validate_on_submit():
|
|
|
|
|
|
current_service.force_permission(permission, on=form.enabled.data)
|
2017-10-27 11:44:40 +01:00
|
|
|
|
|
2019-02-18 16:56:43 +00:00
|
|
|
|
return redirect(url_for(".service_settings", service_id=service_id))
|
|
|
|
|
|
|
|
|
|
|
|
return render_template(
|
2023-08-25 09:12:23 -07:00
|
|
|
|
"views/service-settings/set-service-setting.html",
|
2019-02-18 16:56:43 +00:00
|
|
|
|
title=title,
|
|
|
|
|
|
form=form,
|
|
|
|
|
|
)
|
2018-02-21 17:41:19 +00:00
|
|
|
|
|
|
|
|
|
|
|
2023-08-25 09:12:23 -07:00
|
|
|
|
@main.route(
|
|
|
|
|
|
"/services/<uuid:service_id>/service-settings/archive", methods=["GET", "POST"]
|
|
|
|
|
|
)
|
|
|
|
|
|
@user_has_permissions("manage_service")
|
2017-01-31 09:54:51 +00:00
|
|
|
|
def archive_service(service_id):
|
2021-07-14 14:43:04 +01:00
|
|
|
|
if not current_service.active or not (
|
2019-05-29 16:51:25 +01:00
|
|
|
|
current_service.trial_mode or current_user.platform_admin
|
|
|
|
|
|
):
|
|
|
|
|
|
abort(403)
|
2023-08-25 09:12:23 -07:00
|
|
|
|
if request.method == "POST":
|
2020-05-22 17:12:00 +01:00
|
|
|
|
# We need to purge the cache for the services users as otherwise, although they will have had their permissions
|
|
|
|
|
|
# removed in the DB, they would still have permissions in the cache to view/edit/manage this service
|
|
|
|
|
|
cached_service_user_ids = [user.id for user in current_service.active_users]
|
|
|
|
|
|
|
|
|
|
|
|
service_api_client.archive_service(service_id, cached_service_user_ids)
|
2023-08-25 09:12:23 -07:00
|
|
|
|
create_archive_service_event(
|
|
|
|
|
|
service_id=service_id, archived_by_id=current_user.id
|
|
|
|
|
|
)
|
2021-07-08 15:30:31 +01:00
|
|
|
|
|
2019-05-29 16:51:25 +01:00
|
|
|
|
flash(
|
2023-08-25 09:12:23 -07:00
|
|
|
|
"‘{}’ was deleted".format(current_service.name),
|
|
|
|
|
|
"default_with_tick",
|
2019-05-29 16:51:25 +01:00
|
|
|
|
)
|
2023-08-25 09:12:23 -07:00
|
|
|
|
return redirect(url_for(".choose_account"))
|
2016-11-08 14:33:53 +00:00
|
|
|
|
else:
|
2019-05-29 16:51:25 +01:00
|
|
|
|
flash(
|
2023-08-25 09:12:23 -07:00
|
|
|
|
"Are you sure you want to delete ‘{}’? There’s no way to undo this.".format(
|
|
|
|
|
|
current_service.name
|
|
|
|
|
|
),
|
|
|
|
|
|
"delete",
|
2019-05-29 16:51:25 +01:00
|
|
|
|
)
|
2016-11-08 14:33:53 +00:00
|
|
|
|
return service_settings(service_id)
|
2016-05-16 13:09:58 +01:00
|
|
|
|
|
|
|
|
|
|
|
2023-08-25 09:12:23 -07:00
|
|
|
|
@main.route(
|
|
|
|
|
|
"/services/<uuid:service_id>/service-settings/suspend", methods=["GET", "POST"]
|
|
|
|
|
|
)
|
2021-07-14 14:29:09 +01:00
|
|
|
|
@user_is_platform_admin
|
2017-01-31 15:56:06 +00:00
|
|
|
|
def suspend_service(service_id):
|
2023-08-25 09:12:23 -07:00
|
|
|
|
if request.method == "POST":
|
2017-01-31 15:56:06 +00:00
|
|
|
|
service_api_client.suspend_service(service_id)
|
2023-08-25 09:12:23 -07:00
|
|
|
|
create_suspend_service_event(
|
|
|
|
|
|
service_id=service_id, suspended_by_id=current_user.id
|
|
|
|
|
|
)
|
|
|
|
|
|
return redirect(url_for(".service_settings", service_id=service_id))
|
2017-01-31 15:56:06 +00:00
|
|
|
|
else:
|
2023-08-25 09:12:23 -07:00
|
|
|
|
flash(
|
|
|
|
|
|
"This will suspend the service and revoke all api keys. Are you sure you want to suspend this service?",
|
|
|
|
|
|
"suspend",
|
|
|
|
|
|
)
|
2017-01-31 15:56:06 +00:00
|
|
|
|
return service_settings(service_id)
|
|
|
|
|
|
|
|
|
|
|
|
|
2023-08-25 09:12:23 -07:00
|
|
|
|
@main.route(
|
|
|
|
|
|
"/services/<uuid:service_id>/service-settings/resume", methods=["GET", "POST"]
|
|
|
|
|
|
)
|
2021-07-14 14:29:09 +01:00
|
|
|
|
@user_is_platform_admin
|
2017-01-31 15:56:06 +00:00
|
|
|
|
def resume_service(service_id):
|
2023-08-25 09:12:23 -07:00
|
|
|
|
if request.method == "POST":
|
2017-01-31 15:56:06 +00:00
|
|
|
|
service_api_client.resume_service(service_id)
|
2023-08-25 09:12:23 -07:00
|
|
|
|
create_resume_service_event(
|
|
|
|
|
|
service_id=service_id, resumed_by_id=current_user.id
|
|
|
|
|
|
)
|
|
|
|
|
|
return redirect(url_for(".service_settings", service_id=service_id))
|
2017-01-31 15:56:06 +00:00
|
|
|
|
else:
|
2023-08-25 09:12:23 -07:00
|
|
|
|
flash(
|
|
|
|
|
|
"This will resume the service. New api key are required for this service to use the API.",
|
|
|
|
|
|
"resume",
|
|
|
|
|
|
)
|
2017-01-31 15:56:06 +00:00
|
|
|
|
return service_settings(service_id)
|
|
|
|
|
|
|
|
|
|
|
|
|
2023-08-25 09:12:23 -07:00
|
|
|
|
@main.route(
|
|
|
|
|
|
"/services/<uuid:service_id>/service-settings/send-files-by-email",
|
|
|
|
|
|
methods=["GET", "POST"],
|
|
|
|
|
|
)
|
|
|
|
|
|
@user_has_permissions("manage_service")
|
2020-02-25 11:27:43 +00:00
|
|
|
|
def send_files_by_email_contact_details(service_id):
|
2018-08-09 11:59:05 +01:00
|
|
|
|
form = ServiceContactDetailsForm()
|
2020-02-25 11:27:43 +00:00
|
|
|
|
contact_details = None
|
2018-06-05 10:37:41 +01:00
|
|
|
|
|
2023-08-25 09:12:23 -07:00
|
|
|
|
if request.method == "GET":
|
2018-10-26 12:13:04 +01:00
|
|
|
|
contact_details = current_service.contact_link
|
2020-02-25 11:27:43 +00:00
|
|
|
|
if contact_details:
|
|
|
|
|
|
contact_type = check_contact_details_type(contact_details)
|
|
|
|
|
|
field_to_update = getattr(form, contact_type)
|
2018-08-09 11:59:05 +01:00
|
|
|
|
|
2020-02-25 11:27:43 +00:00
|
|
|
|
form.contact_details_type.data = contact_type
|
|
|
|
|
|
field_to_update.data = contact_details
|
2018-06-05 10:37:41 +01:00
|
|
|
|
|
|
|
|
|
|
if form.validate_on_submit():
|
2018-08-09 11:59:05 +01:00
|
|
|
|
contact_type = form.contact_details_type.data
|
|
|
|
|
|
|
2023-08-25 09:12:23 -07:00
|
|
|
|
current_service.update(contact_link=form.data[contact_type])
|
|
|
|
|
|
return redirect(url_for(".service_settings", service_id=current_service.id))
|
2018-06-05 10:37:41 +01:00
|
|
|
|
|
2020-02-25 11:27:43 +00:00
|
|
|
|
return render_template(
|
2023-08-25 09:12:23 -07:00
|
|
|
|
"views/service-settings/send-files-by-email.html",
|
|
|
|
|
|
form=form,
|
|
|
|
|
|
contact_details=contact_details,
|
2020-02-25 11:27:43 +00:00
|
|
|
|
)
|
2018-06-05 10:37:41 +01:00
|
|
|
|
|
|
|
|
|
|
|
2023-08-25 09:12:23 -07:00
|
|
|
|
@main.route(
|
|
|
|
|
|
"/services/<uuid:service_id>/service-settings/set-reply-to-email", methods=["GET"]
|
|
|
|
|
|
)
|
|
|
|
|
|
@user_has_permissions("manage_service")
|
2016-05-16 13:09:58 +01:00
|
|
|
|
def service_set_reply_to_email(service_id):
|
2023-08-25 09:12:23 -07:00
|
|
|
|
return redirect(url_for(".service_email_reply_to", service_id=service_id))
|
2017-09-25 15:14:13 +01:00
|
|
|
|
|
|
|
|
|
|
|
2023-08-25 09:12:23 -07:00
|
|
|
|
@main.route(
|
|
|
|
|
|
"/services/<uuid:service_id>/service-settings/email-reply-to", methods=["GET"]
|
|
|
|
|
|
)
|
|
|
|
|
|
@user_has_permissions("manage_service", "manage_api_keys")
|
2017-09-25 15:14:13 +01:00
|
|
|
|
def service_email_reply_to(service_id):
|
2023-08-25 09:12:23 -07:00
|
|
|
|
return render_template("views/service-settings/email_reply_to.html")
|
2017-09-25 15:14:13 +01:00
|
|
|
|
|
|
|
|
|
|
|
2023-08-25 09:12:23 -07:00
|
|
|
|
@main.route(
|
|
|
|
|
|
"/services/<uuid:service_id>/service-settings/email-reply-to/add",
|
|
|
|
|
|
methods=["GET", "POST"],
|
|
|
|
|
|
)
|
|
|
|
|
|
@user_has_permissions("manage_service")
|
2017-09-25 15:14:13 +01:00
|
|
|
|
def service_add_email_reply_to(service_id):
|
|
|
|
|
|
form = ServiceReplyToEmailForm()
|
2018-10-26 17:31:49 +01:00
|
|
|
|
first_email_address = current_service.count_email_reply_to_addresses == 0
|
2019-05-14 13:37:16 +01:00
|
|
|
|
is_default = first_email_address if first_email_address else form.is_default.data
|
2016-05-16 13:09:58 +01:00
|
|
|
|
if form.validate_on_submit():
|
2021-05-28 15:06:31 +01:00
|
|
|
|
if current_user.platform_admin:
|
|
|
|
|
|
service_api_client.add_reply_to_email_address(
|
2023-08-25 09:12:23 -07:00
|
|
|
|
service_id, email_address=form.email_address.data, is_default=is_default
|
2021-05-28 15:06:31 +01:00
|
|
|
|
)
|
2023-08-25 09:12:23 -07:00
|
|
|
|
return redirect(url_for(".service_email_reply_to", service_id=service_id))
|
2021-05-28 15:06:31 +01:00
|
|
|
|
else:
|
|
|
|
|
|
try:
|
|
|
|
|
|
notification_id = service_api_client.verify_reply_to_email_address(
|
|
|
|
|
|
service_id, form.email_address.data
|
|
|
|
|
|
)["data"]["id"]
|
|
|
|
|
|
except HTTPError as e:
|
|
|
|
|
|
if e.status_code == 409:
|
2023-08-25 09:12:23 -07:00
|
|
|
|
flash(e.message, "error")
|
|
|
|
|
|
return redirect(
|
|
|
|
|
|
url_for(".service_email_reply_to", service_id=service_id)
|
|
|
|
|
|
)
|
2021-05-28 15:06:31 +01:00
|
|
|
|
else:
|
|
|
|
|
|
raise e
|
2023-08-25 09:12:23 -07:00
|
|
|
|
return redirect(
|
|
|
|
|
|
url_for(
|
|
|
|
|
|
".service_verify_reply_to_address",
|
|
|
|
|
|
service_id=service_id,
|
|
|
|
|
|
notification_id=notification_id,
|
|
|
|
|
|
is_default=is_default,
|
|
|
|
|
|
)
|
|
|
|
|
|
)
|
2019-05-14 13:37:16 +01:00
|
|
|
|
|
2017-09-25 15:14:13 +01:00
|
|
|
|
return render_template(
|
2023-08-25 09:12:23 -07:00
|
|
|
|
"views/service-settings/email-reply-to/add.html",
|
2017-09-25 15:14:13 +01:00
|
|
|
|
form=form,
|
2023-08-25 09:12:23 -07:00
|
|
|
|
first_email_address=first_email_address,
|
|
|
|
|
|
)
|
2017-03-02 15:56:28 +00:00
|
|
|
|
|
2017-09-25 15:14:13 +01:00
|
|
|
|
|
2019-11-29 13:03:23 +00:00
|
|
|
|
@main.route(
|
|
|
|
|
|
"/services/<uuid:service_id>/service-settings/email-reply-to/<uuid:notification_id>/verify",
|
2023-08-25 09:12:23 -07:00
|
|
|
|
methods=["GET", "POST"],
|
2019-11-29 13:03:23 +00:00
|
|
|
|
)
|
2023-08-25 09:12:23 -07:00
|
|
|
|
@user_has_permissions("manage_service")
|
2019-05-16 17:05:55 +01:00
|
|
|
|
def service_verify_reply_to_address(service_id, notification_id):
|
2023-08-25 09:12:23 -07:00
|
|
|
|
replace = request.args.get("replace", False)
|
|
|
|
|
|
is_default = request.args.get("is_default", False)
|
2019-05-14 17:53:00 +01:00
|
|
|
|
return render_template(
|
2023-08-25 09:12:23 -07:00
|
|
|
|
"views/service-settings/email-reply-to/verify.html",
|
2019-05-14 17:53:00 +01:00
|
|
|
|
service_id=service_id,
|
|
|
|
|
|
notification_id=notification_id,
|
2023-08-25 09:12:23 -07:00
|
|
|
|
partials=get_service_verify_reply_to_address_partials(
|
|
|
|
|
|
service_id, notification_id
|
|
|
|
|
|
),
|
2019-05-20 18:05:55 +01:00
|
|
|
|
verb=("Change" if replace else "Add"),
|
2019-05-21 13:10:17 +01:00
|
|
|
|
replace=replace,
|
2023-08-25 09:12:23 -07:00
|
|
|
|
is_default=is_default,
|
2019-05-14 17:53:00 +01:00
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
|
2023-08-25 09:12:23 -07:00
|
|
|
|
@main.route(
|
|
|
|
|
|
"/services/<uuid:service_id>/service-settings/email-reply-to/<uuid:notification_id>/verify.json"
|
|
|
|
|
|
)
|
|
|
|
|
|
@user_has_permissions("manage_service")
|
2019-05-16 17:05:55 +01:00
|
|
|
|
def service_verify_reply_to_address_updates(service_id, notification_id):
|
2023-08-25 09:12:23 -07:00
|
|
|
|
return jsonify(
|
|
|
|
|
|
**get_service_verify_reply_to_address_partials(service_id, notification_id)
|
|
|
|
|
|
)
|
2019-05-14 17:53:00 +01:00
|
|
|
|
|
|
|
|
|
|
|
2019-05-16 17:05:55 +01:00
|
|
|
|
def get_service_verify_reply_to_address_partials(service_id, notification_id):
|
2019-05-20 17:32:40 +01:00
|
|
|
|
form = ServiceReplyToEmailForm()
|
|
|
|
|
|
first_email_address = current_service.count_email_reply_to_addresses == 0
|
2023-08-25 09:12:23 -07:00
|
|
|
|
notification = notification_api_client.get_notification(
|
|
|
|
|
|
current_app.config["NOTIFY_SERVICE_ID"], notification_id
|
|
|
|
|
|
)
|
|
|
|
|
|
replace = request.args.get("replace", False)
|
2019-06-05 16:32:08 +01:00
|
|
|
|
replace = False if replace == "False" else replace
|
|
|
|
|
|
existing_is_default = False
|
|
|
|
|
|
if replace:
|
|
|
|
|
|
existing = current_service.get_email_reply_to_address(replace)
|
2023-08-25 09:12:23 -07:00
|
|
|
|
existing_is_default = existing["is_default"]
|
2019-05-13 10:17:20 +01:00
|
|
|
|
verification_status = "pending"
|
2023-08-25 09:12:23 -07:00
|
|
|
|
is_default = True if (request.args.get("is_default", False) == "True") else False
|
2019-05-21 16:08:50 +01:00
|
|
|
|
if notification["status"] in DELIVERED_STATUSES:
|
2019-05-13 10:17:20 +01:00
|
|
|
|
verification_status = "success"
|
2023-08-25 09:12:23 -07:00
|
|
|
|
if notification["to"] not in [
|
|
|
|
|
|
i["email_address"] for i in current_service.email_reply_to_addresses
|
|
|
|
|
|
]:
|
2019-06-05 16:32:08 +01:00
|
|
|
|
if replace:
|
2019-05-20 18:05:55 +01:00
|
|
|
|
service_api_client.update_reply_to_email_address(
|
2023-08-25 09:12:23 -07:00
|
|
|
|
current_service.id,
|
|
|
|
|
|
replace,
|
|
|
|
|
|
email_address=notification["to"],
|
|
|
|
|
|
is_default=is_default,
|
2019-05-20 18:05:55 +01:00
|
|
|
|
)
|
|
|
|
|
|
else:
|
|
|
|
|
|
service_api_client.add_reply_to_email_address(
|
|
|
|
|
|
current_service.id,
|
|
|
|
|
|
email_address=notification["to"],
|
2023-08-25 09:12:23 -07:00
|
|
|
|
is_default=is_default,
|
2019-05-20 18:05:55 +01:00
|
|
|
|
)
|
2020-01-21 12:23:30 +00:00
|
|
|
|
seconds_since_sending = (
|
2023-08-25 09:12:23 -07:00
|
|
|
|
datetime.utcnow() - parse_naive_dt(notification["created_at"])
|
2020-01-21 12:23:30 +00:00
|
|
|
|
).seconds
|
2019-05-21 16:08:50 +01:00
|
|
|
|
if notification["status"] in FAILURE_STATUSES or (
|
2023-08-25 09:12:23 -07:00
|
|
|
|
notification["status"] in SENDING_STATUSES
|
|
|
|
|
|
and seconds_since_sending
|
|
|
|
|
|
> current_app.config["REPLY_TO_EMAIL_ADDRESS_VALIDATION_TIMEOUT"]
|
2019-05-21 16:08:50 +01:00
|
|
|
|
):
|
2019-05-13 10:17:20 +01:00
|
|
|
|
verification_status = "failure"
|
2023-08-25 09:12:23 -07:00
|
|
|
|
form.email_address.data = notification["to"]
|
2019-05-20 17:32:40 +01:00
|
|
|
|
form.is_default.data = is_default
|
2019-05-14 17:53:00 +01:00
|
|
|
|
return {
|
2023-08-25 09:12:23 -07:00
|
|
|
|
"status": render_template(
|
|
|
|
|
|
"views/service-settings/email-reply-to/_verify-updates.html",
|
2019-05-14 17:53:00 +01:00
|
|
|
|
reply_to_email_address=notification["to"],
|
|
|
|
|
|
service_id=current_service.id,
|
|
|
|
|
|
notification_id=notification_id,
|
|
|
|
|
|
verification_status=verification_status,
|
|
|
|
|
|
is_default=is_default,
|
2019-06-05 16:32:08 +01:00
|
|
|
|
existing_is_default=existing_is_default,
|
2019-05-20 17:32:40 +01:00
|
|
|
|
form=form,
|
2019-05-21 13:10:17 +01:00
|
|
|
|
first_email_address=first_email_address,
|
2023-08-25 09:12:23 -07:00
|
|
|
|
replace=replace,
|
2019-05-14 17:53:00 +01:00
|
|
|
|
),
|
2023-08-25 09:12:23 -07:00
|
|
|
|
"stop": 0 if verification_status == "pending" else 1,
|
2019-05-14 17:53:00 +01:00
|
|
|
|
}
|
2019-05-09 17:55:10 +01:00
|
|
|
|
|
|
|
|
|
|
|
2017-11-14 11:31:20 +00:00
|
|
|
|
@main.route(
|
2019-11-04 11:07:55 +00:00
|
|
|
|
"/services/<uuid:service_id>/service-settings/email-reply-to/<uuid:reply_to_email_id>/edit",
|
2023-08-25 09:12:23 -07:00
|
|
|
|
methods=["GET", "POST"],
|
|
|
|
|
|
endpoint="service_edit_email_reply_to",
|
2017-11-14 11:31:20 +00:00
|
|
|
|
)
|
|
|
|
|
|
@main.route(
|
2019-11-04 11:07:55 +00:00
|
|
|
|
"/services/<uuid:service_id>/service-settings/email-reply-to/<uuid:reply_to_email_id>/delete",
|
2023-08-25 09:12:23 -07:00
|
|
|
|
methods=["GET"],
|
|
|
|
|
|
endpoint="service_confirm_delete_email_reply_to",
|
2017-11-14 11:31:20 +00:00
|
|
|
|
)
|
2023-08-25 09:12:23 -07:00
|
|
|
|
@user_has_permissions("manage_service")
|
2017-09-25 15:14:13 +01:00
|
|
|
|
def service_edit_email_reply_to(service_id, reply_to_email_id):
|
|
|
|
|
|
form = ServiceReplyToEmailForm()
|
2023-08-25 09:12:23 -07:00
|
|
|
|
reply_to_email_address = current_service.get_email_reply_to_address(
|
|
|
|
|
|
reply_to_email_id
|
|
|
|
|
|
)
|
2021-11-04 11:21:58 +00:00
|
|
|
|
|
2023-08-25 09:12:23 -07:00
|
|
|
|
if request.method == "GET":
|
|
|
|
|
|
form.email_address.data = reply_to_email_address["email_address"]
|
|
|
|
|
|
form.is_default.data = reply_to_email_address["is_default"]
|
2021-11-04 11:21:58 +00:00
|
|
|
|
|
2023-08-25 09:12:23 -07:00
|
|
|
|
show_choice_of_default_checkbox = not reply_to_email_address["is_default"]
|
2021-11-04 11:21:58 +00:00
|
|
|
|
|
2017-09-25 15:14:13 +01:00
|
|
|
|
if form.validate_on_submit():
|
2023-08-25 09:12:23 -07:00
|
|
|
|
if (
|
|
|
|
|
|
form.email_address.data == reply_to_email_address["email_address"]
|
|
|
|
|
|
or current_user.platform_admin
|
|
|
|
|
|
):
|
2019-05-23 14:40:18 +01:00
|
|
|
|
service_api_client.update_reply_to_email_address(
|
|
|
|
|
|
current_service.id,
|
|
|
|
|
|
reply_to_email_id=reply_to_email_id,
|
|
|
|
|
|
email_address=form.email_address.data,
|
2024-02-29 08:24:53 -08:00
|
|
|
|
is_default=(
|
|
|
|
|
|
True
|
|
|
|
|
|
if reply_to_email_address["is_default"]
|
|
|
|
|
|
else form.is_default.data
|
|
|
|
|
|
),
|
2019-05-23 14:40:18 +01:00
|
|
|
|
)
|
2023-08-25 09:12:23 -07:00
|
|
|
|
return redirect(url_for(".service_email_reply_to", service_id=service_id))
|
2019-05-16 17:05:55 +01:00
|
|
|
|
try:
|
|
|
|
|
|
notification_id = service_api_client.verify_reply_to_email_address(
|
|
|
|
|
|
service_id, form.email_address.data
|
|
|
|
|
|
)["data"]["id"]
|
|
|
|
|
|
except HTTPError as e:
|
2020-04-02 12:11:14 +01:00
|
|
|
|
if e.status_code == 409:
|
2023-08-25 09:12:23 -07:00
|
|
|
|
flash(e.message, "error")
|
|
|
|
|
|
return redirect(
|
|
|
|
|
|
url_for(".service_email_reply_to", service_id=service_id)
|
|
|
|
|
|
)
|
2019-05-16 17:05:55 +01:00
|
|
|
|
else:
|
|
|
|
|
|
raise e
|
2023-08-25 09:12:23 -07:00
|
|
|
|
return redirect(
|
|
|
|
|
|
url_for(
|
|
|
|
|
|
".service_verify_reply_to_address",
|
|
|
|
|
|
service_id=service_id,
|
|
|
|
|
|
notification_id=notification_id,
|
2024-02-29 08:24:53 -08:00
|
|
|
|
is_default=(
|
|
|
|
|
|
True
|
|
|
|
|
|
if reply_to_email_address["is_default"]
|
|
|
|
|
|
else form.is_default.data
|
|
|
|
|
|
),
|
2023-08-25 09:12:23 -07:00
|
|
|
|
replace=reply_to_email_id,
|
|
|
|
|
|
)
|
|
|
|
|
|
)
|
2019-05-16 17:05:55 +01:00
|
|
|
|
|
2023-08-25 09:12:23 -07:00
|
|
|
|
if request.endpoint == "main.service_confirm_delete_email_reply_to":
|
|
|
|
|
|
flash("Are you sure you want to delete this reply-to email address?", "delete")
|
2016-05-16 13:09:58 +01:00
|
|
|
|
return render_template(
|
2023-08-25 09:12:23 -07:00
|
|
|
|
"views/service-settings/email-reply-to/edit.html",
|
2017-09-25 15:14:13 +01:00
|
|
|
|
form=form,
|
2017-11-14 11:31:20 +00:00
|
|
|
|
reply_to_email_address_id=reply_to_email_id,
|
2023-08-25 09:12:23 -07:00
|
|
|
|
show_choice_of_default_checkbox=show_choice_of_default_checkbox,
|
2017-11-14 11:31:20 +00:00
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
|
2019-11-04 11:07:55 +00:00
|
|
|
|
@main.route(
|
|
|
|
|
|
"/services/<uuid:service_id>/service-settings/email-reply-to/<uuid:reply_to_email_id>/delete",
|
2023-08-25 09:12:23 -07:00
|
|
|
|
methods=["POST"],
|
2019-11-04 11:07:55 +00:00
|
|
|
|
)
|
2023-08-25 09:12:23 -07:00
|
|
|
|
@user_has_permissions("manage_service")
|
2017-11-14 11:31:20 +00:00
|
|
|
|
def service_delete_email_reply_to(service_id, reply_to_email_id):
|
2018-04-26 15:09:37 +01:00
|
|
|
|
service_api_client.delete_reply_to_email_address(
|
2018-07-20 08:42:01 +01:00
|
|
|
|
service_id=current_service.id,
|
2017-11-14 11:31:20 +00:00
|
|
|
|
reply_to_email_id=reply_to_email_id,
|
|
|
|
|
|
)
|
2023-08-25 09:12:23 -07:00
|
|
|
|
return redirect(url_for(".service_email_reply_to", service_id=service_id))
|
2016-07-01 13:47:22 +01:00
|
|
|
|
|
|
|
|
|
|
|
2023-08-25 09:12:23 -07:00
|
|
|
|
@main.route(
|
|
|
|
|
|
"/services/<uuid:service_id>/service-settings/set-inbound-number",
|
|
|
|
|
|
methods=["GET", "POST"],
|
|
|
|
|
|
)
|
|
|
|
|
|
@user_has_permissions("manage_service")
|
2017-08-10 10:29:31 +01:00
|
|
|
|
def service_set_inbound_number(service_id):
|
2023-08-25 09:12:23 -07:00
|
|
|
|
available_inbound_numbers = (
|
|
|
|
|
|
inbound_number_client.get_available_inbound_sms_numbers()
|
|
|
|
|
|
)
|
2017-10-24 15:37:44 +01:00
|
|
|
|
inbound_numbers_value_and_label = [
|
2023-08-25 09:12:23 -07:00
|
|
|
|
(number["id"], number["number"]) for number in available_inbound_numbers["data"]
|
2017-10-24 15:37:44 +01:00
|
|
|
|
]
|
2023-08-25 09:12:23 -07:00
|
|
|
|
no_available_numbers = available_inbound_numbers["data"] == []
|
2022-03-15 10:50:18 +00:00
|
|
|
|
form = AdminServiceInboundNumberForm(
|
2017-10-24 15:37:44 +01:00
|
|
|
|
inbound_number_choices=inbound_numbers_value_and_label
|
|
|
|
|
|
)
|
2019-02-18 16:56:43 +00:00
|
|
|
|
|
2017-10-24 15:37:44 +01:00
|
|
|
|
if form.validate_on_submit():
|
|
|
|
|
|
service_api_client.add_sms_sender(
|
2018-07-20 08:42:01 +01:00
|
|
|
|
current_service.id,
|
2017-10-24 15:37:44 +01:00
|
|
|
|
sms_sender=form.inbound_number.data,
|
|
|
|
|
|
is_default=True,
|
2023-08-25 09:12:23 -07:00
|
|
|
|
inbound_number_id=form.inbound_number.data,
|
2017-10-24 15:37:44 +01:00
|
|
|
|
)
|
2023-08-25 09:12:23 -07:00
|
|
|
|
current_service.force_permission("inbound_sms", on=True)
|
|
|
|
|
|
return redirect(url_for(".service_settings", service_id=service_id))
|
2019-02-18 16:56:43 +00:00
|
|
|
|
|
2017-10-24 15:37:44 +01:00
|
|
|
|
return render_template(
|
2023-08-25 09:12:23 -07:00
|
|
|
|
"views/service-settings/set-inbound-number.html",
|
2017-10-24 15:37:44 +01:00
|
|
|
|
form=form,
|
|
|
|
|
|
no_available_numbers=no_available_numbers,
|
|
|
|
|
|
)
|
2017-08-10 10:29:31 +01:00
|
|
|
|
|
|
|
|
|
|
|
2023-08-25 09:12:23 -07:00
|
|
|
|
@main.route(
|
|
|
|
|
|
"/services/<uuid:service_id>/service-settings/sms-prefix", methods=["GET", "POST"]
|
|
|
|
|
|
)
|
|
|
|
|
|
@user_has_permissions("manage_service")
|
2017-11-03 15:01:41 +00:00
|
|
|
|
def service_set_sms_prefix(service_id):
|
2020-07-03 11:48:17 +01:00
|
|
|
|
form = SMSPrefixForm(enabled=current_service.prefix_sms)
|
2017-11-03 15:01:41 +00:00
|
|
|
|
|
2023-08-25 09:12:23 -07:00
|
|
|
|
form.enabled.label.text = "Start all text messages with ‘{}:’".format(
|
|
|
|
|
|
current_service.name
|
|
|
|
|
|
)
|
2017-11-06 14:12:25 +00:00
|
|
|
|
|
2017-11-03 15:01:41 +00:00
|
|
|
|
if form.validate_on_submit():
|
2023-08-25 09:12:23 -07:00
|
|
|
|
current_service.update(prefix_sms=form.enabled.data)
|
|
|
|
|
|
return redirect(url_for(".service_settings", service_id=service_id))
|
2017-11-03 15:01:41 +00:00
|
|
|
|
|
2023-08-25 09:12:23 -07:00
|
|
|
|
return render_template("views/service-settings/sms-prefix.html", form=form)
|
2017-11-03 15:01:41 +00:00
|
|
|
|
|
|
|
|
|
|
|
2023-08-25 09:12:23 -07:00
|
|
|
|
@main.route(
|
|
|
|
|
|
"/services/<uuid:service_id>/service-settings/set-international-sms",
|
|
|
|
|
|
methods=["GET", "POST"],
|
|
|
|
|
|
)
|
|
|
|
|
|
@user_has_permissions("manage_service")
|
2017-04-27 14:26:25 +01:00
|
|
|
|
def service_set_international_sms(service_id):
|
2020-05-29 09:55:34 +01:00
|
|
|
|
form = ServiceOnOffSettingForm(
|
2023-08-25 09:12:23 -07:00
|
|
|
|
"Send text messages to international phone numbers",
|
|
|
|
|
|
enabled=current_service.has_permission("international_sms"),
|
2017-09-26 14:05:02 +01:00
|
|
|
|
)
|
|
|
|
|
|
if form.validate_on_submit():
|
2018-11-05 16:53:03 +00:00
|
|
|
|
current_service.force_permission(
|
2023-08-25 09:12:23 -07:00
|
|
|
|
"international_sms",
|
2020-05-29 09:55:34 +01:00
|
|
|
|
on=form.enabled.data,
|
2017-09-26 14:05:02 +01:00
|
|
|
|
)
|
2023-08-25 09:12:23 -07:00
|
|
|
|
return redirect(url_for(".service_settings", service_id=service_id))
|
2017-04-27 14:26:25 +01:00
|
|
|
|
return render_template(
|
2023-08-25 09:12:23 -07:00
|
|
|
|
"views/service-settings/set-international-sms.html",
|
2017-09-26 14:05:02 +01:00
|
|
|
|
form=form,
|
2017-04-27 14:26:25 +01:00
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
|
2023-08-25 09:12:23 -07:00
|
|
|
|
@main.route(
|
|
|
|
|
|
"/services/<uuid:service_id>/service-settings/set-inbound-sms", methods=["GET"]
|
|
|
|
|
|
)
|
|
|
|
|
|
@user_has_permissions("manage_service")
|
2017-06-07 14:14:53 +01:00
|
|
|
|
def service_set_inbound_sms(service_id):
|
|
|
|
|
|
return render_template(
|
2023-08-25 09:12:23 -07:00
|
|
|
|
"views/service-settings/set-inbound-sms.html",
|
2017-06-07 14:14:53 +01:00
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
|
2023-08-25 09:12:23 -07:00
|
|
|
|
@main.route(
|
|
|
|
|
|
"/services/<uuid:service_id>/service-settings/set-<channel>",
|
|
|
|
|
|
methods=["GET", "POST"],
|
|
|
|
|
|
)
|
|
|
|
|
|
@user_has_permissions("manage_service")
|
2019-01-29 14:51:31 +00:00
|
|
|
|
def service_set_channel(service_id, channel):
|
2023-08-25 09:12:23 -07:00
|
|
|
|
if channel not in {"email", "sms"}:
|
2019-01-29 14:51:31 +00:00
|
|
|
|
abort(404)
|
|
|
|
|
|
|
|
|
|
|
|
form = ServiceSwitchChannelForm(
|
2023-08-25 09:12:23 -07:00
|
|
|
|
channel=channel, enabled=current_service.has_permission(channel)
|
2018-01-19 13:45:54 +00:00
|
|
|
|
)
|
2019-01-29 14:51:31 +00:00
|
|
|
|
|
2018-01-19 13:45:54 +00:00
|
|
|
|
if form.validate_on_submit():
|
2018-11-05 16:53:03 +00:00
|
|
|
|
current_service.force_permission(
|
2019-01-29 14:51:31 +00:00
|
|
|
|
channel,
|
2019-02-18 16:27:53 +00:00
|
|
|
|
on=form.enabled.data,
|
2018-01-19 13:45:54 +00:00
|
|
|
|
)
|
2023-08-25 09:12:23 -07:00
|
|
|
|
return redirect(url_for(".service_settings", service_id=service_id))
|
2019-01-29 14:51:31 +00:00
|
|
|
|
|
2017-05-02 11:03:10 +01:00
|
|
|
|
return render_template(
|
2023-08-25 09:12:23 -07:00
|
|
|
|
"views/service-settings/set-{}.html".format(channel),
|
2018-01-19 13:45:54 +00:00
|
|
|
|
form=form,
|
2017-05-02 11:03:10 +01:00
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
|
2023-08-25 09:12:23 -07:00
|
|
|
|
@main.route(
|
|
|
|
|
|
"/services/<uuid:service_id>/service-settings/set-auth-type", methods=["GET"]
|
|
|
|
|
|
)
|
|
|
|
|
|
@user_has_permissions("manage_service")
|
2017-11-23 09:59:34 +00:00
|
|
|
|
def service_set_auth_type(service_id):
|
|
|
|
|
|
return render_template(
|
2023-08-25 09:12:23 -07:00
|
|
|
|
"views/service-settings/set-auth-type.html",
|
2017-11-23 09:59:34 +00:00
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
|
2023-08-25 09:12:23 -07:00
|
|
|
|
@main.route("/services/<uuid:service_id>/service-settings/sms-sender", methods=["GET"])
|
|
|
|
|
|
@user_has_permissions("manage_service", "manage_api_keys")
|
2017-10-24 15:37:44 +01:00
|
|
|
|
def service_sms_senders(service_id):
|
|
|
|
|
|
return render_template(
|
2023-08-25 09:12:23 -07:00
|
|
|
|
"views/service-settings/sms-senders.html",
|
2017-10-24 15:37:44 +01:00
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
|
2023-08-25 09:12:23 -07:00
|
|
|
|
@main.route(
|
|
|
|
|
|
"/services/<uuid:service_id>/service-settings/sms-sender/add",
|
|
|
|
|
|
methods=["GET", "POST"],
|
|
|
|
|
|
)
|
|
|
|
|
|
@user_has_permissions("manage_service")
|
2017-10-24 15:37:44 +01:00
|
|
|
|
def service_add_sms_sender(service_id):
|
2017-10-30 14:30:43 +00:00
|
|
|
|
form = ServiceSmsSenderForm()
|
2018-10-26 17:31:49 +01:00
|
|
|
|
first_sms_sender = current_service.count_sms_senders == 0
|
2017-10-24 15:37:44 +01:00
|
|
|
|
if form.validate_on_submit():
|
|
|
|
|
|
service_api_client.add_sms_sender(
|
2018-07-20 08:42:01 +01:00
|
|
|
|
current_service.id,
|
2023-08-25 09:12:23 -07:00
|
|
|
|
sms_sender=form.sms_sender.data.replace("\r", "") or None,
|
|
|
|
|
|
is_default=first_sms_sender if first_sms_sender else form.is_default.data,
|
2017-10-24 15:37:44 +01:00
|
|
|
|
)
|
2023-08-25 09:12:23 -07:00
|
|
|
|
return redirect(url_for(".service_sms_senders", service_id=service_id))
|
2017-10-24 15:37:44 +01:00
|
|
|
|
return render_template(
|
2023-08-25 09:12:23 -07:00
|
|
|
|
"views/service-settings/sms-sender/add.html",
|
2017-10-24 15:37:44 +01:00
|
|
|
|
form=form,
|
2023-08-25 09:12:23 -07:00
|
|
|
|
first_sms_sender=first_sms_sender,
|
|
|
|
|
|
)
|
2017-10-24 15:37:44 +01:00
|
|
|
|
|
|
|
|
|
|
|
2017-11-14 11:31:20 +00:00
|
|
|
|
@main.route(
|
2019-11-04 11:07:55 +00:00
|
|
|
|
"/services/<uuid:service_id>/service-settings/sms-sender/<uuid:sms_sender_id>/edit",
|
2023-08-25 09:12:23 -07:00
|
|
|
|
methods=["GET", "POST"],
|
|
|
|
|
|
endpoint="service_edit_sms_sender",
|
2017-11-14 11:31:20 +00:00
|
|
|
|
)
|
|
|
|
|
|
@main.route(
|
2019-11-04 11:07:55 +00:00
|
|
|
|
"/services/<uuid:service_id>/service-settings/sms-sender/<uuid:sms_sender_id>/delete",
|
2023-08-25 09:12:23 -07:00
|
|
|
|
methods=["GET"],
|
|
|
|
|
|
endpoint="service_confirm_delete_sms_sender",
|
2017-11-14 11:31:20 +00:00
|
|
|
|
)
|
2023-08-25 09:12:23 -07:00
|
|
|
|
@user_has_permissions("manage_service")
|
2017-10-24 15:37:44 +01:00
|
|
|
|
def service_edit_sms_sender(service_id, sms_sender_id):
|
2018-10-26 17:31:49 +01:00
|
|
|
|
sms_sender = current_service.get_sms_sender(sms_sender_id)
|
2023-08-25 09:12:23 -07:00
|
|
|
|
is_inbound_number = sms_sender["inbound_number_id"]
|
2017-10-30 14:30:43 +00:00
|
|
|
|
if is_inbound_number:
|
2023-08-25 09:12:23 -07:00
|
|
|
|
form = ServiceEditInboundNumberForm(is_default=sms_sender["is_default"])
|
2017-10-30 14:30:43 +00:00
|
|
|
|
else:
|
|
|
|
|
|
form = ServiceSmsSenderForm(**sms_sender)
|
|
|
|
|
|
|
2017-10-24 15:37:44 +01:00
|
|
|
|
if form.validate_on_submit():
|
|
|
|
|
|
service_api_client.update_sms_sender(
|
2018-07-20 08:42:01 +01:00
|
|
|
|
current_service.id,
|
2017-10-24 15:37:44 +01:00
|
|
|
|
sms_sender_id=sms_sender_id,
|
2024-02-29 08:24:53 -08:00
|
|
|
|
sms_sender=(
|
|
|
|
|
|
sms_sender["sms_sender"]
|
|
|
|
|
|
if is_inbound_number
|
|
|
|
|
|
else form.sms_sender.data.replace("\r", "")
|
|
|
|
|
|
),
|
2023-08-25 09:12:23 -07:00
|
|
|
|
is_default=True if sms_sender["is_default"] else form.is_default.data,
|
2017-10-24 15:37:44 +01:00
|
|
|
|
)
|
2023-08-25 09:12:23 -07:00
|
|
|
|
return redirect(url_for(".service_sms_senders", service_id=service_id))
|
2017-10-30 14:30:43 +00:00
|
|
|
|
|
2023-08-25 09:12:23 -07:00
|
|
|
|
form.is_default.data = sms_sender["is_default"]
|
|
|
|
|
|
if request.endpoint == "main.service_confirm_delete_sms_sender":
|
|
|
|
|
|
flash("Are you sure you want to delete this text message sender?", "delete")
|
2017-10-24 15:37:44 +01:00
|
|
|
|
return render_template(
|
2023-08-25 09:12:23 -07:00
|
|
|
|
"views/service-settings/sms-sender/edit.html",
|
2017-10-24 15:37:44 +01:00
|
|
|
|
form=form,
|
2017-10-30 14:30:43 +00:00
|
|
|
|
sms_sender=sms_sender,
|
2017-11-14 11:31:20 +00:00
|
|
|
|
inbound_number=is_inbound_number,
|
2023-08-25 09:12:23 -07:00
|
|
|
|
sms_sender_id=sms_sender_id,
|
2017-11-14 11:31:20 +00:00
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@main.route(
|
2019-11-04 11:07:55 +00:00
|
|
|
|
"/services/<uuid:service_id>/service-settings/sms-sender/<uuid:sms_sender_id>/delete",
|
2023-08-25 09:12:23 -07:00
|
|
|
|
methods=["POST"],
|
2017-11-14 11:31:20 +00:00
|
|
|
|
)
|
2023-08-25 09:12:23 -07:00
|
|
|
|
@user_has_permissions("manage_service")
|
2017-11-14 11:31:20 +00:00
|
|
|
|
def service_delete_sms_sender(service_id, sms_sender_id):
|
2018-04-26 15:09:37 +01:00
|
|
|
|
service_api_client.delete_sms_sender(
|
2018-07-20 08:42:01 +01:00
|
|
|
|
service_id=current_service.id,
|
2017-11-14 11:31:20 +00:00
|
|
|
|
sms_sender_id=sms_sender_id,
|
2017-10-30 14:30:43 +00:00
|
|
|
|
)
|
2023-08-25 09:12:23 -07:00
|
|
|
|
return redirect(url_for(".service_sms_senders", service_id=service_id))
|
2017-10-24 15:37:44 +01:00
|
|
|
|
|
|
|
|
|
|
|
2023-08-25 09:12:23 -07:00
|
|
|
|
@main.route(
|
|
|
|
|
|
"/services/<uuid:service_id>/service-settings/set-free-sms-allowance",
|
|
|
|
|
|
methods=["GET", "POST"],
|
|
|
|
|
|
)
|
2018-02-27 16:45:20 +00:00
|
|
|
|
@user_is_platform_admin
|
2017-10-05 13:49:43 +01:00
|
|
|
|
def set_free_sms_allowance(service_id):
|
2023-08-25 09:12:23 -07:00
|
|
|
|
form = AdminServiceSMSAllowanceForm(
|
|
|
|
|
|
free_sms_allowance=current_service.free_sms_fragment_limit
|
|
|
|
|
|
)
|
2017-11-09 13:18:09 +00:00
|
|
|
|
|
2017-10-05 13:49:43 +01:00
|
|
|
|
if form.validate_on_submit():
|
2023-08-25 09:12:23 -07:00
|
|
|
|
billing_api_client.create_or_update_free_sms_fragment_limit(
|
|
|
|
|
|
service_id, form.free_sms_allowance.data
|
|
|
|
|
|
)
|
2017-11-09 13:18:09 +00:00
|
|
|
|
|
2023-08-25 09:12:23 -07:00
|
|
|
|
return redirect(url_for(".service_settings", service_id=service_id))
|
2017-10-05 13:49:43 +01:00
|
|
|
|
|
|
|
|
|
|
return render_template(
|
2023-08-25 09:12:23 -07:00
|
|
|
|
"views/service-settings/set-free-sms-allowance.html",
|
2017-10-05 13:49:43 +01:00
|
|
|
|
form=form,
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
|
2023-08-25 09:12:23 -07:00
|
|
|
|
@main.route(
|
|
|
|
|
|
"/services/<uuid:service_id>/service-settings/set-message-limit",
|
|
|
|
|
|
methods=["GET", "POST"],
|
|
|
|
|
|
)
|
2020-10-19 17:19:32 +01:00
|
|
|
|
@user_is_platform_admin
|
|
|
|
|
|
def set_message_limit(service_id):
|
2022-03-15 10:50:18 +00:00
|
|
|
|
form = AdminServiceMessageLimitForm(message_limit=current_service.message_limit)
|
2020-10-19 17:19:32 +01:00
|
|
|
|
|
|
|
|
|
|
if form.validate_on_submit():
|
|
|
|
|
|
current_service.update(message_limit=form.message_limit.data)
|
|
|
|
|
|
|
2023-08-25 09:12:23 -07:00
|
|
|
|
return redirect(url_for(".service_settings", service_id=service_id))
|
2020-10-19 17:19:32 +01:00
|
|
|
|
|
|
|
|
|
|
return render_template(
|
2023-08-25 09:12:23 -07:00
|
|
|
|
"views/service-settings/set-message-limit.html",
|
2020-10-19 17:19:32 +01:00
|
|
|
|
form=form,
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
|
2023-08-25 09:12:23 -07:00
|
|
|
|
@main.route(
|
|
|
|
|
|
"/services/<uuid:service_id>/service-settings/set-rate-limit",
|
|
|
|
|
|
methods=["GET", "POST"],
|
|
|
|
|
|
)
|
2020-10-21 14:30:35 +01:00
|
|
|
|
@user_is_platform_admin
|
|
|
|
|
|
def set_rate_limit(service_id):
|
2022-03-15 10:50:18 +00:00
|
|
|
|
form = AdminServiceRateLimitForm(rate_limit=current_service.rate_limit)
|
2020-10-21 14:30:35 +01:00
|
|
|
|
|
|
|
|
|
|
if form.validate_on_submit():
|
|
|
|
|
|
current_service.update(rate_limit=form.rate_limit.data)
|
|
|
|
|
|
|
2023-08-25 09:12:23 -07:00
|
|
|
|
return redirect(url_for(".service_settings", service_id=service_id))
|
2020-10-21 14:30:35 +01:00
|
|
|
|
|
|
|
|
|
|
return render_template(
|
2023-08-25 09:12:23 -07:00
|
|
|
|
"views/service-settings/set-rate-limit.html",
|
2020-10-21 14:30:35 +01:00
|
|
|
|
form=form,
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
|
2023-08-25 09:12:23 -07:00
|
|
|
|
@main.route(
|
|
|
|
|
|
"/services/<uuid:service_id>/service-settings/link-service-to-organization",
|
|
|
|
|
|
methods=["GET", "POST"],
|
|
|
|
|
|
)
|
2018-02-27 16:45:20 +00:00
|
|
|
|
@user_is_platform_admin
|
2023-07-12 12:09:44 -04:00
|
|
|
|
def link_service_to_organization(service_id):
|
|
|
|
|
|
all_organizations = organizations_client.get_organizations()
|
2018-02-12 09:26:13 +00:00
|
|
|
|
|
2023-07-12 12:09:44 -04:00
|
|
|
|
form = AdminSetOrganizationForm(
|
2023-08-25 09:12:23 -07:00
|
|
|
|
choices=convert_dictionary_to_wtforms_choices_format(
|
|
|
|
|
|
all_organizations, "id", "name"
|
|
|
|
|
|
),
|
|
|
|
|
|
organizations=current_service.organization_id,
|
2018-02-12 09:26:13 +00:00
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
if form.validate_on_submit():
|
2023-07-12 12:09:44 -04:00
|
|
|
|
if form.organizations.data != current_service.organization_id:
|
|
|
|
|
|
organizations_client.update_service_organization(
|
2023-08-25 09:12:23 -07:00
|
|
|
|
service_id, form.organizations.data
|
2018-02-12 09:26:13 +00:00
|
|
|
|
)
|
2023-08-25 09:12:23 -07:00
|
|
|
|
return redirect(url_for(".service_settings", service_id=service_id))
|
2018-02-12 09:26:13 +00:00
|
|
|
|
|
|
|
|
|
|
return render_template(
|
2023-08-25 09:12:23 -07:00
|
|
|
|
"views/service-settings/link-service-to-organization.html",
|
2023-07-12 12:09:44 -04:00
|
|
|
|
has_organizations=all_organizations,
|
2018-02-12 09:26:13 +00:00
|
|
|
|
form=form,
|
2019-07-16 16:52:19 +01:00
|
|
|
|
search_form=SearchByNameForm(),
|
2018-02-12 09:26:13 +00:00
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
|
2023-08-25 09:12:23 -07:00
|
|
|
|
@main.route("/services/<uuid:service_id>/data-retention", methods=["GET"])
|
2018-07-13 16:47:26 +01:00
|
|
|
|
@user_is_platform_admin
|
2018-07-17 14:39:04 +01:00
|
|
|
|
def data_retention(service_id):
|
2018-10-26 17:31:49 +01:00
|
|
|
|
return render_template(
|
2023-08-25 09:12:23 -07:00
|
|
|
|
"views/service-settings/data-retention.html",
|
2018-10-26 17:31:49 +01:00
|
|
|
|
)
|
2018-07-17 14:39:04 +01:00
|
|
|
|
|
|
|
|
|
|
|
2023-08-25 09:12:23 -07:00
|
|
|
|
@main.route("/services/<uuid:service_id>/data-retention/add", methods=["GET", "POST"])
|
2018-07-17 14:39:04 +01:00
|
|
|
|
@user_is_platform_admin
|
|
|
|
|
|
def add_data_retention(service_id):
|
2022-03-15 10:50:18 +00:00
|
|
|
|
form = AdminServiceAddDataRetentionForm()
|
2018-07-17 14:39:04 +01:00
|
|
|
|
if form.validate_on_submit():
|
2023-08-25 09:12:23 -07:00
|
|
|
|
service_api_client.create_service_data_retention(
|
|
|
|
|
|
service_id, form.notification_type.data, form.days_of_retention.data
|
|
|
|
|
|
)
|
|
|
|
|
|
return redirect(url_for(".data_retention", service_id=service_id))
|
|
|
|
|
|
return render_template("views/service-settings/data-retention/add.html", form=form)
|
2018-07-17 14:39:04 +01:00
|
|
|
|
|
|
|
|
|
|
|
2023-08-25 09:12:23 -07:00
|
|
|
|
@main.route(
|
|
|
|
|
|
"/services/<uuid:service_id>/data-retention/<uuid:data_retention_id>/edit",
|
|
|
|
|
|
methods=["GET", "POST"],
|
|
|
|
|
|
)
|
2018-07-17 14:39:04 +01:00
|
|
|
|
@user_is_platform_admin
|
|
|
|
|
|
def edit_data_retention(service_id, data_retention_id):
|
2018-10-26 17:31:49 +01:00
|
|
|
|
data_retention_item = current_service.get_data_retention_item(data_retention_id)
|
2023-08-25 09:12:23 -07:00
|
|
|
|
form = AdminServiceEditDataRetentionForm(
|
|
|
|
|
|
days_of_retention=data_retention_item["days_of_retention"]
|
|
|
|
|
|
)
|
2018-07-17 14:39:04 +01:00
|
|
|
|
if form.validate_on_submit():
|
2023-08-25 09:12:23 -07:00
|
|
|
|
service_api_client.update_service_data_retention(
|
|
|
|
|
|
service_id, data_retention_id, form.days_of_retention.data
|
|
|
|
|
|
)
|
|
|
|
|
|
return redirect(url_for(".data_retention", service_id=service_id))
|
2018-07-17 14:39:04 +01:00
|
|
|
|
return render_template(
|
2023-08-25 09:12:23 -07:00
|
|
|
|
"views/service-settings/data-retention/edit.html",
|
2018-07-17 14:39:04 +01:00
|
|
|
|
form=form,
|
|
|
|
|
|
data_retention_id=data_retention_id,
|
2023-08-25 09:12:23 -07:00
|
|
|
|
notification_type=data_retention_item["notification_type"],
|
2018-07-13 16:47:26 +01:00
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
|
2023-08-25 09:12:23 -07:00
|
|
|
|
@main.route("/services/<uuid:service_id>/notes", methods=["GET", "POST"])
|
2021-01-25 14:50:49 +00:00
|
|
|
|
@user_is_platform_admin
|
2021-01-14 18:00:44 +00:00
|
|
|
|
def edit_service_notes(service_id):
|
2022-03-15 10:50:18 +00:00
|
|
|
|
form = AdminNotesForm(notes=current_service.notes)
|
2021-01-14 18:00:44 +00:00
|
|
|
|
|
|
|
|
|
|
if form.validate_on_submit():
|
|
|
|
|
|
if form.notes.data == current_service.notes:
|
2023-08-25 09:12:23 -07:00
|
|
|
|
return redirect(url_for(".service_settings", service_id=service_id))
|
2021-01-14 18:00:44 +00:00
|
|
|
|
|
2023-08-25 09:12:23 -07:00
|
|
|
|
current_service.update(notes=form.notes.data)
|
|
|
|
|
|
return redirect(url_for(".service_settings", service_id=service_id))
|
2021-01-14 18:00:44 +00:00
|
|
|
|
|
|
|
|
|
|
return render_template(
|
2023-08-25 09:12:23 -07:00
|
|
|
|
"views/service-settings/edit-service-notes.html",
|
2021-01-14 18:00:44 +00:00
|
|
|
|
form=form,
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
|
2023-08-25 09:12:23 -07:00
|
|
|
|
@main.route("/services/<uuid:service_id>/edit-billing-details", methods=["GET", "POST"])
|
2021-01-25 14:52:07 +00:00
|
|
|
|
@user_is_platform_admin
|
|
|
|
|
|
def edit_service_billing_details(service_id):
|
2022-03-15 10:50:18 +00:00
|
|
|
|
form = AdminBillingDetailsForm(
|
2021-01-26 10:41:22 +00:00
|
|
|
|
billing_contact_email_addresses=current_service.billing_contact_email_addresses,
|
|
|
|
|
|
billing_contact_names=current_service.billing_contact_names,
|
2021-01-25 15:40:49 +00:00
|
|
|
|
billing_reference=current_service.billing_reference,
|
2021-01-27 18:20:25 +00:00
|
|
|
|
purchase_order_number=current_service.purchase_order_number,
|
|
|
|
|
|
notes=current_service.notes,
|
2021-01-25 15:40:49 +00:00
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
if form.validate_on_submit():
|
|
|
|
|
|
current_service.update(
|
2021-01-26 10:41:22 +00:00
|
|
|
|
billing_contact_email_addresses=form.billing_contact_email_addresses.data,
|
|
|
|
|
|
billing_contact_names=form.billing_contact_names.data,
|
2021-01-25 15:40:49 +00:00
|
|
|
|
billing_reference=form.billing_reference.data,
|
2021-01-27 18:20:25 +00:00
|
|
|
|
purchase_order_number=form.purchase_order_number.data,
|
|
|
|
|
|
notes=form.notes.data,
|
2021-01-25 15:40:49 +00:00
|
|
|
|
)
|
2023-08-25 09:12:23 -07:00
|
|
|
|
return redirect(url_for(".service_settings", service_id=service_id))
|
2021-01-25 15:40:49 +00:00
|
|
|
|
|
|
|
|
|
|
return render_template(
|
2023-08-25 09:12:23 -07:00
|
|
|
|
"views/service-settings/edit-service-billing-details.html",
|
2021-01-25 15:40:49 +00:00
|
|
|
|
form=form,
|
|
|
|
|
|
)
|
2021-01-25 14:52:07 +00:00
|
|
|
|
|
|
|
|
|
|
|
2018-02-12 09:26:13 +00:00
|
|
|
|
def convert_dictionary_to_wtforms_choices_format(dictionary, value, label):
|
2023-08-25 09:12:23 -07:00
|
|
|
|
return [(item[value], item[label]) for item in dictionary]
|
2018-08-09 11:59:05 +01:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def check_contact_details_type(contact_details):
|
2023-08-25 09:12:23 -07:00
|
|
|
|
if contact_details.startswith("http"):
|
|
|
|
|
|
return "url"
|
|
|
|
|
|
elif "@" in contact_details:
|
|
|
|
|
|
return "email_address"
|
2018-08-09 11:59:05 +01:00
|
|
|
|
else:
|
2023-08-25 09:12:23 -07:00
|
|
|
|
return "phone_number"
|