From 61b78da2f5334731a96d96a0310f72f76021e036 Mon Sep 17 00:00:00 2001 From: daniel Date: Sun, 25 Feb 2024 14:59:27 +0100 Subject: [PATCH] :sparkles: Lock review requests when done --- src/bptl/work_units/zgw/objects/tasks.py | 19 ++++ .../test_objects_task_review_requests.py | 95 +++++++++++++++++++ 2 files changed, 114 insertions(+) diff --git a/src/bptl/work_units/zgw/objects/tasks.py b/src/bptl/work_units/zgw/objects/tasks.py index 13d23ec6..fb309997 100644 --- a/src/bptl/work_units/zgw/objects/tasks.py +++ b/src/bptl/work_units/zgw/objects/tasks.py @@ -347,3 +347,22 @@ def get_approval_toelichtingen(task: BaseTask) -> dict: ) return {"toelichtingen": "\n\n".join(toelichtingen)} + + +@register +@require_objects_service +@require_objecttypes_service +def lock_review_request(task: BaseTask) -> dict: + """ + Lock review request after all reviews have been given. + + **Required process variables** + + * ``kownslReviewRequestId`` [str]: the identifier of the Kownsl review request. + + **Sets no process variables** + + """ + data = {"locked": True, "lock_reason": "Alle verzoeken zijn uitgevoerd."} + update_review_request(task, requester=None, data=data) + return dict() diff --git a/src/bptl/work_units/zgw/objects/tests/test_objects_task_review_requests.py b/src/bptl/work_units/zgw/objects/tests/test_objects_task_review_requests.py index 132b23e0..6c4eceb8 100644 --- a/src/bptl/work_units/zgw/objects/tests/test_objects_task_review_requests.py +++ b/src/bptl/work_units/zgw/objects/tests/test_objects_task_review_requests.py @@ -14,6 +14,7 @@ get_approval_toelichtingen, get_review_request_start_process_information, get_review_response_status, + lock_review_request, set_review_request_metadata, ) from .utils import ( @@ -262,3 +263,97 @@ def test_get_approval_toelichtingen_no_reviews(self, m): ): result = get_approval_toelichtingen(task) self.assertEqual(result, {"toelichtingen": ""}) + + def test_set_review_request_metadata(self, m): + task = ExternalTask.objects.create( + **self.task_dict, + ) + with patch( + "bptl.work_units.zgw.objects.services.fetch_review_request", + return_value=deepcopy(REVIEW_REQUEST_OBJECT), + ): + with patch( + "bptl.work_units.zgw.objects.services.update_object_record_data", + return_value=deepcopy(REVIEW_REQUEST_OBJECT), + ) as mock_update_object_record_data: + result = lock_review_request(task) + + mock_update_object_record_data.assert_called_once_with( + task, + { + "url": REVIEW_REQUEST_OBJECT["url"], + "uuid": REVIEW_REQUEST_OBJECT["uuid"], + "type": REVIEW_REQUEST_OBJECT["type"], + "record": { + "index": REVIEW_REQUEST_OBJECT["record"]["index"], + "typeVersion": REVIEW_REQUEST_OBJECT["record"]["typeVersion"], + "data": { + "created": REVIEW_REQUEST_OBJECT["record"]["data"]["created"], + "documents": REVIEW_REQUEST_OBJECT["record"]["data"][ + "documents" + ], + "id": REVIEW_REQUEST_OBJECT["record"]["data"]["id"], + "locked": True, + "lockReason": "Alle verzoeken zijn uitgevoerd.", + "metadata": REVIEW_REQUEST_OBJECT["record"]["data"]["metadata"], + "requester": REVIEW_REQUEST_OBJECT["record"]["data"][ + "requester" + ], + "toelichting": REVIEW_REQUEST_OBJECT["record"]["data"][ + "toelichting" + ], + "zaak": REVIEW_REQUEST_OBJECT["record"]["data"]["zaak"], + "zaakeigenschappen": [], + "assignedUsers": REVIEW_REQUEST_OBJECT["record"]["data"][ + "assignedUsers" + ], + "isBeingReconfigured": REVIEW_REQUEST_OBJECT["record"]["data"][ + "isBeingReconfigured" + ], + "numReviewsGivenBeforeChange": REVIEW_REQUEST_OBJECT["record"][ + "data" + ]["numReviewsGivenBeforeChange"], + "reviewType": REVIEW_REQUEST_OBJECT["record"]["data"][ + "reviewType" + ], + "userDeadlines": REVIEW_REQUEST_OBJECT["record"]["data"][ + "userDeadlines" + ], + }, + "geometry": REVIEW_REQUEST_OBJECT["record"]["geometry"], + "startAt": REVIEW_REQUEST_OBJECT["record"]["startAt"], + "endAt": REVIEW_REQUEST_OBJECT["record"]["endAt"], + "registrationAt": REVIEW_REQUEST_OBJECT["record"]["registrationAt"], + "correctionFor": REVIEW_REQUEST_OBJECT["record"]["correctionFor"], + "correctedBy": "None", + }, + }, + { + "created": REVIEW_REQUEST_OBJECT["record"]["data"]["created"], + "documents": REVIEW_REQUEST_OBJECT["record"]["data"]["documents"], + "id": REVIEW_REQUEST_OBJECT["record"]["data"]["id"], + "locked": True, + "lockReason": "Alle verzoeken zijn uitgevoerd.", + "metadata": REVIEW_REQUEST_OBJECT["record"]["data"]["metadata"], + "requester": REVIEW_REQUEST_OBJECT["record"]["data"]["requester"], + "toelichting": REVIEW_REQUEST_OBJECT["record"]["data"]["toelichting"], + "zaak": REVIEW_REQUEST_OBJECT["record"]["data"]["zaak"], + "zaakeigenschappen": [], + "assignedUsers": REVIEW_REQUEST_OBJECT["record"]["data"][ + "assignedUsers" + ], + "isBeingReconfigured": REVIEW_REQUEST_OBJECT["record"]["data"][ + "isBeingReconfigured" + ], + "numReviewsGivenBeforeChange": REVIEW_REQUEST_OBJECT["record"]["data"][ + "numReviewsGivenBeforeChange" + ], + "reviewType": REVIEW_REQUEST_OBJECT["record"]["data"]["reviewType"], + "userDeadlines": REVIEW_REQUEST_OBJECT["record"]["data"][ + "userDeadlines" + ], + }, + username=None, + ) + + self.assertEqual(result, dict())