From 6537e9ef6954760ec7b03511f4743f08ecc3db55 Mon Sep 17 00:00:00 2001 From: allegroai <> Date: Tue, 29 Nov 2022 17:44:19 +0200 Subject: [PATCH] Add active_users and search_hidden options to get_entities_count endpoint --- apiserver/apimodels/organization.py | 2 ++ apiserver/schema/services/organization.conf | 14 +++++++++++ apiserver/services/organization.py | 26 ++++++++++++++++++--- 3 files changed, 39 insertions(+), 3 deletions(-) diff --git a/apiserver/apimodels/organization.py b/apiserver/apimodels/organization.py index 8a12101..f9b72d0 100644 --- a/apiserver/apimodels/organization.py +++ b/apiserver/apimodels/organization.py @@ -19,3 +19,5 @@ class EntitiesCountRequest(models.Base): models = DictField() pipelines = DictField() datasets = DictField() + active_users = fields.ListField(str) + search_hidden = fields.BoolField(default=False) diff --git a/apiserver/schema/services/organization.conf b/apiserver/schema/services/organization.conf index 00e72cb..b0c731a 100644 --- a/apiserver/schema/services/organization.conf +++ b/apiserver/schema/services/organization.conf @@ -162,4 +162,18 @@ get_entities_count { } } } + "2.22": ${get_entities_count."2.20"} { + request.properties { + search_hidden { + description: "If set to 'true' then hidden projects and tasks are included in the search results" + type: boolean + default: false + } + active_users { + descritpion: "The list of users that were active in the project. If passes then the resulting projects are filtered to the ones that have tasks created by these users" + type: array + items: {type: string} + } + } + } } diff --git a/apiserver/services/organization.py b/apiserver/services/organization.py index a3b13cf..b068e3e 100644 --- a/apiserver/services/organization.py +++ b/apiserver/services/organization.py @@ -6,6 +6,7 @@ from mongoengine import Q from apiserver.apimodels.organization import TagsRequest, EntitiesCountRequest from apiserver.bll.organization import OrgBLL, Tags +from apiserver.bll.project import ProjectBLL from apiserver.database.model import User, AttributedDocument, EntityVisibility from apiserver.database.model.model import Model from apiserver.database.model.project import Project @@ -14,6 +15,7 @@ from apiserver.service_repo import endpoint, APICall from apiserver.services.utils import get_tags_filter_dictionary, sort_tags_response org_bll = OrgBLL() +project_bll = ProjectBLL() @endpoint("organization.get_tags", request_data_model=TagsRequest) @@ -49,8 +51,8 @@ def get_user_companies(call: APICall, company_id: str, _): } -@endpoint("organization.get_entities_count", request_data_model=EntitiesCountRequest) -def get_entities_count(call: APICall, company, _): +@endpoint("organization.get_entities_count") +def get_entities_count(call: APICall, company, request: EntitiesCountRequest): entity_classes: Mapping[str, Type[AttributedDocument]] = { "projects": Project, "tasks": Task, @@ -64,8 +66,26 @@ def get_entities_count(call: APICall, company, _): if data is None: continue + if request.active_users: + if entity_cls is Project: + requested_ids = data.get("id") + if isinstance(requested_ids, str): + requested_ids = [requested_ids] + ids, _ = project_bll.get_projects_with_active_user( + company=company, + users=request.active_users, + project_ids=requested_ids, + allow_public=True, + ) + if not ids: + ret[field] = 0 + continue + data["id"] = ids + elif not data.get("user"): + data["user"] = request.active_users + query = Q() - if entity_cls in (Project, Task) and not data.get("search_hidden"): + if entity_cls in (Project, Task) and not request.search_hidden: query &= Q(system_tags__ne=EntityVisibility.hidden.value) ret[field] = entity_cls.get_count(