1+ import datetime
2+
13from .future import DSSFuture
24import json , warnings
35
@@ -164,11 +166,22 @@ def delete(self):
164166 def get_settings (self ):
165167 """
166168 Gets the settings of the user
169+
167170 :rtype: :class:`DSSUserSettings`
168171 """
169172 raw = self .client ._perform_json ("GET" , "/admin/users/%s" % self .login )
170173 return DSSUserSettings (self .client , self .login , raw )
171174
175+ def get_activity (self ):
176+ """
177+ Gets the activity of the user
178+
179+ :return: the user's activity
180+ :rtype: :class:`DSSUserActivity`
181+ """
182+ activity = self .client ._perform_json ("GET" , "/admin/users/%s/activity" % self .login )
183+ return DSSUserActivity (self .client , self .login , activity )
184+
172185 ########################################################
173186 # Legacy
174187 ########################################################
@@ -224,6 +237,7 @@ def get_client_as(self):
224237 else :
225238 raise ValueError ("Don't know how to proxy this client" )
226239
240+
227241class DSSOwnUser (object ):
228242 """
229243 A handle to interact with your own user
@@ -250,8 +264,7 @@ def __init__(self, settings):
250264
251265 def get_raw (self ):
252266 """
253- :return: the raw settings of the user, as a dict. Modifications made to the returned object
254- are reflected when saving
267+ :return: the raw settings of the user, as a dict. Modifications made to the returned object are reflected when saving
255268 :rtype: dict
256269 """
257270 return self .settings
@@ -331,15 +344,15 @@ def admin_properties(self):
331344 """
332345 The user properties (not editable by the user) for this user. Do not set this property, modify the dict in place
333346
334- :rtype dict
347+ :rtype: dict
335348 """
336349 return self .settings ["adminProperties" ]
337350
338351 @property
339352 def enabled (self ):
340353 """
341354 Whether this user is enabled
342- :rtype boolean
355+ :rtype: boolean
343356 """
344357 return self .settings ["enabled" ]
345358
@@ -365,6 +378,67 @@ def save(self):
365378 self .client ._perform_empty ("PUT" , "/current-user" , body = self .settings )
366379
367380
381+ class DSSUserActivity (object ):
382+ """
383+ Activity for a DSS user.
384+ Do not call this directly, use :meth:`DSSUser.get_activity` or :meth:`DSSClient.list_users_activity`
385+ """
386+
387+ def __init__ (self , client , login , activity ):
388+ self .client = client
389+ self .login = login
390+ self .activity = activity
391+
392+ def get_raw (self ):
393+ """
394+ Get the raw activity of the user as a dict.
395+
396+ :return: the raw activity
397+ :rtype: dict
398+ """
399+ return self .activity
400+
401+ @property
402+ def last_successful_login (self ):
403+ """
404+ Get the last successful login of the user as a :class:`datetime.datetime`
405+
406+ Returns None if there was no successful login for this user.
407+
408+ :return: the last successful login
409+ :rtype: :class:`datetime.datetime` or None
410+ """
411+ timestamp = self .activity ["lastSuccessfulLogin" ]
412+ return datetime .datetime .fromtimestamp (timestamp / 1000 ) if timestamp > 0 else None
413+
414+ @property
415+ def last_failed_login (self ):
416+ """
417+ Get the last failed login of the user as a :class:`datetime.datetime`
418+
419+ Returns None if there were no failed login for this user.
420+
421+ :return: the last failed login
422+ :rtype: :class:`datetime.datetime` or None
423+ """
424+ timestamp = self .activity ["lastFailedLogin" ]
425+ return datetime .datetime .fromtimestamp (timestamp / 1000 ) if timestamp > 0 else None
426+
427+ @property
428+ def last_session_activity (self ):
429+ """
430+ Get the last session activity of the user as a :class:`datetime.datetime`, i.e. the last time
431+ the user opened a new DSS tab or refreshed his session.
432+
433+ Returns None if there is no session activity yet.
434+
435+ :return: the last session activity
436+ :rtype: :class:`datetime.datetime` or None
437+ """
438+ timestamp = self .activity ["lastSessionActivity" ]
439+ return datetime .datetime .fromtimestamp (timestamp / 1000 ) if timestamp > 0 else None
440+
441+
368442class DSSGroup (object ):
369443 """
370444 A group on the DSS instance.
0 commit comments