mirror of
https://github.com/Tautulli/Tautulli.git
synced 2025-07-12 08:16:06 -07:00
Add optional include_last_seen parameter to get_user
This commit is contained in:
parent
c3f9072e21
commit
88cae2b0dc
2 changed files with 21 additions and 13 deletions
|
@ -359,7 +359,7 @@ class Users(object):
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logger.warn("Tautulli Users :: Unable to execute database query for set_config: %s." % e)
|
logger.warn("Tautulli Users :: Unable to execute database query for set_config: %s." % e)
|
||||||
|
|
||||||
def get_details(self, user_id=None, user=None, email=None):
|
def get_details(self, user_id=None, user=None, email=None, include_last_seen=False):
|
||||||
default_return = {'row_id': 0,
|
default_return = {'row_id': 0,
|
||||||
'user_id': 0,
|
'user_id': 0,
|
||||||
'username': 'Local',
|
'username': 'Local',
|
||||||
|
@ -382,7 +382,8 @@ class Users(object):
|
||||||
if user_id is None and not user and not email:
|
if user_id is None and not user and not email:
|
||||||
return default_return
|
return default_return
|
||||||
|
|
||||||
user_details = self.get_user_details(user_id=user_id, user=user, email=email)
|
user_details = self.get_user_details(user_id=user_id, user=user, email=email,
|
||||||
|
include_last_seen=include_last_seen)
|
||||||
|
|
||||||
if user_details:
|
if user_details:
|
||||||
return user_details
|
return user_details
|
||||||
|
@ -393,7 +394,8 @@ class Users(object):
|
||||||
# Let's first refresh the user list to make sure the user isn't newly added and not in the db yet
|
# Let's first refresh the user list to make sure the user isn't newly added and not in the db yet
|
||||||
refresh_users()
|
refresh_users()
|
||||||
|
|
||||||
user_details = self.get_user_details(user_id=user_id, user=user, email=email)
|
user_details = self.get_user_details(user_id=user_id, user=user, email=email,
|
||||||
|
include_last_seen=include_last_seen)
|
||||||
|
|
||||||
if user_details:
|
if user_details:
|
||||||
return user_details
|
return user_details
|
||||||
|
@ -405,7 +407,13 @@ class Users(object):
|
||||||
# Use "Local" user to retain compatibility with PlexWatch database value
|
# Use "Local" user to retain compatibility with PlexWatch database value
|
||||||
return default_return
|
return default_return
|
||||||
|
|
||||||
def get_user_details(self, user_id=None, user=None, email=None):
|
def get_user_details(self, user_id=None, user=None, email=None, include_last_seen=False):
|
||||||
|
last_seen = 'NULL'
|
||||||
|
join = ''
|
||||||
|
if include_last_seen:
|
||||||
|
last_seen = 'MAX(session_history.started)'
|
||||||
|
join = 'LEFT OUTER JOIN session_history ON users.user_id == session_history.user_id'
|
||||||
|
|
||||||
monitor_db = database.MonitorDatabase()
|
monitor_db = database.MonitorDatabase()
|
||||||
|
|
||||||
try:
|
try:
|
||||||
|
@ -425,11 +433,9 @@ class Users(object):
|
||||||
'thumb AS user_thumb, custom_avatar_url AS custom_thumb, ' \
|
'thumb AS user_thumb, custom_avatar_url AS custom_thumb, ' \
|
||||||
'email, is_active, is_admin, is_home_user, is_allow_sync, is_restricted, ' \
|
'email, is_active, is_admin, is_home_user, is_allow_sync, is_restricted, ' \
|
||||||
'do_notify, keep_history, deleted_user, ' \
|
'do_notify, keep_history, deleted_user, ' \
|
||||||
'allow_guest, shared_libraries, ' \
|
'allow_guest, shared_libraries, %s AS last_seen ' \
|
||||||
'MAX(session_history.started) AS last_seen ' \
|
'FROM users %s ' \
|
||||||
'FROM users ' \
|
'WHERE %s COLLATE NOCASE' % (last_seen, join, where)
|
||||||
'LEFT OUTER JOIN session_history ON users.user_id == session_history.user_id ' \
|
|
||||||
'WHERE %s COLLATE NOCASE' % where
|
|
||||||
result = monitor_db.select(query, args=args)
|
result = monitor_db.select(query, args=args)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logger.warn("Tautulli Users :: Unable to execute database query for get_user_details: %s." % e)
|
logger.warn("Tautulli Users :: Unable to execute database query for get_user_details: %s." % e)
|
||||||
|
|
|
@ -1588,15 +1588,15 @@ class WebInterface(object):
|
||||||
@cherrypy.tools.json_out()
|
@cherrypy.tools.json_out()
|
||||||
@requireAuth(member_of("admin"))
|
@requireAuth(member_of("admin"))
|
||||||
@addtoapi()
|
@addtoapi()
|
||||||
def get_user(self, user_id=None, **kwargs):
|
def get_user(self, user_id=None, include_last_seen=False, **kwargs):
|
||||||
""" Get a user's details.
|
""" Get a user's details.
|
||||||
|
|
||||||
```
|
```
|
||||||
Required parameters:
|
Required parameters:
|
||||||
user_id (str): The id of the Plex user
|
user_id (str): The id of the Plex user
|
||||||
|
|
||||||
Optional parameters:
|
Optional parameters:
|
||||||
None
|
include_last_seen (bool): True to include the last_seen value for the user.
|
||||||
|
|
||||||
Returns:
|
Returns:
|
||||||
json:
|
json:
|
||||||
|
@ -1620,9 +1620,11 @@ class WebInterface(object):
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
"""
|
"""
|
||||||
|
include_last_seen = helpers.bool_true(include_last_seen)
|
||||||
if user_id:
|
if user_id:
|
||||||
user_data = users.Users()
|
user_data = users.Users()
|
||||||
user_details = user_data.get_details(user_id=user_id)
|
user_details = user_data.get_details(user_id=user_id,
|
||||||
|
include_last_seen=include_last_seen)
|
||||||
if user_details:
|
if user_details:
|
||||||
return user_details
|
return user_details
|
||||||
else:
|
else:
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue