Skip to content

Commit b7f39d8

Browse files
authored
[MPT-14081] Added Accounts users endpoints (#75)
Added Accounts users endpoints https://softwareone.atlassian.net/browse/MPT-14081
2 parents 7b59f65 + 813ce2f commit b7f39d8

7 files changed

Lines changed: 457 additions & 3 deletions

File tree

mpt_api_client/resources/accounts/accounts.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
from mpt_api_client.http import AsyncHTTPClient, HTTPClient
22
from mpt_api_client.resources.accounts.account import AccountsService, AsyncAccountsService
3+
from mpt_api_client.resources.accounts.users import AsyncUsersService, UsersService
34

45

56
class Accounts:
@@ -13,6 +14,11 @@ def accounts(self) -> AccountsService:
1314
"""Accounts service."""
1415
return AccountsService(http_client=self.http_client)
1516

17+
@property
18+
def users(self) -> UsersService:
19+
"""Users service."""
20+
return UsersService(http_client=self.http_client)
21+
1622

1723
class AsyncAccounts:
1824
"""Async Accounts MPT API Module."""
@@ -24,3 +30,8 @@ def __init__(self, *, http_client: AsyncHTTPClient):
2430
def accounts(self) -> AsyncAccountsService:
2531
"""Accounts service."""
2632
return AsyncAccountsService(http_client=self.http_client)
33+
34+
@property
35+
def users(self) -> AsyncUsersService:
36+
"""Users service."""
37+
return AsyncUsersService(http_client=self.http_client)

mpt_api_client/resources/accounts/mixins.py

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,32 @@ def validate(self, resource_id: str, resource_data: ResourceData | None = None)
7171
)
7272

7373

74+
class BlockableMixin[Model]:
75+
"""Blockable mixin for blocking and unblocking resources."""
76+
77+
def block(self, resource_id: str, resource_data: ResourceData | None = None) -> Model:
78+
"""Block a resource.
79+
80+
Args:
81+
resource_id: Resource ID
82+
resource_data: Resource data will be updated
83+
"""
84+
return self._resource_action( # type: ignore[attr-defined, no-any-return]
85+
resource_id, "POST", "block", json=resource_data
86+
)
87+
88+
def unblock(self, resource_id: str, resource_data: ResourceData | None = None) -> Model:
89+
"""Unblock a resource.
90+
91+
Args:
92+
resource_id: Resource ID
93+
resource_data: Resource data will be updated
94+
"""
95+
return self._resource_action( # type: ignore[attr-defined, no-any-return]
96+
resource_id, "POST", "unblock", json=resource_data
97+
)
98+
99+
74100
class AsyncActivatableMixin[Model]:
75101
"""Async activatable mixin for activating, enabling, disabling and deactivating resources."""
76102

