Skip to content

Commit 5435619

Browse files
authored
Merge pull request #2001 from kili-technology/feature/lab-4119-aau-i-have-a-get_current_user-method-on-the-sdk
fix(LAB-4119): expose get_current_user method
2 parents 38d3ddc + a30f927 commit 5435619

3 files changed

Lines changed: 38 additions & 0 deletions

File tree

src/kili/domain_api/users.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ class UsersNamespace(DomainNamespace):
3535
The namespace provides the following main operations:
3636
- list(): Query and list users
3737
- count(): Count users matching filters
38+
- me(): Get the current user
3839
- create(): Create new users
3940
- update(): Update user properties
4041
- update_password(): Update user password with enhanced security validation
@@ -205,6 +206,23 @@ def count(
205206
filter_kwargs = filter or {}
206207
return self._client.count_users(**filter_kwargs)
207208

209+
@typechecked
210+
def me(self, fields: ListOrTuple[str] = ("email", "id", "firstname", "lastname")) -> dict:
211+
"""Get the current user.
212+
213+
Args:
214+
fields: All the fields to request among the possible fields for the users.
215+
See the documentation for all possible fields.
216+
217+
Returns:
218+
A dict with the user fields chosen.
219+
220+
Examples:
221+
>>> # Get the current user
222+
>>> user = kili.users.me(fields=['id', 'email'])
223+
"""
224+
return self._client.get_current_user(fields)
225+
208226
@typechecked
209227
def create(
210228
self,

src/kili/presentation/client/user.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -230,3 +230,19 @@ def update_properties_in_user(
230230
activated=activated,
231231
fields=("id",),
232232
)
233+
234+
@typechecked
235+
def get_current_user(
236+
self, fields: ListOrTuple[str] = ("email", "id", "firstname", "lastname")
237+
) -> dict:
238+
# pylint: disable=line-too-long
239+
"""Get the current user.
240+
241+
Args:
242+
fields: All the fields to request among the possible fields for the users.
243+
See [the documentation](https://api-docs.kili-technology.com/types/objects/user) for all possible fields.
244+
245+
Returns:
246+
A dict with the user fields chosen.
247+
"""
248+
return UserUseCases(self.kili_api_gateway).get_current_user(fields)

src/kili/use_cases/user/__init__.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,10 @@ def count_users(self, filters: UserFilter) -> int:
3030
"""Count users."""
3131
return self._kili_api_gateway.count_users(user_filters=filters)
3232

33+
def get_current_user(self, fields: ListOrTuple[str]):
34+
"""Get the current user."""
35+
return self._kili_api_gateway.get_current_user(fields)
36+
3337
def create_user(
3438
self,
3539
email: str,

0 commit comments

Comments
 (0)