From f110eb0ea864a7115f7ed1d24e868aafb6c038f2 Mon Sep 17 00:00:00 2001 From: Wiktork Date: Wed, 22 Feb 2023 11:10:34 +0100 Subject: [PATCH] fix(tracking): fix automatic unreject when bulk updating Unreject reports when task has changed while bulk updating. --- timed/tracking/tests/test_report.py | 32 +++++++++++++++++++++++++++++ timed/tracking/views.py | 8 +++++--- 2 files changed, 37 insertions(+), 3 deletions(-) diff --git a/timed/tracking/tests/test_report.py b/timed/tracking/tests/test_report.py index 760ccd3b..2cbe0b41 100644 --- a/timed/tracking/tests/test_report.py +++ b/timed/tracking/tests/test_report.py @@ -1810,6 +1810,38 @@ def test_report_automatic_unreject(internal_employee_client, report_factory, tas assert not report.rejected +def test_report_bulk_automatic_unreject( + internal_employee_client, user_factory, report_factory, task +): + reviewer = internal_employee_client.user + + user = user_factory.create() + + report = report_factory.create(user=user, rejected=True) + ProjectAssigneeFactory.create( + user=reviewer, project=report.task.project, is_reviewer=True + ) + + url = reverse("report-bulk") + + data = { + "data": { + "type": "report-bulks", + "id": None, + "relationships": { + "task": {"data": {"type": "tasks", "id": task.id}}, + }, + } + } + + query_params = f"?editable=1&reviewer={reviewer.id}&id={report.id}" + response = internal_employee_client.post(url + query_params, data) + assert response.status_code == status.HTTP_204_NO_CONTENT + + report.refresh_from_db() + assert not report.rejected + + @pytest.mark.parametrize( "is_external, remaining_effort_active, is_superuser, expected", [ diff --git a/timed/tracking/views.py b/timed/tracking/views.py index 46bca34d..a2131842 100644 --- a/timed/tracking/views.py +++ b/timed/tracking/views.py @@ -263,16 +263,18 @@ def bulk(self, request): ) if "task" in fields: + # unreject report if task has changed + fields["rejected"] = False if fields["task"].project.billed: fields["billed"] = fields["task"].project.billed if fields: - if "rejected" in fields: + # send notification if report was rejected + if fields.get("rejected"): tasks.notify_user_rejected_reports(queryset, fields, user) - queryset.update(**fields) else: tasks.notify_user_changed_reports(queryset, fields, user) - queryset.update(**fields) + queryset.update(**fields) return Response(status=status.HTTP_204_NO_CONTENT)