-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathusers.py
More file actions
113 lines (90 loc) · 3.23 KB
/
users.py
File metadata and controls
113 lines (90 loc) · 3.23 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
from mpt_api_client.http import AsyncService, Service
from mpt_api_client.http.mixins import (
AsyncCollectionMixin,
AsyncDeleteMixin,
AsyncGetMixin,
AsyncUpdateFileMixin,
CollectionMixin,
DeleteMixin,
GetMixin,
UpdateFileMixin,
)
from mpt_api_client.models import Model
from mpt_api_client.models.model import ResourceData
from mpt_api_client.resources.accounts.mixins import (
AsyncBlockableMixin,
BlockableMixin,
)
class User(Model):
"""User resource."""
class UsersServiceConfig:
"""Users service configuration."""
_endpoint = "/public/v1/accounts/users"
_model_class = User
_collection_key = "data"
_upload_file_key = "icon"
_upload_data_key = "user"
class UsersService(
UpdateFileMixin[User],
DeleteMixin,
BlockableMixin[User],
GetMixin[User],
CollectionMixin[User],
Service[User],
UsersServiceConfig,
):
"""Users service."""
def sso(self, resource_id: str, resource_data: ResourceData | None = None) -> User:
"""Perform SSO action for a user.
Args:
resource_id: Resource ID
resource_data: Resource data will be updated
"""
return self._resource_action(resource_id, "POST", "sso", json=resource_data)
def sso_check(self, resource_id: str, resource_data: ResourceData | None = None) -> User:
"""Perform SSO check action for a user.
Args:
resource_id: Resource ID
resource_data: Resource data will be updated
"""
return self._resource_action(resource_id, "POST", "sso-check", json=resource_data)
def set_password(self, resource_id: str, password: str) -> User:
"""Set password for a user.
Args:
resource_id: Resource ID
password: New password
"""
resource_data = {"password": password}
return self._resource_action(resource_id, "POST", "set-password", json=resource_data)
class AsyncUsersService(
AsyncUpdateFileMixin[User],
AsyncDeleteMixin,
AsyncBlockableMixin[User],
AsyncGetMixin[User],
AsyncCollectionMixin[User],
AsyncService[User],
UsersServiceConfig,
):
"""Async Users service."""
async def sso(self, resource_id: str, resource_data: ResourceData | None = None) -> User:
"""Perform SSO action for a user.
Args:
resource_id: Resource ID
resource_data: Resource data will be updated
"""
return await self._resource_action(resource_id, "POST", "sso", json=resource_data)
async def sso_check(self, resource_id: str, resource_data: ResourceData | None = None) -> User:
"""Perform SSO check action for a user.
Args:
resource_id: Resource ID
resource_data: Resource data will be updated
"""
return await self._resource_action(resource_id, "POST", "sso-check", json=resource_data)
async def set_password(self, resource_id: str, password: str) -> User:
"""Set password for a user.
Args:
resource_id: Resource ID
password: New password
"""
resource_data = {"password": password}
return await self._resource_action(resource_id, "POST", "set-password", json=resource_data)