Skip to content
This repository has been archived by the owner on May 13, 2024. It is now read-only.

Commit

Permalink
fix(tracking): fix automatic unreject when bulk updating
Browse files Browse the repository at this point in the history
Unreject reports when task has changed while bulk updating.
  • Loading branch information
trowik committed Feb 24, 2023
1 parent 2151dd9 commit f110eb0
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 3 deletions.
32 changes: 32 additions & 0 deletions timed/tracking/tests/test_report.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
[
Expand Down
8 changes: 5 additions & 3 deletions timed/tracking/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down

0 comments on commit f110eb0

Please sign in to comment.