Allow callbacks to be removed

We’ve had a user who’s said:

> Seems configured callbacks cannot be removed once they’re set as the
> fields have a presence check. Is that intentional?

This means it’s not working as they expect. Rather than have to go and
change stuff in the database for them, let’s make it work as they’d
expect.

Only lets you clear the form if you remove both the token and the URL.
This commit is contained in:
Chris Hill-Scott
2018-04-26 17:23:44 +01:00
committed by Leo Hemsted
parent 418a744283
commit c2dbc1934f
5 changed files with 144 additions and 11 deletions

View File

@@ -826,7 +826,15 @@ class ServiceInboundNumberForm(StripWhitespaceForm):
)
class ServiceReceiveMessagesCallbackForm(StripWhitespaceForm):
class CallbackForm(StripWhitespaceForm):
def validate(self):
return super().validate() or (
self.url.data == '' and self.bearer_token.data == ''
)
class ServiceReceiveMessagesCallbackForm(CallbackForm):
url = StringField(
"URL",
validators=[DataRequired(message='Cant be empty'),
@@ -839,7 +847,7 @@ class ServiceReceiveMessagesCallbackForm(StripWhitespaceForm):
)
class ServiceDeliveryStatusCallbackForm(StripWhitespaceForm):
class ServiceDeliveryStatusCallbackForm(CallbackForm):
url = StringField(
"URL",
validators=[DataRequired(message='Cant be empty'),

View File

@@ -208,9 +208,11 @@ def delivery_status_callback(service_id):
)
if form.validate_on_submit():
if delivery_status_callback:
if (delivery_status_callback.get('url') != form.url.data
or form.bearer_token.data != dummy_bearer_token):
if delivery_status_callback and form.url.data:
if (
delivery_status_callback.get('url') != form.url.data or
form.bearer_token.data != dummy_bearer_token
):
service_api_client.update_service_callback_api(
service_id,
url=form.url.data,
@@ -218,7 +220,12 @@ def delivery_status_callback(service_id):
user_id=current_user.id,
callback_api_id=delivery_status_callback.get('id')
)
else:
elif delivery_status_callback and not form.url.data:
service_api_client.delete_service_callback_api(
service_id,
delivery_status_callback['id'],
)
elif form.url.data:
service_api_client.create_service_callback_api(
service_id,
url=form.url.data,
@@ -255,9 +262,11 @@ def received_text_messages_callback(service_id):
)
if form.validate_on_submit():
if received_text_messages_callback:
if (received_text_messages_callback.get('url') != form.url.data
or form.bearer_token.data != dummy_bearer_token):
if received_text_messages_callback and form.url.data:
if (
received_text_messages_callback.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,
@@ -265,7 +274,12 @@ def received_text_messages_callback(service_id):
user_id=current_user.id,
inbound_api_id=received_text_messages_callback.get('id')
)
else:
elif received_text_messages_callback and not form.url.data:
service_api_client.delete_service_inbound_api(
service_id,
received_text_messages_callback['id'],
)
elif form.url.data:
service_api_client.create_service_inbound_api(
service_id,
url=form.url.data,

View File

@@ -332,6 +332,12 @@ class ServiceAPIClient(NotifyAdminAPIClient):
)
)['data']
@cache.delete('service-{service_id}')
def delete_service_inbound_api(self, service_id, callback_api_id):
return self.delete("/service/{}/inbound-api/{}".format(
service_id, callback_api_id
))
def get_reply_to_email_addresses(self, service_id):
return self.get(
"/service/{}/email-reply-to".format(
@@ -463,6 +469,12 @@ class ServiceAPIClient(NotifyAdminAPIClient):
data['bearer_token'] = bearer_token
return self.post("/service/{}/delivery-receipt-api/{}".format(service_id, callback_api_id), data)
@cache.delete('service-{service_id}')
def delete_service_callback_api(self, service_id, callback_api_id):
return self.delete("/service/{}/delivery-receipt-api/{}".format(
service_id, callback_api_id
))
@cache.delete('service-{service_id}')
def create_service_callback_api(self, service_id, url, bearer_token, user_id):
data = {