Show error on page if submitting an empty comment

This commit is contained in:
Patrick Smith 2018-09-24 13:52:35 -04:00
parent e0e51d8c35
commit 92d73387f5
3 changed files with 37 additions and 17 deletions

View File

@ -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/<string:request_id>", 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)

View File

@ -8,7 +8,7 @@
<article class='col col--grow request-approval'>
{% if f.errors %}
{% if review_form.errors or internal_comment_form.errors %}
{{ Alert('There were some errors',
message="<p>Please see below.</p>",
level='error'
@ -88,7 +88,7 @@
<section class='request-approval__review'>
<form method="POST" action="{{ url_for("requests.submit_approval", request_id=request.id) }}" autocomplete="off">
{{ f.csrf_token }}
{{ review_form.csrf_token }}
<ccpo-approval inline-template>
<div>
@ -165,7 +165,7 @@
<h3>Message to Requestor <span class='subtitle'>(optional)</span></h3>
<div v-if='approving' key='approving' v-cloak>
{{ TextInput(
f.comment,
review_form.comment,
label='Approval comments or notes',
description='Provide any comments or notes regarding the approval of this request. <strong>This message will be shared with the person making the JEDI request.</strong>.',
paragraph=True,
@ -175,7 +175,7 @@
<div v-else key='denying' v-cloak>
{{ TextInput(
f.comment,
review_form.comment,
label='Revision instructions or notes',
paragraph=True,
noMaxWidth=True
@ -194,21 +194,21 @@
<div class='form-row'>
<div class='form-col form-col--half'>
{{ TextInput(f.fname_mao, placeholder="First name of mission authorizing official") }}
{{ TextInput(review_form.fname_mao, placeholder="First name of mission authorizing official") }}
</div>
<div class='form-col form-col--half'>
{{ TextInput(f.lname_mao, placeholder="Last name of mission authorizing official") }}
{{ TextInput(review_form.lname_mao, placeholder="Last name of mission authorizing official") }}
</div>
</div>
<div class='form-row'>
<div class='form-col form-col--half'>
{{ TextInput(f.email_mao, placeholder="name@mail.mil", validation='email') }}
{{ TextInput(review_form.email_mao, placeholder="name@mail.mil", validation='email') }}
</div>
<div class='form-col form-col--half'>
{{ TextInput(f.phone_mao, placeholder="(123) 456-7890", validation='usPhone') }}
{{ TextInput(review_form.phone_mao, placeholder="(123) 456-7890", validation='usPhone') }}
</div>
</div>
@ -218,11 +218,11 @@
<div class='form-row'>
<div class='form-col form-col--half'>
{{ TextInput(f.fname_ccpo, placeholder="First name of CCPO authorizing official") }}
{{ TextInput(review_form.fname_ccpo, placeholder="First name of CCPO authorizing official") }}
</div>
<div class='form-col form-col--half'>
{{ TextInput(f.lname_ccpo, placeholder="Last name of CCPO authorizing official") }}
{{ TextInput(review_form.lname_ccpo, placeholder="Last name of CCPO authorizing official") }}
</div>
</div>
</div>

View File

@ -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)