Merge pull request #306 from JonnyWong16/miscellaneous-fixes

Delete users
This commit is contained in:
JonnyWong16 2015-12-02 17:05:39 -08:00
commit 08d65623dd
13 changed files with 213 additions and 70 deletions

View file

@ -2374,7 +2374,8 @@ a .home-platforms-instance-list-oval:hover,
top: 5px; top: 5px;
left: 12px; left: 12px;
} }
#users-to-delete > li { #users-to-delete > li,
#users-to-purge > li {
color: #e9a049; color: #e9a049;
} }
#updatebar { #updatebar {

View file

@ -176,7 +176,9 @@ function getPlatformImagePath(platformName) {
if (platformName.indexOf("Roku") > -1) { if (platformName.indexOf("Roku") > -1) {
return 'interfaces/default/images/platforms/roku.png'; return 'interfaces/default/images/platforms/roku.png';
} else if (platformName.indexOf("Apple TV") > -1) { } else if (platformName.indexOf("Apple TV") > -1) {
return 'interfaces/default/images/platforms/appletv.png'; return 'interfaces/default/images/platforms/atv.png';
} else if (platformName.indexOf("tvOS") > -1) {
return 'interfaces/default/images/platforms/atv.png';
} else if (platformName.indexOf("Firefox") > -1) { } else if (platformName.indexOf("Firefox") > -1) {
return 'interfaces/default/images/platforms/firefox.png'; return 'interfaces/default/images/platforms/firefox.png';
} else if (platformName.indexOf("Chromecast") > -1) { } else if (platformName.indexOf("Chromecast") > -1) {

View file

@ -1,3 +1,4 @@
var users_to_delete = [];
var users_to_purge = []; var users_to_purge = [];
users_list_table_options = { users_list_table_options = {
@ -22,7 +23,8 @@ users_list_table_options = {
"targets": [0], "targets": [0],
"data": null, "data": null,
"createdCell": function (td, cellData, rowData, row, col) { "createdCell": function (td, cellData, rowData, row, col) {
$(td).html('<div class="edit-user-toggles"><button class="btn btn-xs btn-warning" data-id="' + rowData['user_id'] + '" data-toggle="button"><i class="fa fa-eraser fa-fw"></i> Purge</button>&nbsp&nbsp&nbsp' + $(td).html('<div class="edit-user-toggles"><button class="btn btn-xs btn-warning delete-user" data-id="' + rowData['user_id'] + '" data-toggle="button"><i class="fa fa-trash-o fa-fw"></i> Delete</button>&nbsp' +
'<button class="btn btn-xs btn-warning purge-user" data-id="' + rowData['user_id'] + '" data-toggle="button"><i class="fa fa-eraser fa-fw"></i> Purge</button>&nbsp&nbsp&nbsp' +
'<input type="checkbox" id="do_notify-' + rowData['user_id'] + '" name="do_notify" value="1" ' + rowData['do_notify'] + '><label class="edit-tooltip" for="do_notify-' + rowData['user_id'] + '" data-toggle="tooltip" title="Toggle Notifications"><i class="fa fa-bell fa-lg fa-fw"></i></label>&nbsp' + '<input type="checkbox" id="do_notify-' + rowData['user_id'] + '" name="do_notify" value="1" ' + rowData['do_notify'] + '><label class="edit-tooltip" for="do_notify-' + rowData['user_id'] + '" data-toggle="tooltip" title="Toggle Notifications"><i class="fa fa-bell fa-lg fa-fw"></i></label>&nbsp' +
'<input type="checkbox" id="keep_history-' + rowData['user_id'] + '" name="keep_history" value="1" ' + rowData['keep_history'] + '><label class="edit-tooltip" for="keep_history-' + rowData['user_id'] + '" data-toggle="tooltip" title="Toggle History"><i class="fa fa-history fa-lg fa-fw"></i></label>&nbsp'); '<input type="checkbox" id="keep_history-' + rowData['user_id'] + '" name="keep_history" value="1" ' + rowData['keep_history'] + '><label class="edit-tooltip" for="keep_history-' + rowData['user_id'] + '" data-toggle="tooltip" title="Toggle History"><i class="fa fa-history fa-lg fa-fw"></i></label>&nbsp');
// Show/hide user currently doesn't work // Show/hide user currently doesn't work
@ -286,16 +288,44 @@ $('#users_list_table').on('change', 'td.edit-control > .edit-user-toggles > inpu
}); });
}); });
$('#users_list_table').on('click', 'td.edit-control > .edit-user-toggles > button', function () { $('#users_list_table').on('click', 'td.edit-control > .edit-user-toggles > button.delete-user', function () {
var tr = $(this).parents('tr'); var tr = $(this).parents('tr');
var row = users_list_table.row(tr); var row = users_list_table.row(tr);
var rowData = row.data(); var rowData = row.data();
var index = $.inArray(rowData['user_id'], users_to_purge); var index_delete = $.inArray(rowData['user_id'], users_to_delete);
if (index === -1) { var index_purge = $.inArray(rowData['user_id'], users_to_purge);
if (index_delete === -1) {
users_to_delete.push(rowData['user_id']);
if (index_purge === -1) {
tr.find('button.purge-user').click();
}
} else {
users_to_delete.splice(index_delete, 1);
if (index_purge != -1) {
tr.find('button.purge-user').click();
}
}
$(this).toggleClass('btn-warning').toggleClass('btn-danger');
});
$('#users_list_table').on('click', 'td.edit-control > .edit-user-toggles > button.purge-user', function () {
var tr = $(this).parents('tr');
var row = users_list_table.row(tr);
var rowData = row.data();
var index_delete = $.inArray(rowData['user_id'], users_to_delete);
var index_purge = $.inArray(rowData['user_id'], users_to_purge);
if (index_purge === -1) {
users_to_purge.push(rowData['user_id']); users_to_purge.push(rowData['user_id']);
} else { } else {
users_to_purge.splice(index, 1); users_to_purge.splice(index_purge, 1);
if (index_delete != -1) {
tr.find('button.delete-user').click();
}
} }
$(this).toggleClass('btn-warning').toggleClass('btn-danger'); $(this).toggleClass('btn-warning').toggleClass('btn-danger');
}); });

View file

@ -16,7 +16,7 @@
<button class="btn btn-danger btn-edit" data-toggle="button" aria-pressed="false" autocomplete="off" id="row-edit-mode"> <button class="btn btn-danger btn-edit" data-toggle="button" aria-pressed="false" autocomplete="off" id="row-edit-mode">
<i class="fa fa-pencil"></i> Edit mode <i class="fa fa-pencil"></i> Edit mode
</button>&nbsp </button>&nbsp
<div class="alert alert-danger alert-edit" role="alert" id="row-edit-mode-alert"><i class="fa fa-exclamation-triangle"></i>&nbspSelect users to purge. Data is purged upon exiting edit mode.</div> <div class="alert alert-danger alert-edit" role="alert" id="row-edit-mode-alert"><i class="fa fa-exclamation-triangle"></i>&nbspSelect users to delete/purge. Data is deleted/purged upon exiting edit mode.</div>
</div> </div>
</div> </div>
<div class='table-card-back'> <div class='table-card-back'>
@ -46,16 +46,16 @@
<div class="modal-content"> <div class="modal-content">
<div class="modal-header"> <div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-hidden="true"><i class="fa fa-remove"></i></button> <button type="button" class="close" data-dismiss="modal" aria-hidden="true"><i class="fa fa-remove"></i></button>
<h4 class="modal-title" id="myModalLabel">Confirm Purge</h4> <h4 class="modal-title" id="myModalLabel">Confirm Delete/Purge</h4>
</div> </div>
<div class="modal-body" style="text-align: center;"> <div class="modal-body" style="text-align: center;">
<p>Are you REALLY sure you want to purge all history for the following users:</p>
<ul id="users-to-delete" class="list-unstyled"></ul> <ul id="users-to-delete" class="list-unstyled"></ul>
<ul id="users-to-purge" class="list-unstyled"></ul>
<p>This is permanent and cannot be undone!</p> <p>This is permanent and cannot be undone!</p>
</div> </div>
<div class="modal-footer"> <div class="modal-footer">
<button type="button" class="btn btn-dark" data-dismiss="modal">Cancel</button> <button type="button" class="btn btn-dark" data-dismiss="modal">Cancel</button>
<button type="button" class="btn btn-danger btn-ok" data-dismiss="modal" id="confirm-purge">Purge</button> <button type="button" class="btn btn-danger btn-ok" data-dismiss="modal" id="confirm-delete">Confirm</button>
</div> </div>
</div> </div>
</div> </div>
@ -74,8 +74,8 @@
<script> <script>
$(document).ready(function () { $(document).ready(function () {
users_list_table_options.ajax = { users_list_table_options.ajax = {
"url": "get_user_list", url: 'get_user_list',
type: "post", type: 'POST',
data: function ( d ) { data: function ( d ) {
return { 'json_data': JSON.stringify( d ) }; return { 'json_data': JSON.stringify( d ) };
} }
@ -88,18 +88,46 @@
$('#row-edit-mode').on('click', function () { $('#row-edit-mode').on('click', function () {
$('#row-edit-mode-alert').fadeIn(200); $('#row-edit-mode-alert').fadeIn(200);
$('#users-to-delete').html(''); $('#users-to-delete').html('');
$('#users-to-purge').html('');
if ($(this).hasClass('active')) { if ($(this).hasClass('active')) {
if (users_to_purge.length > 0) { if (users_to_delete.length > 0 || users_to_purge.length > 0) {
$('.edit-control').each(function () { $('.edit-control').each(function () {
$(this).find('button.btn-danger').toggleClass('btn-warning').toggleClass('btn-danger'); $(this).find('button.btn-danger').toggleClass('btn-warning').toggleClass('btn-danger');
}); });
for (var i = 0; i < users_to_purge.length; i++) { users_to_purge = $.grep(users_to_purge, function (value) {
$('#users-to-delete').append('<li>' + $('div[data-id=' + users_to_purge[i] + '] > input').val() + '</li>'); return $.inArray(value, users_to_delete) < 0;
});
if (users_to_delete.length > 0) {
$('#users-to-delete').prepend('<p>Are you REALLY sure you want to delete the following users:</p>')
for (var i = 0; i < users_to_delete.length; i++) {
$('#users-to-delete').append('<li>' + $('div[data-id=' + users_to_delete[i] + '] > input').val() + '</li>');
} }
}
if (users_to_purge.length > 0) {
$('#users-to-purge').prepend('<p>Are you REALLY sure you want to purge all history for the following users:</p>')
for (var i = 0; i < users_to_purge.length; i++) {
$('#users-to-purge').append('<li>' + $('div[data-id=' + users_to_purge[i] + '] > input').val() + '</li>');
}
}
$('#confirm-modal').modal(); $('#confirm-modal').modal();
$('#confirm-modal').one('click', '#confirm-purge', function () { $('#confirm-modal').one('click', '#confirm-delete', function () {
for (var i = 0; i < users_to_delete.length; i++) {
$.ajax({
url: 'delete_user',
data: { user_id: users_to_delete[i] },
cache: false,
async: true,
success: function (data) {
var msg = "User deleted";
showMsg(msg, false, true, 2000);
}
});
}
for (var i = 0; i < users_to_purge.length; i++) { for (var i = 0; i < users_to_purge.length; i++) {
$.ajax({ $.ajax({
url: 'delete_all_user_history', url: 'delete_all_user_history',
@ -129,6 +157,7 @@
}); });
} else { } else {
users_to_delete = [];
users_to_purge = []; users_to_purge = [];
$('.edit-control').each(function () { $('.edit-control').each(function () {
$(this).find('button.btn-danger').toggleClass('btn-warning').toggleClass('btn-danger'); $(this).find('button.btn-danger').toggleClass('btn-warning').toggleClass('btn-danger');
@ -152,7 +181,7 @@
}, },
error: function(jqXHR, textStatus, errorThrown) { error: function(jqXHR, textStatus, errorThrown) {
showMsg('<i class="fa fa-exclamation-circle"></i>&nbspUnable to refresh user list.',false,true,2000,true) showMsg('<i class="fa fa-exclamation-circle"></i>&nbspUnable to refresh user list.',false,true,2000,true)
}, }
}); });
}); });
</script> </script>

View file

@ -406,9 +406,9 @@ def dbcheck():
c_db.execute( c_db.execute(
'CREATE TABLE IF NOT EXISTS users (id INTEGER PRIMARY KEY AUTOINCREMENT, ' 'CREATE TABLE IF NOT EXISTS users (id INTEGER PRIMARY KEY AUTOINCREMENT, '
'user_id INTEGER DEFAULT NULL UNIQUE, username TEXT NOT NULL UNIQUE, ' '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, ' '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 # Upgrade sessions table from earlier versions
@ -664,6 +664,15 @@ def dbcheck():
'WHERE t1.id = session_history.id) ' '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() conn_db.commit()
c_db.close() c_db.close()

View file

@ -180,6 +180,8 @@ def check_recently_added():
recently_added = recently_added_list['recently_added'] recently_added = recently_added_list['recently_added']
for item in recently_added: for item in recently_added:
metadata = []
if item['media_type'] == 'movie': if item['media_type'] == 'movie':
metadata_list = pms_connect.get_metadata_details(item['rating_key']) metadata_list = pms_connect.get_metadata_details(item['rating_key'])
if metadata_list: if metadata_list:
@ -199,7 +201,7 @@ def check_recently_added():
if metadata: if metadata:
if not plexpy.CONFIG.NOTIFY_RECENTLY_ADDED_GRANDPARENT: if not plexpy.CONFIG.NOTIFY_RECENTLY_ADDED_GRANDPARENT:
for item in metadata: for item in metadata:
if 0 < int(item['added_at']) - time_threshold <= time_interval: if 0 < time_threshold - int(item['added_at']) <= time_interval:
logger.debug(u"PlexPy Monitor :: Library item %s has been added to Plex." % str(item['rating_key'])) logger.debug(u"PlexPy Monitor :: Library item %s has been added to Plex." % str(item['rating_key']))
# Fire off notifications # Fire off notifications
threading.Thread(target=notification_handler.notify_timeline, threading.Thread(target=notification_handler.notify_timeline,
@ -208,7 +210,7 @@ def check_recently_added():
else: else:
item = max(metadata, key=lambda x:x['added_at']) item = max(metadata, key=lambda x:x['added_at'])
if 0 < int(item['added_at']) - time_threshold <= time_interval: if 0 < time_threshold - int(item['added_at']) <= time_interval:
if item['media_type'] == 'episode' or item['media_type'] == 'track': if item['media_type'] == 'episode' or item['media_type'] == 'track':
metadata_list = pms_connect.get_metadata_details(item['grandparent_rating_key']) metadata_list = pms_connect.get_metadata_details(item['grandparent_rating_key'])

View file

@ -286,12 +286,12 @@ class ActivityProcessor(object):
# The logged IP will always be the first match and we don't want localhost entries # The logged IP will always be the first match and we don't want localhost entries
if ipv4[0] != '127.0.0.1': if ipv4[0] != '127.0.0.1':
# check if IPv4 mapped IPv6 address (::ffff:xxx.xxx.xxx.xxx) # check if IPv4 mapped IPv6 address (::ffff:xxx.xxx.xxx.xxx)
if '::ffff:' + ipv4[0] in line: #if '::ffff:' + ipv4[0] in line:
logger.debug(u"PlexPy ActivityProcessor :: Matched IP address (%s) for stream ratingKey %s " # logger.debug(u"PlexPy ActivityProcessor :: Matched IP address (%s) for stream ratingKey %s "
u"and machineIdentifier %s." # u"and machineIdentifier %s."
% ('::ffff:' + ipv4[0], rating_key, machine_id)) # % ('::ffff:' + ipv4[0], rating_key, machine_id))
return '::ffff:' + ipv4[0] # return '::ffff:' + ipv4[0]
else: #else:
logger.debug(u"PlexPy ActivityProcessor :: Matched IP address (%s) for stream ratingKey %s " logger.debug(u"PlexPy ActivityProcessor :: Matched IP address (%s) for stream ratingKey %s "
u"and machineIdentifier %s." u"and machineIdentifier %s."
% (ipv4[0], rating_key, machine_id)) % (ipv4[0], rating_key, machine_id))
@ -315,11 +315,11 @@ class ActivityProcessor(object):
if ipv4: if ipv4:
# The logged IP will always be the first match and we don't want localhost entries # The logged IP will always be the first match and we don't want localhost entries
if ipv4[0] != '127.0.0.1': if ipv4[0] != '127.0.0.1':
if '::ffff:' + ipv4[0] in line: #if '::ffff:' + ipv4[0] in line:
logger.debug(u"PlexPy ActivityProcessor :: Matched IP address (%s) for stream ratingKey %s." % # logger.debug(u"PlexPy ActivityProcessor :: Matched IP address (%s) for stream ratingKey %s." %
('::ffff:' + ipv4[0], rating_key)) # ('::ffff:' + ipv4[0], rating_key))
return '::ffff:' + ipv4[0] # return '::ffff:' + ipv4[0]
else: #else:
logger.debug(u"PlexPy ActivityProcessor :: Matched IP address (%s) for stream ratingKey %s." % logger.debug(u"PlexPy ActivityProcessor :: Matched IP address (%s) for stream ratingKey %s." %
(ipv4[0], rating_key)) (ipv4[0], rating_key))
return ipv4[0] return ipv4[0]

View file

@ -154,24 +154,24 @@ _CONFIG_DEFINITIONS = {
'NOTIFY_RECENTLY_ADDED_GRANDPARENT': (int, 'Monitoring', 0), 'NOTIFY_RECENTLY_ADDED_GRANDPARENT': (int, 'Monitoring', 0),
'NOTIFY_RECENTLY_ADDED_DELAY': (int, 'Monitoring', 60), 'NOTIFY_RECENTLY_ADDED_DELAY': (int, 'Monitoring', 60),
'NOTIFY_WATCHED_PERCENT': (int, 'Monitoring', 85), 'NOTIFY_WATCHED_PERCENT': (int, 'Monitoring', 85),
'NOTIFY_ON_START_SUBJECT_TEXT': (str, 'Monitoring', 'PlexPy ({server_name})'), 'NOTIFY_ON_START_SUBJECT_TEXT': (unicode, 'Monitoring', 'PlexPy ({server_name})'),
'NOTIFY_ON_START_BODY_TEXT': (str, 'Monitoring', '{user} ({player}) started playing {title}.'), 'NOTIFY_ON_START_BODY_TEXT': (unicode, 'Monitoring', '{user} ({player}) started playing {title}.'),
'NOTIFY_ON_STOP_SUBJECT_TEXT': (str, 'Monitoring', 'PlexPy ({server_name})'), 'NOTIFY_ON_STOP_SUBJECT_TEXT': (unicode, 'Monitoring', 'PlexPy ({server_name})'),
'NOTIFY_ON_STOP_BODY_TEXT': (str, 'Monitoring', '{user} ({player}) has stopped {title}.'), 'NOTIFY_ON_STOP_BODY_TEXT': (unicode, 'Monitoring', '{user} ({player}) has stopped {title}.'),
'NOTIFY_ON_PAUSE_SUBJECT_TEXT': (str, 'Monitoring', 'PlexPy ({server_name})'), 'NOTIFY_ON_PAUSE_SUBJECT_TEXT': (unicode, 'Monitoring', 'PlexPy ({server_name})'),
'NOTIFY_ON_PAUSE_BODY_TEXT': (str, 'Monitoring', '{user} ({player}) has paused {title}.'), 'NOTIFY_ON_PAUSE_BODY_TEXT': (unicode, 'Monitoring', '{user} ({player}) has paused {title}.'),
'NOTIFY_ON_RESUME_SUBJECT_TEXT': (str, 'Monitoring', 'PlexPy ({server_name})'), 'NOTIFY_ON_RESUME_SUBJECT_TEXT': (unicode, 'Monitoring', 'PlexPy ({server_name})'),
'NOTIFY_ON_RESUME_BODY_TEXT': (str, 'Monitoring', '{user} ({player}) has resumed {title}.'), 'NOTIFY_ON_RESUME_BODY_TEXT': (unicode, 'Monitoring', '{user} ({player}) has resumed {title}.'),
'NOTIFY_ON_BUFFER_SUBJECT_TEXT': (str, 'Monitoring', 'PlexPy ({server_name})'), 'NOTIFY_ON_BUFFER_SUBJECT_TEXT': (unicode, 'Monitoring', 'PlexPy ({server_name})'),
'NOTIFY_ON_BUFFER_BODY_TEXT': (str, 'Monitoring', '{user} ({player}) is buffering {title}.'), 'NOTIFY_ON_BUFFER_BODY_TEXT': (unicode, 'Monitoring', '{user} ({player}) is buffering {title}.'),
'NOTIFY_ON_WATCHED_SUBJECT_TEXT': (str, 'Monitoring', 'PlexPy ({server_name})'), 'NOTIFY_ON_WATCHED_SUBJECT_TEXT': (unicode, 'Monitoring', 'PlexPy ({server_name})'),
'NOTIFY_ON_WATCHED_BODY_TEXT': (str, 'Monitoring', '{user} ({player}) has watched {title}.'), 'NOTIFY_ON_WATCHED_BODY_TEXT': (unicode, 'Monitoring', '{user} ({player}) has watched {title}.'),
'NOTIFY_ON_CREATED_SUBJECT_TEXT': (str, 'Monitoring', 'PlexPy ({server_name})'), 'NOTIFY_ON_CREATED_SUBJECT_TEXT': (unicode, 'Monitoring', 'PlexPy ({server_name})'),
'NOTIFY_ON_CREATED_BODY_TEXT': (str, 'Monitoring', '{title} was recently added to Plex.'), 'NOTIFY_ON_CREATED_BODY_TEXT': (unicode, 'Monitoring', '{title} was recently added to Plex.'),
'NOTIFY_ON_EXTDOWN_SUBJECT_TEXT': (str, 'Monitoring', 'PlexPy ({server_name})'), 'NOTIFY_ON_EXTDOWN_SUBJECT_TEXT': (unicode, 'Monitoring', 'PlexPy ({server_name})'),
'NOTIFY_ON_EXTDOWN_BODY_TEXT': (str, 'Monitoring', 'The Plex Media Server remote access is down.'), 'NOTIFY_ON_EXTDOWN_BODY_TEXT': (unicode, 'Monitoring', 'The Plex Media Server remote access is down.'),
'NOTIFY_ON_INTDOWN_SUBJECT_TEXT': (str, 'Monitoring', 'PlexPy ({server_name})'), 'NOTIFY_ON_INTDOWN_SUBJECT_TEXT': (unicode, 'Monitoring', 'PlexPy ({server_name})'),
'NOTIFY_ON_INTDOWN_BODY_TEXT': (str, 'Monitoring', 'The Plex Media Server is down.'), 'NOTIFY_ON_INTDOWN_BODY_TEXT': (unicode, 'Monitoring', 'The Plex Media Server is down.'),
'OSX_NOTIFY_APP': (str, 'OSX_Notify', '/Applications/PlexPy'), 'OSX_NOTIFY_APP': (str, 'OSX_Notify', '/Applications/PlexPy'),
'OSX_NOTIFY_ENABLED': (int, 'OSX_Notify', 0), 'OSX_NOTIFY_ENABLED': (int, 'OSX_Notify', 0),
'OSX_NOTIFY_ON_PLAY': (int, 'OSX_Notify', 0), 'OSX_NOTIFY_ON_PLAY': (int, 'OSX_Notify', 0),
@ -250,7 +250,7 @@ _CONFIG_DEFINITIONS = {
'REFRESH_USERS_ON_STARTUP': (int, 'Monitoring', 1), 'REFRESH_USERS_ON_STARTUP': (int, 'Monitoring', 1),
'TELEGRAM_BOT_TOKEN': (str, 'Telegram', ''), 'TELEGRAM_BOT_TOKEN': (str, 'Telegram', ''),
'TELEGRAM_ENABLED': (int, 'Telegram', 0), 'TELEGRAM_ENABLED': (int, 'Telegram', 0),
'TELEGRAM_CHAT_ID': (int, 'Telegram', 0), 'TELEGRAM_CHAT_ID': (str, 'Telegram', ''),
'TELEGRAM_ON_PLAY': (int, 'Telegram', 0), 'TELEGRAM_ON_PLAY': (int, 'Telegram', 0),
'TELEGRAM_ON_STOP': (int, 'Telegram', 0), 'TELEGRAM_ON_STOP': (int, 'Telegram', 0),
'TELEGRAM_ON_PAUSE': (int, 'Telegram', 0), 'TELEGRAM_ON_PAUSE': (int, 'Telegram', 0),

View file

@ -800,6 +800,40 @@ class DataFactory(object):
else: else:
return 'Unable to delete items. Input user_id not valid.' 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=''): def get_search_query(self, rating_key=''):
monitor_db = database.MonitorDatabase() monitor_db = database.MonitorDatabase()

View file

@ -896,9 +896,9 @@ class PUSHALOT(object):
response = http_handler.getresponse() response = http_handler.getresponse()
request_status = response.status request_status = response.status
logger.debug(u"Pushalot response status: %r" % request_status) #logger.debug(u"Pushalot response status: %r" % request_status)
logger.debug(u"Pushalot response headers: %r" % response.getheaders()) #logger.debug(u"Pushalot response headers: %r" % response.getheaders())
logger.debug(u"Pushalot response body: %r" % response.read()) #logger.debug(u"Pushalot response body: %r" % response.read())
if request_status == 200: if request_status == 200:
logger.info(u"Pushalot notifications sent.") logger.info(u"Pushalot notifications sent.")
@ -1526,7 +1526,7 @@ class TELEGRAM(object):
{'label': 'Telegram Chat ID', {'label': 'Telegram Chat ID',
'value': self.chat_id, 'value': self.chat_id,
'name': 'telegram_chat_id', 'name': 'telegram_chat_id',
'description': 'Your Telegram Chat ID or Group ID. Contact <a href="http://telegram.me/myidbot" target="_blank">@myidbot</a> on Telegram to get an ID.', 'description': 'Your Telegram Chat ID, Group ID, or channel username. Contact <a href="http://telegram.me/myidbot" target="_blank">@myidbot</a> on Telegram to get an ID.',
'input_type': 'text' 'input_type': 'text'
} }
] ]

View file

@ -803,7 +803,7 @@ class PmsConnect(object):
'user_id': user_details['user_id'], 'user_id': user_details['user_id'],
'friendly_name': user_details['friendly_name'], 'friendly_name': user_details['friendly_name'],
'user_thumb': user_details['thumb'], 'user_thumb': user_details['thumb'],
'ip_address': helpers.get_xml_attr(session.getElementsByTagName('Player')[0], 'address'), 'ip_address': helpers.get_xml_attr(session.getElementsByTagName('Player')[0], 'address').split(':')[-1],
'player': helpers.get_xml_attr(session.getElementsByTagName('Player')[0], 'title'), 'player': helpers.get_xml_attr(session.getElementsByTagName('Player')[0], 'title'),
'platform': helpers.get_xml_attr(session.getElementsByTagName('Player')[0], 'platform'), 'platform': helpers.get_xml_attr(session.getElementsByTagName('Player')[0], 'platform'),
'machine_id': machine_id, 'machine_id': machine_id,
@ -924,7 +924,7 @@ class PmsConnect(object):
'user_id': user_details['user_id'], 'user_id': user_details['user_id'],
'friendly_name': user_details['friendly_name'], 'friendly_name': user_details['friendly_name'],
'user_thumb': user_details['thumb'], 'user_thumb': user_details['thumb'],
'ip_address': helpers.get_xml_attr(session.getElementsByTagName('Player')[0], 'address'), 'ip_address': helpers.get_xml_attr(session.getElementsByTagName('Player')[0], 'address').split(':')[-1],
'player': helpers.get_xml_attr(session.getElementsByTagName('Player')[0], 'title'), 'player': helpers.get_xml_attr(session.getElementsByTagName('Player')[0], 'title'),
'platform': helpers.get_xml_attr(session.getElementsByTagName('Player')[0], 'platform'), 'platform': helpers.get_xml_attr(session.getElementsByTagName('Player')[0], 'platform'),
'machine_id': machine_id, 'machine_id': machine_id,
@ -981,7 +981,7 @@ class PmsConnect(object):
'user_id': user_details['user_id'], 'user_id': user_details['user_id'],
'friendly_name': user_details['friendly_name'], 'friendly_name': user_details['friendly_name'],
'user_thumb': user_details['thumb'], 'user_thumb': user_details['thumb'],
'ip_address': helpers.get_xml_attr(session.getElementsByTagName('Player')[0], 'address'), 'ip_address': helpers.get_xml_attr(session.getElementsByTagName('Player')[0], 'address').split(':')[-1],
'player': helpers.get_xml_attr(session.getElementsByTagName('Player')[0], 'title'), 'player': helpers.get_xml_attr(session.getElementsByTagName('Player')[0], 'title'),
'platform': helpers.get_xml_attr(session.getElementsByTagName('Player')[0], 'platform'), 'platform': helpers.get_xml_attr(session.getElementsByTagName('Player')[0], 'platform'),
'machine_id': machine_id, 'machine_id': machine_id,
@ -1038,7 +1038,7 @@ class PmsConnect(object):
'user_id': user_details['user_id'], 'user_id': user_details['user_id'],
'friendly_name': user_details['friendly_name'], 'friendly_name': user_details['friendly_name'],
'user_thumb': user_details['thumb'], 'user_thumb': user_details['thumb'],
'ip_address': helpers.get_xml_attr(session.getElementsByTagName('Player')[0], 'address'), 'ip_address': helpers.get_xml_attr(session.getElementsByTagName('Player')[0], 'address').split(':')[-1],
'player': helpers.get_xml_attr(session.getElementsByTagName('Player')[0], 'title'), 'player': helpers.get_xml_attr(session.getElementsByTagName('Player')[0], 'title'),
'platform': helpers.get_xml_attr(session.getElementsByTagName('Player')[0], 'platform'), 'platform': helpers.get_xml_attr(session.getElementsByTagName('Player')[0], 'platform'),
'machine_id': machine_id, 'machine_id': machine_id,
@ -1128,7 +1128,7 @@ class PmsConnect(object):
'user_id': user_details['user_id'], 'user_id': user_details['user_id'],
'friendly_name': user_details['friendly_name'], 'friendly_name': user_details['friendly_name'],
'user_thumb': user_details['thumb'], 'user_thumb': user_details['thumb'],
'ip_address': helpers.get_xml_attr(session.getElementsByTagName('Player')[0], 'address'), 'ip_address': helpers.get_xml_attr(session.getElementsByTagName('Player')[0], 'address').split(':')[-1],
'player': helpers.get_xml_attr(session.getElementsByTagName('Player')[0], 'title'), 'player': helpers.get_xml_attr(session.getElementsByTagName('Player')[0], 'title'),
'platform': helpers.get_xml_attr(session.getElementsByTagName('Player')[0], 'platform'), 'platform': helpers.get_xml_attr(session.getElementsByTagName('Player')[0], 'platform'),
'machine_id': machine_id, 'machine_id': machine_id,

View file

@ -24,6 +24,8 @@ class Users(object):
def get_user_list(self, kwargs=None): def get_user_list(self, kwargs=None):
data_tables = datatables.DataTables() data_tables = datatables.DataTables()
custom_where = ['users.deleted_user', 0]
columns = ['session_history.id', columns = ['session_history.id',
'users.user_id as user_id', 'users.user_id as user_id',
'users.custom_avatar_url as user_thumb', 'users.custom_avatar_url as user_thumb',
@ -48,7 +50,7 @@ class Users(object):
try: try:
query = data_tables.ssp_query(table_name='users', query = data_tables.ssp_query(table_name='users',
columns=columns, columns=columns,
custom_where=[], custom_where=[custom_where],
group_by=['users.user_id'], group_by=['users.user_id'],
join_types=['LEFT OUTER JOIN', join_types=['LEFT OUTER JOIN',
'LEFT OUTER JOIN', 'LEFT OUTER JOIN',

View file

@ -1397,6 +1397,40 @@ class WebInterface(object):
cherrypy.response.headers['Content-type'] = 'application/json' cherrypy.response.headers['Content-type'] = 'application/json'
return json.dumps({'message': 'no data received'}) 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 @cherrypy.expose
def search(self, query=''): def search(self, query=''):