Page and form to persist the inbound api data for a service.
This commit is contained in:
Rebecca Law
2017-06-15 16:20:07 +01:00
parent 12cfd45f60
commit 703b48b157
5 changed files with 84 additions and 1 deletions

View File

@@ -651,6 +651,17 @@ class PlaceholderForm(Form):
pass
class ServiceInboundApiForm(Form):
url = StringField("Inbound sms url",
validators=[DataRequired(message='Cant be empty'),
Regexp(regex="^https.*",
message='Must be a valid https url')]
)
bearer_token = StringField("Bearer token",
validators=[DataRequired(message='Cant be empty'),
Length(min=5, message='Must be at least 10 characters')])
def get_placeholder_form_instance(
placeholder_name,
dict_to_populate_from,

View File

@@ -30,7 +30,7 @@ from app.main.forms import (
ServiceLetterContactBlock,
ServiceBrandingOrg,
LetterBranding,
)
ServiceInboundApiForm)
from app import user_api_client, current_service, organisations_client
@@ -38,6 +38,7 @@ from app import user_api_client, current_service, organisations_client
@login_required
@user_has_permissions('manage_settings', admin_override=True)
def service_settings(service_id):
print(current_service)
letter_branding_organisations = organisations_client.get_letter_organisations()
if current_service['organisation']:
organisation = organisations_client.get_organisation(current_service['organisation'])['organisation']
@@ -410,3 +411,24 @@ def get_branding_as_dict(organisations):
'colour': organisation['colour']
} for organisation in organisations
}
@main.route("/services/<service_id>/service-settings/set-inbound-api", methods=['GET', 'POST'])
@login_required
@user_has_permissions('manage_settings', admin_override=True)
def service_set_inbound_api(service_id):
form = ServiceInboundApiForm()
if form.validate_on_submit():
service_api_client.update_service_inbound_api(
service_id,
url=form.url.data,
bearer_token=form.bearer_token.data,
user_id=current_user.id
)
return redirect(url_for('.service_settings', service_id=service_id))
return render_template(
'views/service-settings/set-inbound-api.html',
form=form,
)

View File

@@ -266,6 +266,14 @@ class ServiceAPIClient(NotifyAdminAPIClient):
'/service/{}/inbound-sms/summary'.format(service_id)
)
def update_service_inbound_api(self, service_id, url, bearer_token, user_id):
data = {
"url":url,
"bearer_token": bearer_token,
"updated_by_id": user_id
}
return self.post("/service/{}/inbound-api".format(service_id), data)
class ServicesBrowsableItem(BrowsableItem):
@property

View File

@@ -72,6 +72,13 @@
{{ edit_field('Change', url_for('.service_set_letter_contact_block', service_id=current_service.id)) }}
{% endcall %}
{% endif %}
{% call row() %}
{{ text_field('Inbound API') }}
{{ boolean_field(current_service.can_send_letters) }}
{{ edit_field('Change', url_for('.service_set_inbound_api', service_id=current_service.id)) }}
{% endcall %}
{% endcall %}
</div>

View File

@@ -0,0 +1,35 @@
{% extends "withnav_template.html" %}
{% from "components/textbox.html" import textbox %}
{% from "components/page-footer.html" import page_footer %}
{% block service_page_title %}
Inbound api
{% endblock %}
{% block maincolumn_content %}
<h1 class="heading-large">Inbound API</h1>
<p>
This is the https url that the inbound SMS messages will be posted to
and the bearer token used in the authorisation header of the request.
</p>
<form method="post">
{{ textbox(
form.url,
width='1-4',
hint='Valid https url'
) }}
{{ textbox(
form.bearer_token,
width='1-4',
hint='At least 10 characters'
) }}
{{ page_footer(
'Save',
back_link=url_for('.service_settings', service_id=current_service.id),
back_link_text='Back to settings'
) }}
</form>
{% endblock %}