From fa83dfe6bd8397c6daa4664dadcda18b0055b18a Mon Sep 17 00:00:00 2001 From: leigh-mil Date: Fri, 9 Aug 2019 10:36:04 -0400 Subject: [PATCH] When user not found, redirect to users page and show flash message --- atst/routes/ccpo.py | 4 ++-- atst/utils/flash.py | 5 +++++ templates/ccpo/confirm_user.html | 10 ---------- tests/routes/test_ccpo.py | 4 ++-- tests/test_access.py | 2 +- 5 files changed, 10 insertions(+), 15 deletions(-) diff --git a/atst/routes/ccpo.py b/atst/routes/ccpo.py index 90aaa03f..c2846aa1 100644 --- a/atst/routes/ccpo.py +++ b/atst/routes/ccpo.py @@ -43,8 +43,8 @@ def submit_new_user(): new_user = Users.get_by_dod_id(request.form["dod_id"]) form = CCPOUserForm(obj=new_user) except NotFoundError: - new_user = None - form = CCPOUserForm() + flash("ccpo_user_not_found") + return redirect(url_for("ccpo.users")) return render_template("ccpo/confirm_user.html", new_user=new_user, form=form) diff --git a/atst/utils/flash.py b/atst/utils/flash.py index e7fc72d7..e4f852ea 100644 --- a/atst/utils/flash.py +++ b/atst/utils/flash.py @@ -35,6 +35,11 @@ MESSAGES = { "message_template": "You have successfully given {{ user_name }} CCPO permissions.", "category": "success", }, + "ccpo_user_not_found": { + "title_template": translate("ccpo.form.user_not_found_title"), + "message_template": translate("ccpo.form.user_not_found_text"), + "category": "info", + }, "environment_added": { "title_template": translate("flash.success"), "message_template": """ diff --git a/templates/ccpo/confirm_user.html b/templates/ccpo/confirm_user.html index d7f26c13..4d054240 100644 --- a/templates/ccpo/confirm_user.html +++ b/templates/ccpo/confirm_user.html @@ -30,15 +30,5 @@ - {% else %} -

{{ 'ccpo.form.user_not_found_title' | translate }}

-

- {{ "ccpo.form.user_not_found_text" | translate }} -

-
- - {{ "ccpo.form.return_link" | translate }} - -
{% endif %} {% endblock %} diff --git a/tests/routes/test_ccpo.py b/tests/routes/test_ccpo.py index 9cbd6159..618eb9b9 100644 --- a/tests/routes/test_ccpo.py +++ b/tests/routes/test_ccpo.py @@ -24,11 +24,11 @@ def test_submit_new_user(user_session, client): ) assert new_user.email in response.data.decode() - # give person with out ATAT account CCPO permissions + # give person without ATAT account CCPO permissions response = client.post( url_for("ccpo.submit_new_user"), data={"dod_id": random_dod_id} ) - assert translate("ccpo.form.user_not_found_title") in response.data.decode() + assert url_for("ccpo.users") in response.location def test_confirm_new_user(user_session, client): diff --git a/tests/test_access.py b/tests/test_access.py index 43e842d2..f459ea06 100644 --- a/tests/test_access.py +++ b/tests/test_access.py @@ -146,7 +146,7 @@ def test_ccpo_submit_new_user_access(post_url_assert_status): rando = user_with() url = url_for("ccpo.submit_new_user") - post_url_assert_status(ccpo, url, 200, data={"dod_id": "1234567890"}) + post_url_assert_status(ccpo, url, 302, data={"dod_id": "1234567890"}) post_url_assert_status(rando, url, 404, data={"dod_id": "1234567890"})