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:
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:

View File

@ -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"