mirror of
https://github.com/Tautulli/Tautulli.git
synced 2025-07-16 02:02:58 -07:00
Add ability to delete users
This commit is contained in:
parent
c501923f2b
commit
1c00f82097
7 changed files with 160 additions and 21 deletions
|
@ -406,9 +406,9 @@ def dbcheck():
|
|||
c_db.execute(
|
||||
'CREATE TABLE IF NOT EXISTS users (id INTEGER PRIMARY KEY AUTOINCREMENT, '
|
||||
'user_id INTEGER DEFAULT NULL UNIQUE, username TEXT NOT NULL UNIQUE, '
|
||||
'friendly_name TEXT, thumb TEXT, email TEXT, is_home_user INTEGER DEFAULT NULL, '
|
||||
'friendly_name TEXT, thumb TEXT, email TEXT, custom_avatar_url TEXT, is_home_user INTEGER DEFAULT NULL, '
|
||||
'is_allow_sync INTEGER DEFAULT NULL, is_restricted INTEGER DEFAULT NULL, do_notify INTEGER DEFAULT 1, '
|
||||
'keep_history INTEGER DEFAULT 1, custom_avatar_url TEXT)'
|
||||
'keep_history INTEGER DEFAULT 1, deleted_user INTEGER DEFAULT 0)'
|
||||
)
|
||||
|
||||
# Upgrade sessions table from earlier versions
|
||||
|
@ -664,6 +664,15 @@ def dbcheck():
|
|||
'WHERE t1.id = session_history.id) '
|
||||
)
|
||||
|
||||
# Upgrade users table from earlier versions
|
||||
try:
|
||||
c_db.execute('SELECT deleted_user from users')
|
||||
except sqlite3.OperationalError:
|
||||
logger.debug(u"Altering database. Updating database table users.")
|
||||
c_db.execute(
|
||||
'ALTER TABLE users ADD COLUMN deleted_user INTEGER DEFAULT 0'
|
||||
)
|
||||
|
||||
conn_db.commit()
|
||||
c_db.close()
|
||||
|
||||
|
|
|
@ -800,6 +800,40 @@ class DataFactory(object):
|
|||
else:
|
||||
return 'Unable to delete items. Input user_id not valid.'
|
||||
|
||||
def delete_user(self, user_id=None):
|
||||
monitor_db = database.MonitorDatabase()
|
||||
|
||||
if user_id.isdigit():
|
||||
self.delete_all_user_history(user_id)
|
||||
logger.info(u"PlexPy DataFactory :: Deleting user with id %s from database." % user_id)
|
||||
monitor_db.action('UPDATE users SET deleted_user = 1 WHERE user_id = ?', [user_id])
|
||||
monitor_db.action('UPDATE users SET keep_history = 0 WHERE user_id = ?', [user_id])
|
||||
monitor_db.action('UPDATE users SET do_notify = 0 WHERE user_id = ?', [user_id])
|
||||
|
||||
return 'Deleted user with id %s.' % user_id
|
||||
else:
|
||||
return 'Unable to delete user. Input user_id not valid.'
|
||||
|
||||
def undelete_user(self, user_id=None, username=None):
|
||||
monitor_db = database.MonitorDatabase()
|
||||
|
||||
if user_id and user_id.isdigit():
|
||||
logger.info(u"PlexPy DataFactory :: Re-adding user with id %s to database." % user_id)
|
||||
monitor_db.action('UPDATE users SET deleted_user = 0 WHERE user_id = ?', [user_id])
|
||||
monitor_db.action('UPDATE users SET keep_history = 1 WHERE user_id = ?', [user_id])
|
||||
monitor_db.action('UPDATE users SET do_notify = 1 WHERE user_id = ?', [user_id])
|
||||
|
||||
return 'Re-added user with id %s.' % user_id
|
||||
elif username:
|
||||
logger.info(u"PlexPy DataFactory :: Re-adding user with username %s to database." % username)
|
||||
monitor_db.action('UPDATE users SET deleted_user = 0 WHERE username = ?', [username])
|
||||
monitor_db.action('UPDATE users SET keep_history = 1 WHERE username = ?', [username])
|
||||
monitor_db.action('UPDATE users SET do_notify = 1 WHERE username = ?', [username])
|
||||
|
||||
return 'Re-added user with username %s.' % username
|
||||
else:
|
||||
return 'Unable to re-add user. Input user_id or username not valid.'
|
||||
|
||||
def get_search_query(self, rating_key=''):
|
||||
monitor_db = database.MonitorDatabase()
|
||||
|
||||
|
|
|
@ -24,6 +24,8 @@ class Users(object):
|
|||
def get_user_list(self, kwargs=None):
|
||||
data_tables = datatables.DataTables()
|
||||
|
||||
custom_where = ['users.deleted_user', 0]
|
||||
|
||||
columns = ['session_history.id',
|
||||
'users.user_id as user_id',
|
||||
'users.custom_avatar_url as user_thumb',
|
||||
|
@ -48,7 +50,7 @@ class Users(object):
|
|||
try:
|
||||
query = data_tables.ssp_query(table_name='users',
|
||||
columns=columns,
|
||||
custom_where=[],
|
||||
custom_where=[custom_where],
|
||||
group_by=['users.user_id'],
|
||||
join_types=['LEFT OUTER JOIN',
|
||||
'LEFT OUTER JOIN',
|
||||
|
|
|
@ -1397,6 +1397,40 @@ class WebInterface(object):
|
|||
cherrypy.response.headers['Content-type'] = 'application/json'
|
||||
return json.dumps({'message': 'no data received'})
|
||||
|
||||
@cherrypy.expose
|
||||
def delete_user(self, user_id, **kwargs):
|
||||
data_factory = datafactory.DataFactory()
|
||||
|
||||
if user_id:
|
||||
delete_row = data_factory.delete_user(user_id=user_id)
|
||||
|
||||
if delete_row:
|
||||
cherrypy.response.headers['Content-type'] = 'application/json'
|
||||
return json.dumps({'message': delete_row})
|
||||
else:
|
||||
cherrypy.response.headers['Content-type'] = 'application/json'
|
||||
return json.dumps({'message': 'no data received'})
|
||||
|
||||
@cherrypy.expose
|
||||
def undelete_user(self, user_id=None, username=None, **kwargs):
|
||||
data_factory = datafactory.DataFactory()
|
||||
|
||||
if user_id:
|
||||
delete_row = data_factory.undelete_user(user_id=user_id)
|
||||
|
||||
if delete_row:
|
||||
cherrypy.response.headers['Content-type'] = 'application/json'
|
||||
return json.dumps({'message': delete_row})
|
||||
elif username:
|
||||
delete_row = data_factory.undelete_user(username=username)
|
||||
|
||||
if delete_row:
|
||||
cherrypy.response.headers['Content-type'] = 'application/json'
|
||||
return json.dumps({'message': delete_row})
|
||||
else:
|
||||
cherrypy.response.headers['Content-type'] = 'application/json'
|
||||
return json.dumps({'message': 'no data received'})
|
||||
|
||||
@cherrypy.expose
|
||||
def search(self, query=''):
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue