mirror of
https://github.com/clearml/clearml-server
synced 2025-02-07 13:33:42 +00:00
Add active_users and search_hidden options to get_entities_count endpoint
This commit is contained in:
parent
930aaff791
commit
6537e9ef69
@ -19,3 +19,5 @@ class EntitiesCountRequest(models.Base):
|
|||||||
models = DictField()
|
models = DictField()
|
||||||
pipelines = DictField()
|
pipelines = DictField()
|
||||||
datasets = DictField()
|
datasets = DictField()
|
||||||
|
active_users = fields.ListField(str)
|
||||||
|
search_hidden = fields.BoolField(default=False)
|
||||||
|
@ -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}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -6,6 +6,7 @@ from mongoengine import Q
|
|||||||
|
|
||||||
from apiserver.apimodels.organization import TagsRequest, EntitiesCountRequest
|
from apiserver.apimodels.organization import TagsRequest, EntitiesCountRequest
|
||||||
from apiserver.bll.organization import OrgBLL, Tags
|
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 import User, AttributedDocument, EntityVisibility
|
||||||
from apiserver.database.model.model import Model
|
from apiserver.database.model.model import Model
|
||||||
from apiserver.database.model.project import Project
|
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
|
from apiserver.services.utils import get_tags_filter_dictionary, sort_tags_response
|
||||||
|
|
||||||
org_bll = OrgBLL()
|
org_bll = OrgBLL()
|
||||||
|
project_bll = ProjectBLL()
|
||||||
|
|
||||||
|
|
||||||
@endpoint("organization.get_tags", request_data_model=TagsRequest)
|
@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)
|
@endpoint("organization.get_entities_count")
|
||||||
def get_entities_count(call: APICall, company, _):
|
def get_entities_count(call: APICall, company, request: EntitiesCountRequest):
|
||||||
entity_classes: Mapping[str, Type[AttributedDocument]] = {
|
entity_classes: Mapping[str, Type[AttributedDocument]] = {
|
||||||
"projects": Project,
|
"projects": Project,
|
||||||
"tasks": Task,
|
"tasks": Task,
|
||||||
@ -64,8 +66,26 @@ def get_entities_count(call: APICall, company, _):
|
|||||||
if data is None:
|
if data is None:
|
||||||
continue
|
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()
|
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)
|
query &= Q(system_tags__ne=EntityVisibility.hidden.value)
|
||||||
|
|
||||||
ret[field] = entity_cls.get_count(
|
ret[field] = entity_cls.get_count(
|
||||||
|
Loading…
Reference in New Issue
Block a user