mirror of
https://github.com/GSA/notifications-admin.git
synced 2026-06-30 12:18:19 -04:00
Sometimes we get a service ID from a support ticket or a Slack discussion. Rather than having to hack the URL, this PR augments the ‘Find services by name’ page to support service IDs. If a UUID is entered, it assumes that it’s been given a service ID, and redirects straight to the dashboard for that service, without showing any search results (a complete UUID would never match multiple services). If the UUID is not a service ID, the user will get a 404.
29 lines
895 B
Python
29 lines
895 B
Python
import uuid
|
|
from contextlib import suppress
|
|
|
|
from flask import redirect, render_template, url_for
|
|
|
|
from app import service_api_client
|
|
from app.main import main
|
|
from app.main.forms import SearchByNameForm
|
|
from app.utils import user_is_platform_admin
|
|
|
|
|
|
@main.route("/find-services-by-name", methods=['GET', 'POST'])
|
|
@user_is_platform_admin
|
|
def find_services_by_name():
|
|
form = SearchByNameForm()
|
|
services_found = None
|
|
if form.validate_on_submit():
|
|
with suppress(ValueError):
|
|
return redirect(url_for(
|
|
'main.service_dashboard',
|
|
service_id=uuid.UUID(form.search.data)
|
|
))
|
|
services_found = service_api_client.find_services_by_name(service_name=form.search.data)['data']
|
|
return render_template(
|
|
'views/find-services/find-services-by-name.html',
|
|
form=form,
|
|
services_found=services_found
|
|
)
|