From 99a745904fb4ec2e416fc4e957b3bed9e4033800 Mon Sep 17 00:00:00 2001 From: Patrick Smith Date: Mon, 24 Sep 2018 13:26:56 -0400 Subject: [PATCH 1/6] Allow having multiple internal comments on a request --- atst/domain/requests/requests.py | 6 +++--- atst/models/request.py | 6 +----- tests/domain/test_requests.py | 9 ++++++--- 3 files changed, 10 insertions(+), 11 deletions(-) diff --git a/atst/domain/requests/requests.py b/atst/domain/requests/requests.py index f830d604..e61df2a9 100644 --- a/atst/domain/requests/requests.py +++ b/atst/domain/requests/requests.py @@ -225,8 +225,8 @@ class Requests(object): return Requests._add_review(user, request, review_data) @classmethod - def update_internal_comments(cls, user, request, comment_text): + def add_internal_comment(cls, user, request, comment_text): Authorization.check_can_approve_request(user) - request.internal_comments = RequestInternalComment(text=comment_text, user=user) - request = RequestsQuery.add_and_commit(request) + comment = RequestInternalComment(request=request, text=comment_text, user=user) + RequestsQuery.add_and_commit(comment) return request diff --git a/atst/models/request.py b/atst/models/request.py index d7d1f96c..e2dee7a4 100644 --- a/atst/models/request.py +++ b/atst/models/request.py @@ -45,7 +45,7 @@ class Request(Base, mixins.TimestampsMixin): "RequestRevision", back_populates="request", order_by="RequestRevision.sequence" ) - internal_comments = relationship("RequestInternalComment", uselist=False) + internal_comments = relationship("RequestInternalComment") @property def latest_revision(self): @@ -167,10 +167,6 @@ class Request(Base, mixins.TimestampsMixin): def reviews(self): return [status.review for status in self.status_events if status.review] - @property - def internal_comments_text(self): - return self.internal_comments.text if self.internal_comments else "" - @property def is_pending_financial_verification(self): return self.status == RequestStatus.PENDING_FINANCIAL_VERIFICATION diff --git a/tests/domain/test_requests.py b/tests/domain/test_requests.py index c9f03d8e..286e906a 100644 --- a/tests/domain/test_requests.py +++ b/tests/domain/test_requests.py @@ -223,10 +223,13 @@ def test_request_changes_to_financial_verification_info(): assert current_review.fname_mao == review_data["fname_mao"] -def test_update_internal_comments(): +def test_add_internal_comment(): request = RequestFactory.create() ccpo = UserFactory.from_atat_role("ccpo") - request = Requests.update_internal_comments(ccpo, request, "this is my comment") + assert len(request.internal_comments) == 0 - assert request.internal_comments.text == "this is my comment" + request = Requests.add_internal_comment(ccpo, request, "this is my comment") + + assert len(request.internal_comments) == 1 + assert request.internal_comments[0].text == "this is my comment" From e0e51d8c352acf5bc9505c72f3aa768a7592ed72 Mon Sep 17 00:00:00 2001 From: Patrick Smith Date: Mon, 24 Sep 2018 13:44:28 -0400 Subject: [PATCH 2/6] Allow adding an internal comment on a request --- atst/forms/internal_comment.py | 5 ++-- atst/models/request_internal_comment.py | 1 + atst/routes/requests/approval.py | 12 ++++----- templates/requests/approval.html | 4 +-- tests/routes/test_request_approval.py | 36 +++++++++++++++++++++++++ 5 files changed, 48 insertions(+), 10 deletions(-) diff --git a/atst/forms/internal_comment.py b/atst/forms/internal_comment.py index c082aefb..e3dc182e 100644 --- a/atst/forms/internal_comment.py +++ b/atst/forms/internal_comment.py @@ -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.These comments will not be visible to the person making the JEDI request.", - validators=[Optional()], + validators=[InputRequired()], ) diff --git a/atst/models/request_internal_comment.py b/atst/models/request_internal_comment.py index 6e1d0825..5d1c3440 100644 --- a/atst/models/request_internal_comment.py +++ b/atst/models/request_internal_comment.py @@ -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") diff --git a/atst/routes/requests/approval.py b/atst/routes/requests/approval.py index e1f6511b..77e0b628 100644 --- a/atst/routes/requests/approval.py +++ b/atst/routes/requests/approval.py @@ -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/", 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") ) diff --git a/templates/requests/approval.html b/templates/requests/approval.html index 64b150aa..d8ff8299 100644 --- a/templates/requests/approval.html +++ b/templates/requests/approval.html @@ -51,8 +51,8 @@
  • -

    {{ comment.full_name_commenter }}

    -

    {{ comment.message }}

    +

    {{ comment.user.full_name }}

    +

    {{ comment.text }}

    {% set timestamp=comment.time_created | formattedDate("%Y-%m-%d %H:%M:%S %Z") %}