Skip to content

Commit 1476262

Browse files
Narek MkhitaryanNarek Mkhitaryan
authored andcommitted
added get_user_metadata (draft)
1 parent d342cd9 commit 1476262

File tree

6 files changed

+67
-2
lines changed

6 files changed

+67
-2
lines changed

docs/source/api_reference/api_team.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,4 @@ Team
77
.. automethod:: superannotate.SAClient.get_integrations
88
.. automethod:: superannotate.SAClient.invite_contributors_to_team
99
.. automethod:: superannotate.SAClient.search_team_contributors
10+
.. automethod:: superannotate.SAClient.get_user_metadata

src/superannotate/lib/app/interface/sdk_interface.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -279,6 +279,29 @@ def get_team_metadata(self):
279279
response = self.controller.get_team()
280280
return TeamSerializer(response.data).serialize()
281281

282+
def get_user_metadata(
283+
self, pk: Union[str, int], include: List[Literal["custom_fields"]] = None
284+
):
285+
"""
286+
Returns team contributor metadata
287+
288+
:param pk: The email address or ID of the team contributor.
289+
:type pk: str or int
290+
291+
:param include: Specifies additional fields to include in the response.
292+
293+
Possible values are
294+
295+
- "custom_fields": whether to include custom fields that have been created for the team user.
296+
297+
:type include: list of str, optional
298+
299+
:return: metadata of team contributor
300+
:rtype: dict
301+
"""
302+
response = self.controller.get_user_metadata()
303+
return TeamSerializer(response.data).serialize()
304+
282305
def get_component_config(self, project: Union[NotEmptyStr, int], component_id: str):
283306
"""
284307
Retrieves the configuration for a given project and component ID.
@@ -3088,6 +3111,7 @@ def list_projects(
30883111
- status__in: List[Literal[“NotStarted”, “InProgress”, “Completed”, “OnHold”]]
30893112
- status__notin: List[Literal[“NotStarted”, “InProgress”, “Completed”, “OnHold”]]
30903113
- custom_field: Optional[dict] – Specifies custom fields attributes to filter projects by.
3114+
30913115
Custom fields can be accessed using the `custom_field__` prefix followed by the attribute name.
30923116
30933117
:type filters: ProjectFilters

src/superannotate/lib/core/entities/work_managament.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,3 +87,14 @@ def json(self, **kwargs):
8787
if "exclude" not in kwargs:
8888
kwargs["exclude"] = {"custom_fields"}
8989
return super().json(**kwargs)
90+
91+
92+
class UserEntity(TimedBaseModel):
93+
id: Optional[str]
94+
first_name: Optional[str]
95+
last_name: Optional[str]
96+
email: Optional[str]
97+
user_role: Optional[int]
98+
99+
class Config:
100+
extra = Extra.ignore

src/superannotate/lib/core/service_types.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
from lib.core import entities
88
from lib.core.entities.work_managament import WMProjectEntity
9+
from lib.core.entities.work_managament import WMUserEntity
910
from lib.core.enums import ProjectType
1011
from lib.core.exceptions import AppException
1112
from lib.core.pydantic_v1 import BaseModel
@@ -247,6 +248,10 @@ class WMProjectListResponse(ServiceResponse):
247248
res_data: List[WMProjectEntity] = None
248249

249250

251+
class WMUserListResponse(ServiceResponse):
252+
res_data: List[WMUserEntity] = None
253+
254+
250255
class SettingsListResponse(ServiceResponse):
251256
res_data: List[entities.SettingEntity] = None
252257

src/superannotate/lib/infrastructure/controller.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1362,6 +1362,11 @@ def search_team_contributors(self, **kwargs):
13621362
)
13631363
return use_case.execute()
13641364

1365+
def get_user_metadata(
1366+
self, pk: Union[str, int], include: List[Literal["custom_fields"]] = None
1367+
):
1368+
self.service_provider.work_management.list_projects()
1369+
13651370
def _get_image(
13661371
self,
13671372
project: ProjectEntity,

src/superannotate/lib/infrastructure/services/work_management.py

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
from lib.core.service_types import ListCategoryResponse
1313
from lib.core.service_types import ServiceResponse
1414
from lib.core.service_types import WMProjectListResponse
15+
from lib.core.service_types import WMUserListResponse
1516
from lib.core.serviceproviders import BaseWorkManagementService
1617

1718

@@ -27,7 +28,7 @@ class WorkManagementService(BaseWorkManagementService):
2728
URL_CUSTOM_FIELD_TEMPLATES = "customfieldtemplates"
2829
URL_CUSTOM_FIELD_TEMPLATE_DELETE = "customfieldtemplates/{template_id}"
2930
URL_PROJECT_CUSTOM_ENTITIES = "customentities/{project_id}"
30-
LIST_PROJECTS = "customentities/search"
31+
SEARCH_CUSTOM_ENTITIES = "customentities/search"
3132

3233
@staticmethod
3334
def _generate_context(**kwargs):
@@ -214,7 +215,7 @@ def set_project_custom_field_value(self, project_id: int, data: dict):
214215

215216
def list_projects(self, body_query: Query, chunk_size=100) -> WMProjectListResponse:
216217
return self.client.jsx_paginate(
217-
url=self.LIST_PROJECTS,
218+
url=self.SEARCH_CUSTOM_ENTITIES,
218219
method="post",
219220
body_query=body_query,
220221
query_params={
@@ -229,3 +230,21 @@ def list_projects(self, body_query: Query, chunk_size=100) -> WMProjectListRespo
229230
chunk_size=chunk_size,
230231
item_type=WMProjectEntity,
231232
)
233+
234+
def list_users(self, body_query: Query, chunk_size=100) -> WMUserListResponse:
235+
return self.client.jsx_paginate(
236+
url=self.SEARCH_CUSTOM_ENTITIES,
237+
method="post",
238+
body_query=body_query,
239+
query_params={
240+
"entity": "Contributor",
241+
"parentEntity": "Team",
242+
},
243+
headers={
244+
"x-sa-entity-context": self._generate_context(
245+
team_id=self.client.team_id
246+
),
247+
},
248+
chunk_size=chunk_size,
249+
item_type=WMProjectEntity,
250+
)

0 commit comments

Comments
 (0)