Skip to content

Commit 4190a72

Browse files
committed
[sc-80908] DSSClient.list_users() can now return a list of DSSUser for convenience
1 parent 4a13f4a commit 4190a72

File tree

2 files changed

+19
-13
lines changed

2 files changed

+19
-13
lines changed

dataikuapi/dss/admin.py

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -172,10 +172,13 @@ def get_settings(self):
172172
def get_last_activity(self):
173173
"""
174174
Gets the last activity of a user:
175-
- his last successful login attempt
176-
- his last failed login attempt
177-
- his last load of DSS
178-
:return: a dict
175+
176+
* last successful login attempt
177+
* last failed login attempt
178+
* last loading of DSS (new tab or tab refresh)
179+
180+
:return: the user's activity, as a dict
181+
:rtype: dict
179182
"""
180183
return self.client._perform_json("GET", "/admin/users/%s/activity" % self.login)
181184

@@ -260,8 +263,7 @@ def __init__(self, settings):
260263

261264
def get_raw(self):
262265
"""
263-
:return: the raw settings of the user, as a dict. Modifications made to the returned object
264-
are reflected when saving
266+
:return: the raw settings of the user, as a dict. Modifications made to the returned object are reflected when saving
265267
:rtype: dict
266268
"""
267269
return self.settings
@@ -341,15 +343,15 @@ def admin_properties(self):
341343
"""
342344
The user properties (not editable by the user) for this user. Do not set this property, modify the dict in place
343345
344-
:rtype dict
346+
:rtype: dict
345347
"""
346348
return self.settings["adminProperties"]
347349

348350
@property
349351
def enabled(self):
350352
"""
351353
Whether this user is enabled
352-
:rtype boolean
354+
:rtype: boolean
353355
"""
354356
return self.settings["enabled"]
355357

dataikuapi/dssclient.py

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -329,17 +329,21 @@ def sql_query(self, query, connection=None, database=None, dataset_full_name=Non
329329
# Users
330330
########################################################
331331

332-
def list_users(self):
332+
def list_users(self, as_objects=False):
333333
"""
334334
List all users setup on the DSS instance
335335
336336
Note: this call requires an API key with admin rights
337337
338-
:return: A list of users, as a list of dicts
339-
:rtype: list of dicts
338+
:return: A list of users, as a list of :class:`dataikuapi.dss.admin.DSSUser` if as_objects is True, else as a list of dicts
339+
:rtype: list of :class:`dataikuapi.dss.admin.DSSUser` or list of dicts
340340
"""
341-
return self._perform_json(
342-
"GET", "/admin/users/")
341+
users = self._perform_json("GET", "/admin/users/")
342+
343+
if as_objects:
344+
return [DSSUser(self, user["login"]) for user in users]
345+
else:
346+
return users
343347

344348
def get_user(self, login):
345349
"""

0 commit comments

Comments
 (0)