Skip to content

Commit

Permalink
Squash validation bug
Browse files Browse the repository at this point in the history
  • Loading branch information
whabanks committed Sep 25, 2024
1 parent 842ccaf commit 3474d19
Showing 1 changed file with 60 additions and 30 deletions.
90 changes: 60 additions & 30 deletions app/main/views/api_keys.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,13 @@
@main.route("/services/<service_id>/api")
@user_has_permissions("manage_api_keys")
def api_integration(service_id):
callbacks_link = ".api_callbacks" if current_service.has_permission("inbound_sms") else ".delivery_status_callback"
callbacks_link = ".api_callbacks" if current_service.has_permission(
"inbound_sms") else ".delivery_status_callback"
return render_template(
"views/api/index.html",
callbacks_link=callbacks_link,
api_notifications=notification_api_client.get_api_notifications_for_service(service_id),
api_notifications=notification_api_client.get_api_notifications_for_service(
service_id),
)


Expand Down Expand Up @@ -87,7 +89,8 @@ def create_api_key(service_id):
disabled_options, option_hints = [], {}
if current_service.trial_mode:
disabled_options = [KEY_TYPE_NORMAL]
option_hints[KEY_TYPE_NORMAL] = Markup(_l("Not available because your service is in trial mode."))
option_hints[KEY_TYPE_NORMAL] = Markup(
_l("Not available because your service is in trial mode."))
if current_service.has_permission("letter"):
option_hints[KEY_TYPE_TEAM] = ""
if form.validate_on_submit():
Expand Down Expand Up @@ -119,7 +122,8 @@ def revoke_api_key(service_id, key_id):
if request.method == "GET":
flash(
[
"{} ‘{}’?".format(_l("Are you sure you want to revoke"), key_name),
"{} ‘{}’?".format(
_l("Are you sure you want to revoke"), key_name),
_l("You will not be able to use this API key to connect to GC Notify"),
],
"revoke this API key",
Expand All @@ -137,9 +141,11 @@ def get_apis():
callback_api = None
inbound_api = None
if current_service.service_callback_api:
callback_api = service_api_client.get_service_callback_api(current_service.id, current_service.service_callback_api[0])
callback_api = service_api_client.get_service_callback_api(
current_service.id, current_service.service_callback_api[0])
if current_service.inbound_api:
inbound_api = service_api_client.get_service_inbound_api(current_service.id, current_service.inbound_api[0])
inbound_api = service_api_client.get_service_inbound_api(
current_service.id, current_service.inbound_api[0])

return (callback_api, inbound_api)

Expand All @@ -161,7 +167,8 @@ def api_callbacks(service_id):

return render_template(
"views/api/callbacks.html",
received_text_messages_callback=received_text_messages_callback["url"] if received_text_messages_callback else None,
received_text_messages_callback=received_text_messages_callback[
"url"] if received_text_messages_callback else None,
delivery_status_callback=delivery_status_callback["url"] if delivery_status_callback else None,
)

Expand All @@ -175,7 +182,8 @@ def get_delivery_status_callback_details():
@user_has_permissions("manage_api_keys")
def delete_delivery_status_callback(service_id):
delivery_status_callback = get_delivery_status_callback_details()
back_link = ".api_callbacks" if current_service.has_permission("inbound_sms") else ".api_integration"
back_link = ".api_callbacks" if current_service.has_permission(
"inbound_sms") else ".api_integration"
url_hint_txt = "Must start with https://"

if request.method == "POST":
Expand All @@ -185,19 +193,23 @@ def delete_delivery_status_callback(service_id):
delivery_status_callback["id"],
)

flash(_l("Your Callback configuration has been deleted."), "default_with_tick")
flash(_l("Your Callback configuration has been deleted."),
"default_with_tick")
return redirect(url_for(back_link, service_id=service_id))

flash(["{}".format(_l("Are you sure you want to delete this callback configuration?"))], "delete")
flash(["{}".format(
_l("Are you sure you want to delete this callback configuration?"))], "delete")

form = ServiceDeliveryStatusCallbackForm(
url=delivery_status_callback.get("url") if delivery_status_callback else "",
url=delivery_status_callback.get(
"url") if delivery_status_callback else "",
bearer_token=dummy_bearer_token if delivery_status_callback else "",
)

