diff --git a/apiserver/services/reports.py b/apiserver/services/reports.py index f6ace6b..1bf2b89 100644 --- a/apiserver/services/reports.py +++ b/apiserver/services/reports.py @@ -80,18 +80,16 @@ def update_report(call: APICall, company_id: str, request: UpdateReportRequest): if not partial_update_dict: return UpdateResponse(updated=0) - tags_only = list(partial_update_dict.keys()) == ["tags"] - if task.status != TaskStatus.created and not tags_only: + allowed_for_published = set(partial_update_dict.keys()).issubset({"tags", "name"}) + if task.status != TaskStatus.created and not allowed_for_published: raise errors.bad_request.InvalidTaskStatus( expected=TaskStatus.created, status=task.status ) - more_updates = {} - if not tags_only: - now = datetime.utcnow() - more_updates.update( - last_change=now, last_update=now, last_changed_by=call.identity.user - ) + now = datetime.utcnow() + more_updates = {"last_change": now, "last_changed_by": call.identity.user} + if not allowed_for_published: + more_updates["last_update"] = now updated = task.update(upsert=False, **partial_update_dict, **more_updates) if not updated: diff --git a/apiserver/tests/automated/test_reports.py b/apiserver/tests/automated/test_reports.py index e3d44b8..a007a07 100644 --- a/apiserver/tests/automated/test_reports.py +++ b/apiserver/tests/automated/test_reports.py @@ -58,10 +58,11 @@ class TestReports(TestService): with self.api.raises(errors.bad_request.InvalidTaskStatus): self.api.reports.update(task=task_id, comment=comment) - # update on tags can be done for published report too - self.api.reports.update(task=task_id, tags=["test"]) + # update on tags or rename can be done for published report too + self.api.reports.update(task=task_id, name="new name", tags=["test"]) task = self.api.tasks.get_all_ex(id=[task_id]).tasks[0] self.assertEqual(task.tags, ["test"]) + self.assertEqual(task.name, "new name") # move under another project autodeletes the empty project new_project_name = "Reports Test"