diff --git a/huntflow_api_client/entities/users_management.py b/huntflow_api_client/entities/users_management.py index 5e50d7e..5b4b904 100644 --- a/huntflow_api_client/entities/users_management.py +++ b/huntflow_api_client/entities/users_management.py @@ -1,6 +1,7 @@ -from typing import Any, Dict, Optional +from typing import Any, Dict, List, Optional from huntflow_api_client.entities.base import BaseEntity +from huntflow_api_client.models.consts import MemberType from huntflow_api_client.models.request.users_management import ForeignUserRequest from huntflow_api_client.models.response.users_management import ( CreatedUserControlTaskResponse, @@ -15,6 +16,7 @@ class UsersManagement(BaseEntity): async def get_users_with_foreign( self, account_id: int, + member_types: Optional[List[MemberType]] = None, count: Optional[int] = 30, page: Optional[int] = 1, ) -> ForeignUsersListResponse: @@ -23,6 +25,7 @@ async def get_users_with_foreign( https://api.huntflow.ai/v2/docs#get-/accounts/-account_id-/users/foreign :param account_id: Organization ID + :param member_types: Array of member types :param count: Number of items per page :param page: Page number @@ -32,6 +35,8 @@ async def get_users_with_foreign( All identifiers in response are foreign. """ params: Dict[str, Any] = {"count": count, "page": page} + if member_types: + params["member_types"] = [member_type.value for member_type in member_types] response = await self._api.request( "GET", f"/accounts/{account_id}/users/foreign", diff --git a/pyproject.toml b/pyproject.toml index f62ac8b..6335b2d 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,7 +1,7 @@ [project] name = "huntflow-api-client" -version = "2.1.0" +version = "2.2.0" description = "Huntflow API Client for Python" authors = [ {name = "Developers huntflow", email = "developer@huntflow.ru"}, diff --git a/tests/test_entities/test_users_management.py b/tests/test_entities/test_users_management.py index 7340819..72cbf75 100644 --- a/tests/test_entities/test_users_management.py +++ b/tests/test_entities/test_users_management.py @@ -37,6 +37,34 @@ }, ], } +GET_USERS_RESPONSE_TWO_MEMBERS: Dict[str, Any] = { + "page": 1, + "count": 30, + "total_pages": 1, + "total_items": 2, + "items": [ + { + "id": "some_foreign_id_1", + "name": "John Doe", + "email": "mail@gmail.com", + "type": "owner", + "head_id": "user-032044", + "division_ids": ["division-154", "division-871"], + "permissions": ["string"], + "meta": {}, + }, + { + "id": "some_foreign_id_2", + "name": "Nick Smith", + "email": "mail@example.com", + "type": "manager", + "head_id": "user-1234", + "division_ids": ["division-123", "division-321"], + "permissions": ["string"], + "meta": {}, + }, + ], +} GET_USER_BY_FOREIGN_RESPONSE: Dict[str, Any] = { "id": FOREIGN_USER_ID, "name": "John Doe", @@ -75,15 +103,33 @@ async def test_get_users_with_foreign( token_proxy: HuntflowTokenProxy, ) -> None: httpx_mock.add_response( - url=f"{VERSIONED_BASE_URL}/accounts/{ACCOUNT_ID}/users/foreign?count=30&page=1", + url=f"{VERSIONED_BASE_URL}/accounts/{ACCOUNT_ID}/users/" + f"foreign?count=30&page=1&member_types=owner", json=GET_USERS_RESPONSE, ) api_client = HuntflowAPI(BASE_URL, token_proxy=token_proxy) users_management = UsersManagement(api_client) - response = await users_management.get_users_with_foreign(account_id=ACCOUNT_ID) + response = await users_management.get_users_with_foreign( + account_id=ACCOUNT_ID, + member_types=[MemberType.owner], + ) assert response == ForeignUsersListResponse(**GET_USERS_RESPONSE) + httpx_mock.add_response( + url=f"{VERSIONED_BASE_URL}/accounts/{ACCOUNT_ID}/users/" + f"foreign?count=30&page=1&member_types=owner&member_types=manager", + json=GET_USERS_RESPONSE_TWO_MEMBERS, + ) + api_client = HuntflowAPI(BASE_URL, token_proxy=token_proxy) + users_management = UsersManagement(api_client) + + response = await users_management.get_users_with_foreign( + account_id=ACCOUNT_ID, + member_types=[MemberType.owner, MemberType.manager], + ) + assert response == ForeignUsersListResponse(**GET_USERS_RESPONSE_TWO_MEMBERS) + async def test_get_user_by_foreign( httpx_mock: HTTPXMock,