Allow renaming published reports

This commit is contained in:
allegroai 2023-01-03 12:15:44 +02:00
parent ab798e4170
commit 22a2a02760
2 changed files with 9 additions and 10 deletions

View File

@ -80,18 +80,16 @@ def update_report(call: APICall, company_id: str, request: UpdateReportRequest):
if not partial_update_dict: if not partial_update_dict:
return UpdateResponse(updated=0) return UpdateResponse(updated=0)
tags_only = list(partial_update_dict.keys()) == ["tags"] allowed_for_published = set(partial_update_dict.keys()).issubset({"tags", "name"})
if task.status != TaskStatus.created and not tags_only: if task.status != TaskStatus.created and not allowed_for_published:
raise errors.bad_request.InvalidTaskStatus( raise errors.bad_request.InvalidTaskStatus(
expected=TaskStatus.created, status=task.status expected=TaskStatus.created, status=task.status
) )
more_updates = {} now = datetime.utcnow()
if not tags_only: more_updates = {"last_change": now, "last_changed_by": call.identity.user}
now = datetime.utcnow() if not allowed_for_published:
more_updates.update( more_updates["last_update"] = now
last_change=now, last_update=now, last_changed_by=call.identity.user
)
updated = task.update(upsert=False, **partial_update_dict, **more_updates) updated = task.update(upsert=False, **partial_update_dict, **more_updates)
if not updated: if not updated:

View File

@ -58,10 +58,11 @@ class TestReports(TestService):
with self.api.raises(errors.bad_request.InvalidTaskStatus): with self.api.raises(errors.bad_request.InvalidTaskStatus):
self.api.reports.update(task=task_id, comment=comment) self.api.reports.update(task=task_id, comment=comment)
# update on tags can be done for published report too # update on tags or rename can be done for published report too
self.api.reports.update(task=task_id, tags=["test"]) self.api.reports.update(task=task_id, name="new name", tags=["test"])
task = self.api.tasks.get_all_ex(id=[task_id]).tasks[0] task = self.api.tasks.get_all_ex(id=[task_id]).tasks[0]
self.assertEqual(task.tags, ["test"]) self.assertEqual(task.tags, ["test"])
self.assertEqual(task.name, "new name")
# move under another project autodeletes the empty project # move under another project autodeletes the empty project
new_project_name = "Reports Test" new_project_name = "Reports Test"