return render_template(
"views/api/callbacks/delivery-status-callback.html",
back_link=".api_callbacks" if current_service.has_permission("inbound_sms") else ".delivery_status_callback",
back_link=".api_callbacks" if current_service.has_permission(
"inbound_sms") else ".delivery_status_callback",
hint_text=url_hint_txt,
is_deleting=True,
form=form,
Expand All @@ -211,11 +223,13 @@ def delete_delivery_status_callback(service_id):
@user_has_permissions("manage_api_keys")
def delivery_status_callback(service_id):
delivery_status_callback = get_delivery_status_callback_details()
back_link = ".api_callbacks" if current_service.has_permission("inbound_sms") else ".api_integration"
back_link = ".api_callbacks" if current_service.has_permission(
"inbound_sms") else ".api_integration"
url_hint_txt = _l("Must start with https://")

form = ServiceDeliveryStatusCallbackForm(
url=delivery_status_callback.get("url") if delivery_status_callback else "",
url=delivery_status_callback.get(
"url") if delivery_status_callback else "",
bearer_token=dummy_bearer_token if delivery_status_callback else "",
)

Expand All @@ -230,13 +244,22 @@ def delivery_status_callback(service_id):
service_api_client.update_service_callback_api(
service_id,
url=form.url.data,
bearer_token=check_token_against_dummy_bearer(form.bearer_token.data),
bearer_token=check_token_against_dummy_bearer(
form.bearer_token.data),
user_id=current_user.id,
callback_api_id=delivery_status_callback.get("id"),
)

# If the user is just testing their URL, don't send them back to the API Integration page
if request.form.get("button_pressed") == "test_response_time":
if request.form.get("button_pressed") == "test_response_time" and g.callback_response_time >= 1:
flash(
_l("The service {} took longer than 1 second to respond.").format(
url_hostname,
),
"error",
)
return redirect(url_for("main.delivery_status_callback", service_id=service_id))
else:
flash(
_l("The service {} responded in {} seconds.").format(
url_hostname,
Expand Down Expand Up @@ -329,11 +352,13 @@ def get_received_text_messages_callback():
def received_text_messages_callback(service_id):
if not current_service.has_permission("inbound_sms"):
return redirect(url_for(".api_integration", service_id=service_id))
back_link = ".api_callbacks" if current_service.has_permission("inbound_sms") else ".api_integration"
back_link = ".api_callbacks" if current_service.has_permission(
"inbound_sms") else ".api_integration"

received_text_messages_callback = get_received_text_messages_callback()
form = ServiceReceiveMessagesCallbackForm(
url=received_text_messages_callback.get("url") if received_text_messages_callback else "",
url=received_text_messages_callback.get(
"url") if received_text_messages_callback else "",
bearer_token=dummy_bearer_token if received_text_messages_callback else "",
)
url_hint_txt = _l("Must start with https://")
Expand All @@ -348,19 +373,19 @@ def received_text_messages_callback(service_id):
service_api_client.update_service_inbound_api(
service_id,
url=form.url.data,
bearer_token=check_token_against_dummy_bearer(form.bearer_token.data),
bearer_token=check_token_against_dummy_bearer(
form.bearer_token.data),
user_id=current_user.id,
inbound_api_id=received_text_messages_callback.get("id"),
)

# If the user is just testing their URL, don't send them back to the API Integration page
if request.form.get("button_pressed") == "test_response_time":
if request.form.get("button_pressed") == "test_response_time" and g.callback_response_time >= 1:
flash(
_l("The service {} responded in {} seconds.").format(
_l("The service {} took longer than 1 second to respond.").format(
url_hostname,
response_time,
),
"default_with_tick",
"error",
)
return redirect(url_for("main.received_text_messages_callback", service_id=service_id))
else:
Expand All @@ -371,7 +396,7 @@ def received_text_messages_callback(service_id):
),
"default_with_tick",
)
return redirect(url_for("main.delivery_status_callback", service_id=service_id))
return redirect(url_for("main.received_text_messages_callback", service_id=service_id))

flash(
_l("We’ve saved your callback configuration. {} responded in {} seconds.").format(
Expand Down Expand Up @@ -420,7 +445,7 @@ def received_text_messages_callback(service_id):
),
"default_with_tick",
)
return redirect(url_for("main.delivery_status_callback", service_id=service_id))
return redirect(url_for("main.received_text_messages_callback", service_id=service_id))

flash(
_l("We’ve saved your callback configuration. {} responded in {} seconds.").format(
Expand All @@ -444,7 +469,8 @@ def received_text_messages_callback(service_id):
@user_has_permissions("manage_api_keys")
def delete_received_text_messages_callback(service_id):
received_text_messages_callback = get_received_text_messages_callback()
back_link = ".api_callbacks" if current_service.has_permission("inbound_sms") else ".api_integration"
back_link = ".api_callbacks" if current_service.has_permission(
"inbound_sms") else ".api_integration"
url_hint_txt = "Must start with https://"

if request.method == "POST":
Expand All @@ -454,19 +480,23 @@ def delete_received_text_messages_callback(service_id):
received_text_messages_callback["id"],
)

flash(_l("Your Callback configuration has been deleted."), "default_with_tick")
flash(_l("Your Callback configuration has been deleted."),
"default_with_tick")
return redirect(url_for(back_link, service_id=service_id))

flash(["{}".format(_l("Are you sure you want to delete this callback configuration?"))], "delete")
flash(["{}".format(
_l("Are you sure you want to delete this callback configuration?"))], "delete")

form = ServiceReceiveMessagesCallbackForm(
url=received_text_messages_callback.get("url") if delivery_status_callback else "",
url=received_text_messages_callback.get(
"url") if delivery_status_callback else "",
bearer_token=dummy_bearer_token if received_text_messages_callback else "",
)

return render_template(
"views/api/callbacks/delivery-status-callback.html",
back_link=".api_callbacks" if current_service.has_permission("inbound_sms") else ".delivery_status_callback",
back_link=".api_callbacks" if current_service.has_permission(
"inbound_sms") else ".delivery_status_callback",
hint_text=url_hint_txt,
is_deleting=True,
form=form,
Expand Down

0 comments on commit 3474d19

Please sign in to comment.