From fafe98756b48295291a495f3c7081fec29bd5d6a Mon Sep 17 00:00:00 2001 From: Patrick Smith Date: Mon, 24 Sep 2018 13:52:35 -0400 Subject: [PATCH] Show error on page if submitting an empty comment --- atst/routes/requests/approval.py | 17 ++++++++++------- templates/requests/approval.html | 20 ++++++++++---------- tests/routes/test_request_approval.py | 17 +++++++++++++++++ 3 files changed, 37 insertions(+), 17 deletions(-) diff --git a/atst/routes/requests/approval.py b/atst/routes/requests/approval.py index 77e0b628..5b3bcd92 100644 --- a/atst/routes/requests/approval.py +++ b/atst/routes/requests/approval.py @@ -21,7 +21,7 @@ def map_ccpo_authorizing(user): return {"fname_ccpo": user.first_name, "lname_ccpo": user.last_name} -def render_approval(request, form=None): +def render_approval(request, form=None, internal_comment_form=None): data = request.body if request.has_financial_data: data["task_order"] = request.task_order.to_dictionary() @@ -30,7 +30,8 @@ def render_approval(request, form=None): mo_data = map_ccpo_authorizing(g.current_user) form = CCPOReviewForm(data=mo_data) - internal_comment_form = InternalCommentForm() + if not internal_comment_form: + internal_comment_form = InternalCommentForm() # Dummy internal comments comments = [ @@ -52,7 +53,7 @@ def render_approval(request, form=None): reviews=list(reversed(request.reviews)), request=request, current_status=request.status.value, - f=form or CCPOReviewForm(), + review_form=form or CCPOReviewForm(), internal_comment_form=internal_comment_form, comments=request.internal_comments, ) @@ -102,9 +103,11 @@ def task_order_pdf_download(request_id): @requests_bp.route("/requests/internal_comments/", methods=["POST"]) def create_internal_comment(request_id): form = InternalCommentForm(http_request.form) + request = Requests.get(g.current_user, request_id) if form.validate(): - request = Requests.get(g.current_user, request_id) Requests.add_internal_comment(g.current_user, request, form.data.get("text")) - return redirect( - url_for("requests.approval", request_id=request_id, _anchor="ccpo-notes") - ) + return redirect( + url_for("requests.approval", request_id=request_id, _anchor="ccpo-notes") + ) + else: + return render_approval(request, internal_comment_form=form) diff --git a/templates/requests/approval.html b/templates/requests/approval.html index d8ff8299..5e607f57 100644 --- a/templates/requests/approval.html +++ b/templates/requests/approval.html @@ -8,7 +8,7 @@
-{% if f.errors %} +{% if review_form.errors or internal_comment_form.errors %} {{ Alert('There were some errors', message="

Please see below.

", level='error' @@ -88,7 +88,7 @@
- {{ f.csrf_token }} + {{ review_form.csrf_token }}
@@ -165,7 +165,7 @@

Message to Requestor (optional)

{{ TextInput( - f.comment, + review_form.comment, label='Approval comments or notes', description='Provide any comments or notes regarding the approval of this request. This message will be shared with the person making the JEDI request..', paragraph=True, @@ -175,7 +175,7 @@
{{ TextInput( - f.comment, + review_form.comment, label='Revision instructions or notes', paragraph=True, noMaxWidth=True @@ -194,21 +194,21 @@
- {{ TextInput(f.fname_mao, placeholder="First name of mission authorizing official") }} + {{ TextInput(review_form.fname_mao, placeholder="First name of mission authorizing official") }}
- {{ TextInput(f.lname_mao, placeholder="Last name of mission authorizing official") }} + {{ TextInput(review_form.lname_mao, placeholder="Last name of mission authorizing official") }}
- {{ TextInput(f.email_mao, placeholder="name@mail.mil", validation='email') }} + {{ TextInput(review_form.email_mao, placeholder="name@mail.mil", validation='email') }}
- {{ TextInput(f.phone_mao, placeholder="(123) 456-7890", validation='usPhone') }} + {{ TextInput(review_form.phone_mao, placeholder="(123) 456-7890", validation='usPhone') }}
@@ -218,11 +218,11 @@
- {{ TextInput(f.fname_ccpo, placeholder="First name of CCPO authorizing official") }} + {{ TextInput(review_form.fname_ccpo, placeholder="First name of CCPO authorizing official") }}
- {{ TextInput(f.lname_ccpo, placeholder="Last name of CCPO authorizing official") }} + {{ TextInput(review_form.lname_ccpo, placeholder="Last name of CCPO authorizing official") }}
diff --git a/tests/routes/test_request_approval.py b/tests/routes/test_request_approval.py index a10bd5f4..7a0ed0d7 100644 --- a/tests/routes/test_request_approval.py +++ b/tests/routes/test_request_approval.py @@ -129,6 +129,23 @@ def test_ccpo_user_can_comment_on_request(client, user_session): assert request.internal_comments[0].text == comment_text +def test_ccpo_user_can_comment_on_request(client, user_session): + user = UserFactory.from_atat_role("ccpo") + user_session(user) + request = RequestFactory.create_with_status( + status=RequestStatus.PENDING_CCPO_ACCEPTANCE + ) + assert len(request.internal_comments) == 0 + + comment_form_data = {"text": ""} + response = client.post( + url_for("requests.create_internal_comment", request_id=request.id), + data=comment_form_data, + ) + assert response.status_code == 200 + assert len(request.internal_comments) == 0 + + def test_other_user_cannot_comment_on_request(client, user_session): user = UserFactory.create() user_session(user)