Allow adding an internal comment on a request

This commit is contained in:
Patrick Smith 2018-09-24 13:44:28 -04:00
parent 99a745904f
commit e0e51d8c35
5 changed files with 48 additions and 10 deletions

View File

@ -1,5 +1,5 @@
from wtforms.fields import TextAreaField
from wtforms.validators import Optional
from wtforms.validators import InputRequired
from .forms import ValidatedForm
@ -7,6 +7,7 @@ from .forms import ValidatedForm
class InternalCommentForm(ValidatedForm):
text = TextAreaField(
"CCPO Internal Notes",
default="",
description="Add comments or notes for internal CCPO reference and follow-up here.<strong>These comments <em>will not</em> be visible to the person making the JEDI request.</strong>",
validators=[Optional()],
validators=[InputRequired()],
)

View File

@ -14,3 +14,4 @@ class RequestInternalComment(Base, mixins.TimestampsMixin):
user = relationship("User")
request_id = Column(ForeignKey("requests.id", ondelete="CASCADE"), nullable=False)
request = relationship("Request")

View File

@ -30,7 +30,7 @@ def render_approval(request, form=None):
mo_data = map_ccpo_authorizing(g.current_user)
form = CCPOReviewForm(data=mo_data)
internal_comment_form = InternalCommentForm(text=request.internal_comments_text)
internal_comment_form = InternalCommentForm()
# Dummy internal comments
comments = [
@ -54,7 +54,7 @@ def render_approval(request, form=None):
current_status=request.status.value,
f=form or CCPOReviewForm(),
internal_comment_form=internal_comment_form,
comments=comments,
comments=request.internal_comments,
)
@ -101,10 +101,10 @@ 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)
# if form.validate():
# request = Requests.get(g.current_user, request_id)
# Requests.update_internal_comments(g.current_user, request, form.data["text"])
form = InternalCommentForm(http_request.form)
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")
)

View File

@ -51,8 +51,8 @@
<li>
<article class='comment-log__log-item'>
<div>
<h3 class='comment-log__log-item__header'>{{ comment.full_name_commenter }}</h3>
<p>{{ comment.message }}</p>
<h3 class='comment-log__log-item__header'>{{ comment.user.full_name }}</h3>
<p>{{ comment.text }}</p>
</div>
{% set timestamp=comment.time_created | formattedDate("%Y-%m-%d %H:%M:%S %Z") %}
<footer class='comment-log__log-item__timestamp'>

View File

@ -108,3 +108,39 @@ def test_can_submit_request_denial(client, user_session):
)
assert response.status_code == 302
assert request.status == RequestStatus.CHANGES_REQUESTED
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_text = "This is the greatest request in the history of requests"
comment_form_data = {"text": comment_text}
response = client.post(
url_for("requests.create_internal_comment", request_id=request.id),
data=comment_form_data,
)
assert response.status_code == 302
assert len(request.internal_comments) == 1
assert request.internal_comments[0].text == comment_text
def test_other_user_cannot_comment_on_request(client, user_session):
user = UserFactory.create()
user_session(user)
request = RequestFactory.create_with_status(
status=RequestStatus.PENDING_CCPO_ACCEPTANCE
)
comment_text = "What is this even"
comment_form_data = {"text": comment_text}
response = client.post(
url_for("requests.create_internal_comment", request_id=request.id),
data=comment_form_data,
)
assert response.status_code == 404