mirror of
https://github.com/GSA/notifications-admin.git
synced 2026-05-05 16:38:59 -04:00
Enable update of url / bearer_token inbound api
This commit is contained in:
@@ -9,6 +9,7 @@ from notifications_utils.recipients import (
|
||||
)
|
||||
from notifications_utils.columns import Columns
|
||||
from wtforms import (
|
||||
widgets,
|
||||
validators,
|
||||
StringField,
|
||||
PasswordField,
|
||||
@@ -651,15 +652,19 @@ class PlaceholderForm(Form):
|
||||
pass
|
||||
|
||||
|
||||
class PasswordFieldShowHasContent(StringField):
|
||||
widget = widgets.PasswordInput(hide_value=False)
|
||||
|
||||
|
||||
class ServiceInboundApiForm(Form):
|
||||
url = StringField("Inbound sms url",
|
||||
validators=[DataRequired(message='Can’t be empty'),
|
||||
Regexp(regex="^https.*",
|
||||
message='Must be a valid https url')]
|
||||
)
|
||||
bearer_token = PasswordField("Bearer token",
|
||||
validators=[DataRequired(message='Can’t be empty'),
|
||||
Length(min=10, message='Must be at least 10 characters')])
|
||||
bearer_token = PasswordFieldShowHasContent("Bearer token",
|
||||
validators=[DataRequired(message='Can’t be empty'),
|
||||
Length(min=10, message='Must be at least 10 characters')])
|
||||
|
||||
|
||||
def get_placeholder_form_instance(
|
||||
|
||||
@@ -36,6 +36,9 @@ from app.main.forms import (
|
||||
from app import user_api_client, current_service, organisations_client
|
||||
|
||||
|
||||
dummy_bearer_token = 'bearer_token_set'
|
||||
|
||||
|
||||
def get_inbound_api():
|
||||
if current_service['inbound_api']:
|
||||
return service_api_client.get_service_inbound_api(
|
||||
@@ -441,17 +444,21 @@ def service_set_inbound_api(service_id):
|
||||
abort(403)
|
||||
|
||||
inbound_api = get_inbound_api()
|
||||
form = ServiceInboundApiForm(url=inbound_api.get('url') if inbound_api else '')
|
||||
form = ServiceInboundApiForm(
|
||||
url=inbound_api.get('url') if inbound_api else '',
|
||||
bearer_token=dummy_bearer_token if inbound_api else ''
|
||||
)
|
||||
|
||||
if form.validate_on_submit():
|
||||
if inbound_api:
|
||||
service_api_client.update_service_inbound_api(
|
||||
service_id,
|
||||
url=form.url.data,
|
||||
bearer_token=form.bearer_token.data,
|
||||
user_id=current_user.id,
|
||||
inbound_api_id=inbound_api.get('id')
|
||||
)
|
||||
if inbound_api.get('url') != form.url.data or form.bearer_token.data != dummy_bearer_token:
|
||||
service_api_client.update_service_inbound_api(
|
||||
service_id,
|
||||
url=form.url.data,
|
||||
bearer_token=form.bearer_token.data if form.bearer_token.data != dummy_bearer_token else '',
|
||||
user_id=current_user.id,
|
||||
inbound_api_id=inbound_api.get('id')
|
||||
)
|
||||
else:
|
||||
service_api_client.create_service_inbound_api(
|
||||
service_id,
|
||||
|
||||
Reference in New Issue
Block a user