Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Squash a few routing / UI bugs #1957

Merged
merged 2 commits into from
Sep 25, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
127 changes: 67 additions & 60 deletions app/main/views/api_keys.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,11 @@
@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 @@ -89,8 +87,7 @@
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 @@ -122,8 +119,7 @@
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 @@ -141,11 +137,9 @@
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 @@ -167,8 +161,7 @@

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 @@ -182,8 +175,7 @@
@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 @@ -193,23 +185,19 @@
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 @@ -223,13 +211,11 @@
@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 @@ -244,32 +230,31 @@
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":
flash(
_l("The service {} responded in {} seconds.").format(
url_hostname,
response_time,
),
"default_with_tick",
)
return redirect(url_for("main.delivery_status_callback", service_id=service_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":
flash(
_l("We’ve saved your callback configuration. {} responded in {} seconds.").format(
_l("The service {} responded in {} seconds.").format(
url_hostname,
response_time,
),
"default_with_tick",
)
return redirect(url_for("main.delivery_status_callback", service_id=service_id))

return redirect(url_for(back_link, service_id=service_id))
flash(
_l("We’ve saved your callback configuration. {} responded in {} seconds.").format(
url_hostname,
response_time,
),
"default_with_tick",
)
Dismissed Show dismissed Hide dismissed

return redirect(url_for(back_link, service_id=service_id))
# Create a new callback
elif form.url.data:
service_api_client.create_service_callback_api(
Expand Down Expand Up @@ -312,6 +297,16 @@
)
return redirect(url_for("main.delivery_status_callback", service_id=service_id))

flash(
_l("We’ve saved your callback configuration. {} responded in {} seconds.").format(
url_hostname,
response_time,
),
"default_with_tick",
)
Dismissed Show dismissed Hide dismissed

return redirect(url_for(back_link, service_id=service_id))

return render_template(
"views/api/callbacks/delivery-status-callback.html",
has_callback_config=delivery_status_callback is not None,
Expand All @@ -334,13 +329,11 @@
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 @@ -355,8 +348,7 @@
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"),
)
Expand All @@ -371,6 +363,15 @@
"default_with_tick",
)
return redirect(url_for("main.received_text_messages_callback", service_id=service_id))
else:
flash(
_l("The service {} responded in {} seconds.").format(
url_hostname,
response_time,
),
"default_with_tick",
)
return redirect(url_for("main.delivery_status_callback", service_id=service_id))

flash(
_l("We’ve saved your callback configuration. {} responded in {} seconds.").format(
Expand All @@ -379,6 +380,7 @@
),
"default_with_tick",
)
return redirect(url_for(back_link, service_id=service_id))

elif received_text_messages_callback and not form.url.data:
service_api_client.delete_service_inbound_api(
Expand Down Expand Up @@ -418,7 +420,17 @@
),
"default_with_tick",
)
return redirect(url_for("main.received_text_messages_callback", service_id=service_id))
return redirect(url_for("main.delivery_status_callback", service_id=service_id))

flash(
_l("We’ve saved your callback configuration. {} responded in {} seconds.").format(
url_hostname,
response_time,
),
"default_with_tick",
)
Dismissed Show dismissed Hide dismissed

return redirect(url_for(back_link, service_id=service_id))

return render_template(
"views/api/callbacks/received-text-messages-callback.html",
Expand All @@ -432,8 +444,7 @@
@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 @@ -443,23 +454,19 @@
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
2 changes: 1 addition & 1 deletion app/templates/components/page-footer.html
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@
button1_value="b1",
button2_text=None,
button2_value=None,
delete_link=False,
delete_link=None,
delete_link_text=_("Delete")) %}
<div class="js-stick-at-bottom-when-scrolling">
<div class="page-footer">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,14 +43,14 @@ <h2 class="heading-small">
{% set test_response_txt = _('Test response time') if has_callback_config else None %}
{% set test_response_value = _('test_response_time') if has_callback_config else None %}
{% set display_footer = is_deleting if is_deleting else False %}
{% set delete_link = url_for('.delete_delivery_status_callback', service_id=current_service.id) if has_callback_config else None%}
{% if not display_footer %}
{{ sticky_page_footer_two_submit_buttons_and_delete_link(
button1_text=_('Save'),
button1_value=_('save'),
button2_text=test_response_txt,
button2_value=test_response_value,
delete_link=url_for('.delete_delivery_status_callback', service_id=current_service.id),
delete_link_text=_('Delete')
delete_link=delete_link,
) }}
{% endif %}
{% endcall %}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,14 +38,15 @@ <h2 class="heading-small">
{% set test_response_txt = _('Test response time') if has_callback_config else None %}
{% set test_response_value = _('test_response_time') if has_callback_config else None %}
{% set display_footer = is_deleting if is_deleting else False %}
{% set delete_link = url_for('.delete_received_text_messages_callback', service_id=current_service.id) if has_callback_config else None%}
{% set delete_link_text = _('Delete') if has_callback_config else None %}
{% if not display_footer %}
{{ sticky_page_footer_two_submit_buttons_and_delete_link(
button1_text=_('Save'),
button1_value=_('save'),
button2_text=test_response_txt,
button2_value=test_response_value,
delete_link=url_for('.delete_received_text_messages_callback', service_id=current_service.id),
delete_link_text=_('Delete')
delete_link=delete_link,
) }}
{% endif %}
{% endcall %}
Expand Down
Loading