delete the draft task data when the task has been submitted (#364)

Co-authored-by: jasquat <jasquat@users.noreply.github.com>
This commit is contained in:
jasquat 2023-06-30 03:33:56 -04:00 committed by GitHub
parent e30488c95b
commit 766a7e491e
2 changed files with 27 additions and 4 deletions

View File

@ -281,12 +281,10 @@ def task_show(process_instance_id: int, task_guid: str = "next") -> flask.wrappe
try:
AuthorizationService.assert_user_can_complete_task(process_instance.id, task_model.guid, g.user)
can_complete = True
except HumanTaskNotFoundError:
can_complete = False
except UserDoesNotHaveAccessToTaskError:
except (HumanTaskNotFoundError, UserDoesNotHaveAccessToTaskError, HumanTaskAlreadyCompletedError):
can_complete = False
task_draft_data = TaskService.task_draft_data_from_task_model(task_model, create_if_not_exists=True)
task_draft_data = TaskService.task_draft_data_from_task_model(task_model)
saved_form_data = None
if task_draft_data is not None:
@ -564,6 +562,13 @@ def _task_submit_shared(
human_task=human_task,
)
# delete draft data when we submit a task to ensure cycling back to the task contains the
# most up-to-date data
task_draft_data = TaskService.task_draft_data_from_task_model(human_task.task_model)
if task_draft_data is not None:
db.session.delete(task_draft_data)
db.session.commit()
next_human_task_assigned_to_me = (
HumanTaskModel.query.filter_by(process_instance_id=process_instance_id, completed=False)
.order_by(asc(HumanTaskModel.id)) # type: ignore

View File

@ -318,3 +318,21 @@ class TestTasksController(BaseTest):
assert response.status_code == 200
assert response.json is not None
assert response.json["saved_form_data"] == draft_data
response = client.put(
f"/v1.0/tasks/{process_instance_id}/{task_id}",
headers=self.logged_in_headers(with_super_admin_user),
content_type="application/json",
data=json.dumps(draft_data),
)
assert response.status_code == 200
# ensure draft data is deleted after submitting the task
response = client.get(
f"/v1.0/tasks/{process_instance_id}/{task_id}",
headers=self.logged_in_headers(with_super_admin_user),
)
assert response.status_code == 200
assert response.json is not None
assert response.json["saved_form_data"] is None
assert response.json["data"]["HEY"] == draft_data["HEY"]