@@ -138,3 +164,29 @@ async def validate(self, resource_id: str, resource_data: ResourceData | None =
138164
return await self._resource_action( # type: ignore[attr-defined, no-any-return]
139165
resource_id, "POST", "validate", json=resource_data
140166
)
167+
168+
169+
class AsyncBlockableMixin[Model]:
170+
"""Asynchronous Blockable mixin for blocking and unblocking resources."""
171+
172+
async def block(self, resource_id: str, resource_data: ResourceData | None = None) -> Model:
173+
"""Block a resource.
174+
175+
Args:
176+
resource_id: Resource ID
177+
resource_data: Resource data will be updated
178+
"""
179+
return await self._resource_action( # type: ignore[attr-defined, no-any-return]
180+
resource_id, "POST", "block", json=resource_data
181+
)
182+
183+
async def unblock(self, resource_id: str, resource_data: ResourceData | None = None) -> Model:
184+
"""Unblock a resource.
185+
186+
Args:
187+
resource_id: Resource ID
188+
resource_data: Resource data will be updated
189+
"""
190+
return await self._resource_action( # type: ignore[attr-defined, no-any-return]
191+
resource_id, "POST", "unblock", json=resource_data
192+
)
Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
from mpt_api_client.http import AsyncService, Service
2+
from mpt_api_client.http.mixins import (
3+
AsyncDeleteMixin,
4+
AsyncUpdateMixin,
5+
DeleteMixin,
6+
UpdateMixin,
7+
)
8+
from mpt_api_client.models import Model
9+
from mpt_api_client.models.model import ResourceData
10+
from mpt_api_client.resources.accounts.mixins import (
11+
AsyncBlockableMixin,
12+
BlockableMixin,
13+
)
14+
15+
16+
class User(Model):
17+
"""User resource."""
18+
19+
20+
class UsersServiceConfig:
21+
"""Users service configuration."""
22+
23+
_endpoint = "/public/v1/accounts/users"
24+
_model_class = User
25+
_collection_key = "data"
26+
27+
28+
class UsersService(
29+
UpdateMixin[User],
30+
DeleteMixin,
31+
BlockableMixin[User],
32+
Service[User],
33+
UsersServiceConfig,
34+
):
35+
"""Users service."""
36+
37+
def sso(self, resource_id: str, resource_data: ResourceData | None = None) -> User:
38+
"""Perform SSO action for a user.
39+
40+
Args:
41+
resource_id: Resource ID
42+
resource_data: Resource data will be updated
43+
"""
44+
return self._resource_action(resource_id, "POST", "sso", json=resource_data)
45+
46+
def sso_check(self, resource_id: str, resource_data: ResourceData | None = None) -> User:
47+
"""Perform SSO check action for a user.
48+
49+
Args:
50+
resource_id: Resource ID
51+
resource_data: Resource data will be updated
52+
"""
53+
return self._resource_action(resource_id, "POST", "sso-check", json=resource_data)
54+
55+
56+
class AsyncUsersService(
57+
AsyncUpdateMixin[User],
58+
AsyncDeleteMixin,
59+
AsyncBlockableMixin[User],
60+
AsyncService[User],
61+
UsersServiceConfig,
62+
):
63+
"""Async Users service."""
64+
65+
async def sso(self, resource_id: str, resource_data: ResourceData | None = None) -> User:
66+
"""Perform SSO action for a user.
67+
68+
Args:
69+
resource_id: Resource ID
70+
resource_data: Resource data will be updated
71+
"""
72+
return await self._resource_action(resource_id, "POST", "sso", json=resource_data)
73+
74+
async def sso_check(self, resource_id: str, resource_data: ResourceData | None = None) -> User:
75+
"""Perform SSO check action for a user.
76+
77+
Args:
78+
resource_id: Resource ID
79+
resource_data: Resource data will be updated
80+
"""
81+
return await self._resource_action(resource_id, "POST", "sso-check", json=resource_data)

setup.cfg

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,10 @@ extend-ignore =
3232

3333

3434
per-file-ignores =
35-
3635
mpt_api_client/mpt_client.py: WPS214 WPS235
3736
mpt_api_client/http/mixins.py: WPS202
3837
mpt_api_client/resources/*: WPS215
38+
mpt_api_client/resources/accounts/*.py: WPS202 WPS215
3939
mpt_api_client/resources/billing/*.py: WPS202 WPS204 WPS214 WPS215
4040
mpt_api_client/resources/catalog/*.py: WPS110 WPS214 WPS215
4141
mpt_api_client/resources/catalog/products.py: WPS204 WPS214 WPS215

tests/resources/accounts/test_accounts.py

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
from mpt_api_client.resources.accounts.account import AccountsService, AsyncAccountsService
44
from mpt_api_client.resources.accounts.accounts import Accounts, AsyncAccounts
5+
from mpt_api_client.resources.accounts.users import AsyncUsersService, UsersService
56

67

78
@pytest.fixture
@@ -15,7 +16,11 @@ def async_accounts(async_http_client):
1516

1617

1718
@pytest.mark.parametrize(
18-
("property_name", "expected_service_class"), [("accounts", AccountsService)]
19+
("property_name", "expected_service_class"),
20+
[
21+
("accounts", AccountsService),
22+
("users", UsersService),
23+
],
1924
)
2025
def test_accounts_properties(accounts, property_name, expected_service_class):
2126
"""Test that Accounts properties return correct instances."""
@@ -26,7 +31,11 @@ def test_accounts_properties(accounts, property_name, expected_service_class):
2631

2732

2833
@pytest.mark.parametrize(
29-
("property_name", "expected_service_class"), [("accounts", AsyncAccountsService)]
34+
("property_name", "expected_service_class"),
35+
[
36+
("accounts", AsyncAccountsService),
37+
("users", AsyncUsersService),
38+
],
3039
)
3140
def test_async_accounts_properties(async_accounts, property_name, expected_service_class):
3241
"""Test that AsyncAccounts properties return correct instances."""

0 commit comments

Comments
 (0)