Skip to content

Commit 805ab9e

Browse files
committed
[sc-80908] new public API to get all users activity in one call
1 parent f7c9412 commit 805ab9e

File tree

2 files changed

+23
-6
lines changed

2 files changed

+23
-6
lines changed

dataikuapi/dss/admin.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -179,8 +179,8 @@ def get_activity(self):
179179
:return: the user's activity
180180
:rtype: :class:`DSSUserActivity`
181181
"""
182-
raw = self.client._perform_json("GET", "/admin/users/%s/activity" % self.login)
183-
return DSSUserActivity(self.client, self.login, raw)
182+
activity = self.client._perform_json("GET", "/admin/users/%s/activity" % self.login)
183+
return DSSUserActivity(self.client, self.login, activity)
184184

185185
########################################################
186186
# Legacy
@@ -381,7 +381,7 @@ def save(self):
381381
class DSSUserActivity(object):
382382
"""
383383
Settings for a DSS user.
384-
Do not call this directly, use :meth:`DSSUser.get_activity`
384+
Do not call this directly, use :meth:`DSSUser.get_activity` or :meth:`DSSClient.list_users_activity`
385385
"""
386386

387387
def __init__(self, client, login, activity):
@@ -432,9 +432,9 @@ def get_last_failed_login_attempt(self, as_date=False):
432432
else:
433433
return timestamp
434434

435-
def get_last_session_loading(self, as_date=False):
435+
def get_last_session_activity(self, as_date=False):
436436
"""
437-
Get the last session loading of the user as a timestamp or as a :class:`datetime.datetime`, i.e. the last time
437+
Get the last session activity of the user as a timestamp or as a :class:`datetime.datetime`, i.e. the last time
438438
he opened a new DSS tab or refreshed his session.
439439
440440
Returns None if there is no logged attempt.

dataikuapi/dssclient.py

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
from .dss.project import DSSProject
1111
from .dss.app import DSSApp
1212
from .dss.plugin import DSSPlugin
13-
from .dss.admin import DSSUser, DSSOwnUser, DSSGroup, DSSConnection, DSSGeneralSettings, DSSCodeEnv, DSSGlobalApiKey, DSSCluster, DSSGlobalUsageSummary, DSSInstanceVariables
13+
from .dss.admin import DSSUser, DSSUserActivity, DSSOwnUser, DSSGroup, DSSConnection, DSSGeneralSettings, DSSCodeEnv, DSSGlobalApiKey, DSSCluster, DSSGlobalUsageSummary, DSSInstanceVariables
1414
from .dss.meaning import DSSMeaning
1515
from .dss.sqlquery import DSSSQLQuery
1616
from .dss.discussion import DSSObjectDiscussions
@@ -386,6 +386,23 @@ def create_user(self, login, password, display_name='', source_type='LOCAL', gro
386386
def get_own_user(self):
387387
return DSSOwnUser(self)
388388

389+
def list_users_activity(self, as_objects=False):
390+
"""
391+
List all users activity
392+
393+
Note: this call requires an API key with admin rights
394+
395+
:return: A list of user activity logs, as a list of :class:`dataikuapi.dss.admin.DSSUserActivity` if as_objects is True, else as a list of dict
396+
:rtype: list of :class:`dataikuapi.dss.admin.DSSUserActivity` or a list of dict
397+
"""
398+
all_activity = self._perform_json("GET", "/admin/users/activity")
399+
400+
if as_objects:
401+
return [DSSUserActivity(self, user_activity["login"], user_activity) for user_activity in all_activity]
402+
else:
403+
return all_activity
404+
405+
389406
########################################################
390407
# Groups
391408
########################################################

0 commit comments

Comments
 (0)