mirror of
https://github.com/clearml/clearml-server
synced 2025-03-12 14:59:22 +00:00
Support reports from the root project in reports.get_all_ex
This commit is contained in:
parent
875f4b9536
commit
5449b332d2
@ -951,9 +951,7 @@ class ProjectBLL:
|
|||||||
)
|
)
|
||||||
|
|
||||||
res = (
|
res = (
|
||||||
{p.id for p in Project.objects(project_query).only("id")}
|
set(Project.objects(project_query).scalar("id")) if project_query else set()
|
||||||
if project_query
|
|
||||||
else set()
|
|
||||||
)
|
)
|
||||||
for cls_, query_ in child_queries.items():
|
for cls_, query_ in child_queries.items():
|
||||||
res |= set(
|
res |= set(
|
||||||
|
@ -144,8 +144,8 @@ def _ids_with_children(project_ids: Sequence[str]) -> Sequence[str]:
|
|||||||
"""
|
"""
|
||||||
Return project ids with the ids of all the subprojects
|
Return project ids with the ids of all the subprojects
|
||||||
"""
|
"""
|
||||||
subprojects = Project.objects(path__in=project_ids).only("id")
|
children_ids = Project.objects(path__in=project_ids).scalar("id")
|
||||||
return list({*project_ids, *(child.id for child in subprojects)})
|
return list({*project_ids, *children_ids})
|
||||||
|
|
||||||
|
|
||||||
def _update_subproject_names(
|
def _update_subproject_names(
|
||||||
|
@ -171,9 +171,19 @@ def _delete_reports_project_if_empty(project_id):
|
|||||||
def get_all_ex(call: APICall, company_id, request: GetAllRequest):
|
def get_all_ex(call: APICall, company_id, request: GetAllRequest):
|
||||||
call_data = call.data
|
call_data = call.data
|
||||||
call_data["type"] = TaskType.report
|
call_data["type"] = TaskType.report
|
||||||
call_data["include_subprojects"] = True
|
|
||||||
|
|
||||||
process_include_subprojects(call_data)
|
# bring projects one level down in case not the .reports project was passed
|
||||||
|
if "project" in call_data:
|
||||||
|
project_ids = call_data["project"]
|
||||||
|
if not isinstance(project_ids, list):
|
||||||
|
project_ids = [project_ids]
|
||||||
|
call_data["project"] = [
|
||||||
|
*project_ids,
|
||||||
|
*Project.objects(
|
||||||
|
parent__in=project_ids, basename=reports_project_name
|
||||||
|
).scalar("id"),
|
||||||
|
]
|
||||||
|
|
||||||
ret_params = {}
|
ret_params = {}
|
||||||
tasks = Task.get_many_with_join(
|
tasks = Task.get_many_with_join(
|
||||||
company=company_id,
|
company=company_id,
|
||||||
|
@ -96,6 +96,44 @@ class TestReports(TestService):
|
|||||||
self.assertEqual(project.get("parent"), None)
|
self.assertEqual(project.get("parent"), None)
|
||||||
self.assertEqual(project.name, ".reports")
|
self.assertEqual(project.name, ".reports")
|
||||||
|
|
||||||
|
def test_root_reports(self):
|
||||||
|
root_report = self._temp_report(name="Rep1")
|
||||||
|
project_name = "Test reports"
|
||||||
|
project = self._temp_project(name=project_name)
|
||||||
|
project_report = self._temp_report(name="Rep2", project=project)
|
||||||
|
|
||||||
|
projects = self.api.projects.get_all_ex(
|
||||||
|
name=r"^\.reports$",
|
||||||
|
children_type="report",
|
||||||
|
include_stats=True,
|
||||||
|
check_own_contents=True,
|
||||||
|
search_hidden=True,
|
||||||
|
).projects
|
||||||
|
self.assertEqual(len(projects), 1)
|
||||||
|
p = projects[0]
|
||||||
|
self.assertEqual(p.name, ".reports")
|
||||||
|
self.assertEqual(p.own_tasks, 1)
|
||||||
|
|
||||||
|
projects = self.api.projects.get_all_ex(
|
||||||
|
name=rf"^{project_name}/\.reports$",
|
||||||
|
children_type="report",
|
||||||
|
include_stats=True,
|
||||||
|
check_own_contents=True,
|
||||||
|
search_hidden=True,
|
||||||
|
).projects
|
||||||
|
self.assertEqual(len(projects), 1)
|
||||||
|
p = projects[0]
|
||||||
|
self.assertEqual(p.name, f"{project_name}/.reports")
|
||||||
|
self.assertEqual(p.own_tasks, 1)
|
||||||
|
|
||||||
|
reports = self.api.reports.get_all_ex().tasks
|
||||||
|
self.assertTrue({root_report, project_report}.issubset({r.id for r in reports}))
|
||||||
|
reports = self.api.reports.get_all_ex(project=project).tasks
|
||||||
|
self.assertEqual([project_report], [r.id for r in reports])
|
||||||
|
reports = self.api.reports.get_all_ex(project=[None]).tasks
|
||||||
|
self.assertIn(root_report, {r.id for r in reports})
|
||||||
|
self.assertNotIn(project_report, {r.id for r in reports})
|
||||||
|
|
||||||
def test_reports_search(self):
|
def test_reports_search(self):
|
||||||
report_task = self._temp_report(name="Rep1")
|
report_task = self._temp_report(name="Rep1")
|
||||||
non_report_task = self._temp_task(name="hello")
|
non_report_task = self._temp_task(name="hello")
|
||||||
@ -236,6 +274,15 @@ class TestReports(TestService):
|
|||||||
|
|
||||||
delete_params = {"force": True}
|
delete_params = {"force": True}
|
||||||
|
|
||||||
|
def _temp_project(self, name, **kwargs):
|
||||||
|
return self.create_temp(
|
||||||
|
"projects",
|
||||||
|
delete_params=self.delete_params,
|
||||||
|
name=name,
|
||||||
|
description="",
|
||||||
|
**kwargs,
|
||||||
|
)
|
||||||
|
|
||||||
def _temp_report(self, name, **kwargs):
|
def _temp_report(self, name, **kwargs):
|
||||||
return self.create_temp(
|
return self.create_temp(
|
||||||
"reports",
|
"reports",
|
||||||
|
Loading…
Reference in New Issue
Block a user