1+ import warnings
12from typing import List , Optional
23
34from thehive4py .endpoints ._base import EndpointBase
1516
1617
1718class UserEndpoint (EndpointBase ):
19+ def get_current (self ) -> OutputUser :
20+ """Get the current session's user.
21+
22+ Returns:
23+ The current session user.
24+ """
25+ return self ._session .make_request ("GET" , path = "/api/v1/user/current" )
26+
1827 def create (self , user : InputUser ) -> OutputUser :
28+ """Create a user.
29+
30+ Args:
31+ user: The body of the user.
32+
33+ Returns:
34+ The created user.
35+ """
1936 return self ._session .make_request ("POST" , path = "/api/v1/user" , json = user )
2037
2138 def get (self , user_id : str ) -> OutputUser :
39+ """Get a user by id.
40+
41+ Args:
42+ user_id: The id of the user.
43+
44+ Returns:
45+ The user specified by the id.
46+ """
2247 return self ._session .make_request ("GET" , path = f"/api/v1/user/{ user_id } " )
2348
24- def get_current (self ) -> OutputUser :
25- return self . _session . make_request ( "GET" , path = "/api/v1/ user/current" )
49+ def lock (self , user_id : str ) -> None :
50+ """Lock a user.
2651
27- def delete (self , user_id : str , organisation : Optional [str ] = None ) -> None :
28- return self ._session .make_request (
29- "DELETE" ,
30- path = f"/api/v1/user/{ user_id } /force" ,
31- params = {"organisation" : organisation },
52+ !!! warning
53+ Deprecated: use the generic [user.update]
54+ [thehive4py.endpoints.user.UserEndpoint.update] method
55+ to set the `locked` field to `True`
56+
57+ Args:
58+ user_id: The id of the user.
59+
60+ Returns:
61+ N/A
62+ """
63+ warnings .warn (
64+ message = (
65+ "Deprecated: use the generic user.update method to "
66+ "set the `locked` field to True"
67+ ),
68+ category = DeprecationWarning ,
69+ stacklevel = 2 ,
3270 )
71+ return self .update (user_id = user_id , fields = {"locked" : True })
72+
73+ def unlock (self , user_id : str ) -> None :
74+ """Unlock a user.
75+
76+ !!! warning
77+ Deprecated: use the generic [user.update]
78+ [thehive4py.endpoints.user.UserEndpoint.update] method
79+ to set the `locked` field to `False`
80+
81+ Args:
82+ user_id: The id of the user.
83+
84+ Returns:
85+ N/A
86+ """
87+ warnings .warn (
88+ message = (
89+ "Deprecated: use the generic user.update method to "
90+ "set the `locked` field to False"
91+ ),
92+ category = DeprecationWarning ,
93+ stacklevel = 2 ,
94+ )
95+ return self .update (user_id = user_id , fields = {"locked" : False })
3396
3497 def update (self , user_id : str , fields : InputUpdateUser ) -> None :
98+ """Update a user.
99+
100+ Args:
101+ user_id: The id of the user.
102+ fields: The fields of the user to update.
103+
104+ Returns:
105+ N/A
106+ """
35107 return self ._session .make_request (
36108 "PATCH" , path = f"/api/v1/user/{ user_id } " , json = fields
37109 )
38110
39- def lock (self , user_id : str ) -> None :
40- return self . update ( user_id = user_id , fields = { "locked" : True })
111+ def delete (self , user_id : str , organisation : Optional [ str ] = None ) -> None :
112+ """Delete a user.
41113
42- def unlock (self , user_id : str ) -> None :
43- return self .update (user_id = user_id , fields = {"locked" : False })
114+ Args:
115+ user_id: The id of the user.
116+ organisation: The organisation from which to delete the user from. Optional.
117+
118+ Returns:
119+ N/A
120+ """
121+ return self ._session .make_request (
122+ "DELETE" ,
123+ path = f"/api/v1/user/{ user_id } /force" ,
124+ params = {"organisation" : organisation },
125+ )
44126
45127 def set_organisations (
46128 self , user_id : str , organisations : List [InputUserOrganisation ]
47129 ) -> List [OutputUserOrganisation ]:
130+ """Set the organisations of a user.
131+
132+ Args:
133+ user_id: The id of the user.
134+ organisations: The list of organisations to set to the user.
135+
136+ Returns:
137+ The list of the set user organisations.
138+ """
48139 return self ._session .make_request (
49140 "PUT" ,
50141 path = f"/api/v1/user/{ user_id } /organisations" ,
51142 json = {"organisations" : organisations },
52143 )["organisations" ]
53144
54145 def set_password (self , user_id : str , password : str ) -> None :
146+ """Set the password of a user.
147+
148+ Args:
149+ user_id: The id of the user.
150+ password: The new password of the user.
151+
152+ Returns:
153+ N/A
154+ """
55155 return self ._session .make_request (
56156 "POST" ,
57157 path = f"/api/v1/user/{ user_id } /password/set" ,
58158 json = {"password" : password },
59159 )
60160
161+ def change_password (
162+ self , user_id : str , password : str , current_password : str
163+ ) -> None :
164+ """Change the password of a user.
165+
166+ Args:
167+ user_id: The id of the user.
168+ password: The new password of the user.
169+ current_password: The old password of the user.
170+
171+ Returns:
172+ N/A
173+ """
174+ return self ._session .make_request (
175+ "POST" ,
176+ path = f"/api/v1/user/{ user_id } /password/change" ,
177+ json = {"password" : password , "currentPassword" : current_password },
178+ )
179+
61180 def get_apikey (self , user_id : str ) -> str :
181+ """Get the apikey of a user.
182+
183+ Args:
184+ user_id: The id of the user.
185+
186+ Returns:
187+ The apikey of the user.
188+ """
62189 return self ._session .make_request ("GET" , path = f"/api/v1/user/{ user_id } /key" )
63190
64191 def remove_apikey (self , user_id : str ) -> None :
192+ """Remove the apikey of a user.
193+
194+ Args:
195+ user_id: The id of the user.
196+
197+ Returns:
198+ N/A
199+ """
65200 return self ._session .make_request ("DELETE" , path = f"/api/v1/user/{ user_id } /key" )
66201
67202 def renew_apikey (self , user_id : str ) -> str :
203+ """Renew the apikey of a user.
204+
205+ Args:
206+ user_id: The id of the user.
207+
208+ Returns:
209+ The renewed apikey of the user.
210+ """
68211 return self ._session .make_request (
69212 "POST" , path = f"/api/v1/user/{ user_id } /key/renew"
70213 )
71214
72- def get_avatar (self , user_id : str ):
73- # TODO: implement the avatar download
74- raise NotImplementedError ()
75-
76215 def find (
77216 self ,
78217 filters : Optional [FilterExpr ] = None ,
79218 sortby : Optional [SortExpr ] = None ,
80219 paginate : Optional [Paginate ] = None ,
81220 ) -> List [OutputUser ]:
221+ """Find multiple users.
222+
223+ Args:
224+ filters: The filter expressions to apply in the query.
225+ sortby: The sort expressions to apply in the query.
226+ paginate: The pagination experssion to apply in the query.
227+
228+ Returns:
229+ The list of users matched by the query or an empty list.
230+ """
82231 query : QueryExpr = [
83232 {"_name" : "listUser" },
84233 * self ._build_subquery (filters = filters , sortby = sortby , paginate = paginate ),
@@ -92,6 +241,14 @@ def find(
92241 )
93242
94243 def count (self , filters : Optional [FilterExpr ] = None ) -> int :
244+ """Count users.
245+
246+ Args:
247+ filters: The filter expressions to apply in the query.
248+
249+ Returns:
250+ The count of users matched by the query.
251+ """
95252 query : QueryExpr = [
96253 {"_name" : "listUser" },
97254 * self ._build_subquery (filters = filters ),
0 commit comments