mirror of
https://github.com/Tautulli/Tautulli.git
synced 2025-07-15 01:32:57 -07:00
Add undelete button to edit library/user modal
This commit is contained in:
parent
f41ed9953a
commit
24ed63e07c
5 changed files with 93 additions and 55 deletions
|
@ -690,7 +690,8 @@ class Libraries(object):
|
|||
'child_count': 0,
|
||||
'do_notify': 0,
|
||||
'do_notify_created': 0,
|
||||
'keep_history': 1
|
||||
'keep_history': 1,
|
||||
'deleted_section': 0
|
||||
}
|
||||
|
||||
if not section_id:
|
||||
|
@ -703,7 +704,7 @@ class Libraries(object):
|
|||
if str(section_id).isdigit():
|
||||
query = 'SELECT section_id, section_name, section_type, count, parent_count, child_count, ' \
|
||||
'thumb AS library_thumb, custom_thumb_url AS custom_thumb, art, ' \
|
||||
'do_notify, do_notify_created, keep_history ' \
|
||||
'do_notify, do_notify_created, keep_history, deleted_section ' \
|
||||
'FROM library_sections ' \
|
||||
'WHERE section_id = ? '
|
||||
result = monitor_db.select(query, args=[section_id])
|
||||
|
@ -733,7 +734,8 @@ class Libraries(object):
|
|||
'child_count': item['child_count'],
|
||||
'do_notify': item['do_notify'],
|
||||
'do_notify_created': item['do_notify_created'],
|
||||
'keep_history': item['keep_history']
|
||||
'keep_history': item['keep_history'],
|
||||
'deleted_section': item['deleted_section']
|
||||
}
|
||||
return library_details
|
||||
|
||||
|
@ -924,7 +926,8 @@ class Libraries(object):
|
|||
monitor_db = database.MonitorDatabase()
|
||||
|
||||
try:
|
||||
query = 'SELECT section_id, section_name, section_type, agent FROM library_sections WHERE deleted_section = 0'
|
||||
query = 'SELECT section_id, section_name, section_type, agent ' \
|
||||
'FROM library_sections WHERE deleted_section = 0'
|
||||
result = monitor_db.select(query=query)
|
||||
except Exception as e:
|
||||
logger.warn(u"Tautulli Libraries :: Unable to execute database query for get_sections: %s." % e)
|
||||
|
@ -1001,23 +1004,31 @@ class Libraries(object):
|
|||
|
||||
try:
|
||||
if section_id and section_id.isdigit():
|
||||
logger.info(u"Tautulli Libraries :: Re-adding library with id %s to database." % section_id)
|
||||
monitor_db.action('UPDATE library_sections SET deleted_section = 0 WHERE section_id = ?', [section_id])
|
||||
monitor_db.action('UPDATE library_sections SET keep_history = 1 WHERE section_id = ?', [section_id])
|
||||
monitor_db.action('UPDATE library_sections SET do_notify = 1 WHERE section_id = ?', [section_id])
|
||||
monitor_db.action('UPDATE library_sections SET do_notify_created = 1 WHERE section_id = ?', [section_id])
|
||||
query = 'SELECT * FROM library_sections WHERE section_id = ?'
|
||||
result = monitor_db.select(query=query, args=[section_id])
|
||||
if result:
|
||||
logger.info(u"Tautulli Libraries :: Re-adding library with id %s to database." % section_id)
|
||||
monitor_db.action('UPDATE library_sections SET deleted_section = 0 WHERE section_id = ?', [section_id])
|
||||
monitor_db.action('UPDATE library_sections SET keep_history = 1 WHERE section_id = ?', [section_id])
|
||||
monitor_db.action('UPDATE library_sections SET do_notify = 1 WHERE section_id = ?', [section_id])
|
||||
monitor_db.action('UPDATE library_sections SET do_notify_created = 1 WHERE section_id = ?', [section_id])
|
||||
return True
|
||||
else:
|
||||
return False
|
||||
|
||||
return 'Re-added library with id %s.' % section_id
|
||||
elif section_name:
|
||||
logger.info(u"Tautulli Libraries :: Re-adding library with name %s to database." % section_name)
|
||||
monitor_db.action('UPDATE library_sections SET deleted_section = 0 WHERE section_name = ?', [section_name])
|
||||
monitor_db.action('UPDATE library_sections SET keep_history = 1 WHERE section_name = ?', [section_name])
|
||||
monitor_db.action('UPDATE library_sections SET do_notify = 1 WHERE section_name = ?', [section_name])
|
||||
monitor_db.action('UPDATE library_sections SET do_notify_created = 1 WHERE section_name = ?', [section_name])
|
||||
query = 'SELECT * FROM library_sections WHERE section_name = ?'
|
||||
result = monitor_db.select(query=query, args=[section_name])
|
||||
if result:
|
||||
logger.info(u"Tautulli Libraries :: Re-adding library with name %s to database." % section_name)
|
||||
monitor_db.action('UPDATE library_sections SET deleted_section = 0 WHERE section_name = ?', [section_name])
|
||||
monitor_db.action('UPDATE library_sections SET keep_history = 1 WHERE section_name = ?', [section_name])
|
||||
monitor_db.action('UPDATE library_sections SET do_notify = 1 WHERE section_name = ?', [section_name])
|
||||
monitor_db.action('UPDATE library_sections SET do_notify_created = 1 WHERE section_name = ?', [section_name])
|
||||
return True
|
||||
else:
|
||||
return False
|
||||
|
||||
return 'Re-added library with section_name %s.' % section_name
|
||||
else:
|
||||
return 'Unable to re-add library, section_id or section_name not valid.'
|
||||
except Exception as e:
|
||||
logger.warn(u"Tautulli Libraries :: Unable to execute database query for undelete: %s." % e)
|
||||
|
||||
|
|
|
@ -668,21 +668,29 @@ class Users(object):
|
|||
|
||||
try:
|
||||
if user_id and str(user_id).isdigit():
|
||||
logger.info(u"Tautulli Users :: 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])
|
||||
query = 'SELECT * FROM users WHERE user_id = ?'
|
||||
result = monitor_db.select(query=query, args=[user_id])
|
||||
if result:
|
||||
logger.info(u"Tautulli Users :: 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 True
|
||||
else:
|
||||
return False
|
||||
|
||||
return 'Re-added user with id %s.' % user_id
|
||||
elif username:
|
||||
logger.info(u"Tautulli Users :: 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])
|
||||
query = 'SELECT * FROM users WHERE username = ?'
|
||||
result = monitor_db.select(query=query, args=[username])
|
||||
if result:
|
||||
logger.info(u"Tautulli Users :: 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 True
|
||||
else:
|
||||
return False
|
||||
|
||||
return 'Re-added user with username %s.' % username
|
||||
else:
|
||||
return 'Unable to re-add user, user_id or username not valid.'
|
||||
except Exception as e:
|
||||
logger.warn(u"Tautulli Users :: Unable to execute database query for undelete: %s." % e)
|
||||
|
||||
|
|
|
@ -761,6 +761,7 @@ class WebInterface(object):
|
|||
json:
|
||||
{"child_count": null,
|
||||
"count": 887,
|
||||
"deleted_section": 0,
|
||||
"do_notify": 1,
|
||||
"do_notify_created": 1,
|
||||
"keep_history": 1,
|
||||
|
@ -949,19 +950,14 @@ class WebInterface(object):
|
|||
```
|
||||
"""
|
||||
library_data = libraries.Libraries()
|
||||
|
||||
if section_id:
|
||||
delete_row = library_data.undelete(section_id=section_id)
|
||||
|
||||
if delete_row:
|
||||
return {'message': delete_row}
|
||||
elif section_name:
|
||||
delete_row = library_data.undelete(section_name=section_name)
|
||||
|
||||
if delete_row:
|
||||
return {'message': delete_row}
|
||||
else:
|
||||
return {'message': 'no data received'}
|
||||
result = library_data.undelete(section_id=section_id, section_name=section_name)
|
||||
if result:
|
||||
if section_id:
|
||||
msg ='section_id %s' % section_id
|
||||
elif section_name:
|
||||
msg = 'section_name %s' % section_name
|
||||
return {'result': 'success', 'message': 'Re-added library with %s.' % msg}
|
||||
return {'result': 'error', 'message': 'Unable to re-add library. Invalid section_id or section_name.'}
|
||||
|
||||
@cherrypy.expose
|
||||
@cherrypy.tools.json_out()
|
||||
|
@ -1559,18 +1555,15 @@ class WebInterface(object):
|
|||
None
|
||||
```
|
||||
"""
|
||||
if user_id:
|
||||
user_data = users.Users()
|
||||
delete_row = user_data.undelete(user_id=user_id)
|
||||
if delete_row:
|
||||
return {'message': delete_row}
|
||||
elif username:
|
||||
user_data = users.Users()
|
||||
delete_row = user_data.undelete(username=username)
|
||||
if delete_row:
|
||||
return {'message': delete_row}
|
||||
else:
|
||||
return {'message': 'no data received'}
|
||||
user_data = users.Users()
|
||||
result = user_data.undelete(user_id=user_id, username=username)
|
||||
if result:
|
||||
if user_id:
|
||||
msg ='user_id %s' % user_id
|
||||
elif username:
|
||||
msg = 'username %s' % username
|
||||
return {'result': 'success', 'message': 'Re-added user with %s.' % msg}
|
||||
return {'result': 'error', 'message': 'Unable to re-add user. Invalid user_id or username.'}
|
||||
|
||||
|
||||
##### History #####
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue