Show error on page if submitting an empty comment
This commit is contained in:
@@ -21,7 +21,7 @@ def map_ccpo_authorizing(user):
|
|||||||
return {"fname_ccpo": user.first_name, "lname_ccpo": user.last_name}
|
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
|
data = request.body
|
||||||
if request.has_financial_data:
|
if request.has_financial_data:
|
||||||
data["task_order"] = request.task_order.to_dictionary()
|
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)
|
mo_data = map_ccpo_authorizing(g.current_user)
|
||||||
form = CCPOReviewForm(data=mo_data)
|
form = CCPOReviewForm(data=mo_data)
|
||||||
|
|
||||||
internal_comment_form = InternalCommentForm()
|
if not internal_comment_form:
|
||||||
|
internal_comment_form = InternalCommentForm()
|
||||||
|
|
||||||
# Dummy internal comments
|
# Dummy internal comments
|
||||||
comments = [
|
comments = [
|
||||||
@@ -52,7 +53,7 @@ def render_approval(request, form=None):
|
|||||||
reviews=list(reversed(request.reviews)),
|
reviews=list(reversed(request.reviews)),
|
||||||
request=request,
|
request=request,
|
||||||
current_status=request.status.value,
|
current_status=request.status.value,
|
||||||
f=form or CCPOReviewForm(),
|
review_form=form or CCPOReviewForm(),
|
||||||
internal_comment_form=internal_comment_form,
|
internal_comment_form=internal_comment_form,
|
||||||
comments=request.internal_comments,
|
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"])
|
@requests_bp.route("/requests/internal_comments/<string:request_id>", methods=["POST"])
|
||||||
def create_internal_comment(request_id):
|
def create_internal_comment(request_id):
|
||||||
form = InternalCommentForm(http_request.form)
|
form = InternalCommentForm(http_request.form)
|
||||||
|
request = Requests.get(g.current_user, request_id)
|
||||||
if form.validate():
|
if form.validate():
|
||||||
request = Requests.get(g.current_user, request_id)
|
|
||||||
Requests.add_internal_comment(g.current_user, request, form.data.get("text"))
|
Requests.add_internal_comment(g.current_user, request, form.data.get("text"))
|
||||||
return redirect(
|
return redirect(
|
||||||
url_for("requests.approval", request_id=request_id, _anchor="ccpo-notes")
|
url_for("requests.approval", request_id=request_id, _anchor="ccpo-notes")
|
||||||
)
|
)
|
||||||
|
else:
|
||||||
|
return render_approval(request, internal_comment_form=form)
|
||||||
|
@@ -8,7 +8,7 @@
|
|||||||
|
|
||||||
<article class='col col--grow request-approval'>
|
<article class='col col--grow request-approval'>
|
||||||
|
|
||||||
{% if f.errors %}
|
{% if review_form.errors or internal_comment_form.errors %}
|
||||||
{{ Alert('There were some errors',
|
{{ Alert('There were some errors',
|
||||||
message="<p>Please see below.</p>",
|
message="<p>Please see below.</p>",
|
||||||
level='error'
|
level='error'
|
||||||
@@ -88,7 +88,7 @@
|
|||||||
|
|
||||||
<section class='request-approval__review'>
|
<section class='request-approval__review'>
|
||||||
<form method="POST" action="{{ url_for("requests.submit_approval", request_id=request.id) }}" autocomplete="off">
|
<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>
|
<ccpo-approval inline-template>
|
||||||
<div>
|
<div>
|
||||||
@@ -165,7 +165,7 @@
|
|||||||
<h3>Message to Requestor <span class='subtitle'>(optional)</span></h3>
|
<h3>Message to Requestor <span class='subtitle'>(optional)</span></h3>
|
||||||
<div v-if='approving' key='approving' v-cloak>
|
<div v-if='approving' key='approving' v-cloak>
|
||||||
{{ TextInput(
|
{{ TextInput(
|
||||||
f.comment,
|
review_form.comment,
|
||||||
label='Approval comments or notes',
|
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>.',
|
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,
|
paragraph=True,
|
||||||
@@ -175,7 +175,7 @@
|
|||||||
|
|
||||||
<div v-else key='denying' v-cloak>
|
<div v-else key='denying' v-cloak>
|
||||||
{{ TextInput(
|
{{ TextInput(
|
||||||
f.comment,
|
review_form.comment,
|
||||||
label='Revision instructions or notes',
|
label='Revision instructions or notes',
|
||||||
paragraph=True,
|
paragraph=True,
|
||||||
noMaxWidth=True
|
noMaxWidth=True
|
||||||
@@ -194,21 +194,21 @@
|
|||||||
|
|
||||||
<div class='form-row'>
|
<div class='form-row'>
|
||||||
<div class='form-col form-col--half'>
|
<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>
|
||||||
|
|
||||||
<div class='form-col form-col--half'>
|
<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>
|
</div>
|
||||||
|
|
||||||
<div class='form-row'>
|
<div class='form-row'>
|
||||||
<div class='form-col form-col--half'>
|
<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>
|
||||||
|
|
||||||
<div class='form-col form-col--half'>
|
<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>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
@@ -218,11 +218,11 @@
|
|||||||
|
|
||||||
<div class='form-row'>
|
<div class='form-row'>
|
||||||
<div class='form-col form-col--half'>
|
<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>
|
||||||
|
|
||||||
<div class='form-col form-col--half'>
|
<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>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
@@ -129,6 +129,23 @@ def test_ccpo_user_can_comment_on_request(client, user_session):
|
|||||||
assert request.internal_comments[0].text == comment_text
|
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):
|
def test_other_user_cannot_comment_on_request(client, user_session):
|
||||||
user = UserFactory.create()
|
user = UserFactory.create()
|
||||||
user_session(user)
|
user_session(user)
|
||||||
|
Reference in New Issue
Block a user