Fix projects own_tasks does not take task state filter into account

This commit is contained in:
allegroai 2023-05-25 19:32:52 +03:00
parent d9579891c8
commit 741fa84b52
3 changed files with 17 additions and 1 deletions

View File

@ -1146,6 +1146,7 @@ class ProjectBLL:
company: str, company: str,
project_ids: Sequence[str], project_ids: Sequence[str],
filter_: Mapping[str, Any] = None, filter_: Mapping[str, Any] = None,
specific_state: Optional[EntityVisibility] = None,
users: Sequence[str] = None, users: Sequence[str] = None,
) -> Dict[str, dict]: ) -> Dict[str, dict]:
""" """
@ -1156,6 +1157,20 @@ class ProjectBLL:
if not project_ids: if not project_ids:
return {} return {}
if specific_state:
filter_ = filter_ or {}
system_tags_filter = filter_.get("system_tags", [])
archived = EntityVisibility.archived.value
non_archived = f"-{EntityVisibility.archived.value}"
if not any(t in system_tags_filter for t in (archived, non_archived)):
filter_ = {k: v for k, v in filter_.items()}
filter_["system_tags"] = [
archived
if specific_state == EntityVisibility.archived
else non_archived,
*system_tags_filter,
]
pipeline = [ pipeline = [
{ {
"$match": cls.get_match_conditions( "$match": cls.get_match_conditions(

View File

@ -201,6 +201,7 @@ def get_all_ex(call: APICall, company_id: str, request: ProjectsGetRequest):
company=company_id, company=company_id,
project_ids=project_ids, project_ids=project_ids,
filter_=stats_filter, filter_=stats_filter,
specific_state=request.stats_for_state,
users=request.active_users, users=request.active_users,
) )

View File

@ -348,7 +348,7 @@ class TestSubProjects(TestService):
id=[project1, project2], check_own_contents=True id=[project1, project2], check_own_contents=True
).projects ).projects
res1 = next(p for p in res if p.id == project1) res1 = next(p for p in res if p.id == project1)
self.assertEqual(res1.own_tasks, 2) self.assertEqual(res1.own_tasks, 1)
self.assertEqual(res1.own_models, 1) self.assertEqual(res1.own_models, 1)
res2 = next(p for p in res if p.id == project2) res2 = next(p for p in res if p.id == project2)