mirror of
https://github.com/Tautulli/Tautulli.git
synced 2025-07-10 23:42:37 -07:00
Add per-user history logging toggle. Uncheck to disable history logging for specific user.
On SSL cert bypass check that the method is available before allowing.
This commit is contained in:
parent
b0ded77571
commit
0877a6bf21
6 changed files with 61 additions and 15 deletions
|
@ -14,6 +14,7 @@ user Return the real Plex username
|
||||||
user_id Return the Plex user_id
|
user_id Return the Plex user_id
|
||||||
friendly_name Returns the friendly edited Plex username
|
friendly_name Returns the friendly edited Plex username
|
||||||
do_notify Returns bool value for whether the user should trigger notifications
|
do_notify Returns bool value for whether the user should trigger notifications
|
||||||
|
keep_history Returns bool value for whether the user's activity should be logged
|
||||||
|
|
||||||
DOCUMENTATION :: END
|
DOCUMENTATION :: END
|
||||||
</%doc>
|
</%doc>
|
||||||
|
@ -42,6 +43,12 @@ DOCUMENTATION :: END
|
||||||
</label>
|
</label>
|
||||||
<p class="help-block">Uncheck this if you do not want to receive notifications for this user's activity.</p>
|
<p class="help-block">Uncheck this if you do not want to receive notifications for this user's activity.</p>
|
||||||
</div>
|
</div>
|
||||||
|
<div class="checkbox">
|
||||||
|
<label>
|
||||||
|
<input type="checkbox" id="keep_history" name="keep_history" value="1" ${data['keep_history']}> Keep history
|
||||||
|
</label>
|
||||||
|
<p class="help-block">Uncheck this if you do not want this keep any history on this user's activity.</p>
|
||||||
|
</div>
|
||||||
</fieldset>
|
</fieldset>
|
||||||
</div>
|
</div>
|
||||||
<div class="modal-footer">
|
<div class="modal-footer">
|
||||||
|
@ -57,14 +64,18 @@ DOCUMENTATION :: END
|
||||||
$("#save_user_name").click(function() {
|
$("#save_user_name").click(function() {
|
||||||
var friendly_name = $("#friendly_name").val();
|
var friendly_name = $("#friendly_name").val();
|
||||||
var do_notify = 0;
|
var do_notify = 0;
|
||||||
|
var keep_history = 0;
|
||||||
if ($("#do_notify").is(":checked")) {
|
if ($("#do_notify").is(":checked")) {
|
||||||
do_notify = 1;
|
do_notify = 1;
|
||||||
}
|
}
|
||||||
|
if ($("#keep_history").is(":checked")) {
|
||||||
|
keep_history = 1;
|
||||||
|
}
|
||||||
|
|
||||||
% if data['user_id']:
|
% if data['user_id']:
|
||||||
$.ajax({
|
$.ajax({
|
||||||
url: 'edit_user',
|
url: 'edit_user',
|
||||||
data: {user_id: '${data['user_id']}', friendly_name: friendly_name, do_notify: do_notify},
|
data: {user_id: '${data['user_id']}', friendly_name: friendly_name, do_notify: do_notify, keep_history: keep_history},
|
||||||
cache: false,
|
cache: false,
|
||||||
async: true,
|
async: true,
|
||||||
success: function(data) {
|
success: function(data) {
|
||||||
|
@ -77,7 +88,7 @@ DOCUMENTATION :: END
|
||||||
% else:
|
% else:
|
||||||
$.ajax({
|
$.ajax({
|
||||||
url: 'edit_user',
|
url: 'edit_user',
|
||||||
data: {user: '${data['user']}', friendly_name: friendly_name, do_notify: do_notify},
|
data: {user: '${data['user']}', friendly_name: friendly_name, do_notify: do_notify, keep_history: keep_history},
|
||||||
cache: false,
|
cache: false,
|
||||||
async: true,
|
async: true,
|
||||||
success: function(data) {
|
success: function(data) {
|
||||||
|
|
|
@ -386,7 +386,8 @@ def dbcheck():
|
||||||
'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, 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)'
|
||||||
)
|
)
|
||||||
|
|
||||||
# Upgrade sessions table from earlier versions
|
# Upgrade sessions table from earlier versions
|
||||||
|
@ -540,6 +541,15 @@ def dbcheck():
|
||||||
'ALTER TABLE users ADD COLUMN do_notify INTEGER DEFAULT 1'
|
'ALTER TABLE users ADD COLUMN do_notify INTEGER DEFAULT 1'
|
||||||
)
|
)
|
||||||
|
|
||||||
|
# Upgrade sessions table from earlier versions
|
||||||
|
try:
|
||||||
|
c_db.execute('SELECT keep_history from users')
|
||||||
|
except sqlite3.OperationalError:
|
||||||
|
logger.debug(u"Altering database. Updating database table sessions.")
|
||||||
|
c_db.execute(
|
||||||
|
'ALTER TABLE users ADD COLUMN keep_history INTEGER DEFAULT 1'
|
||||||
|
)
|
||||||
|
|
||||||
conn_db.commit()
|
conn_db.commit()
|
||||||
c_db.close()
|
c_db.close()
|
||||||
|
|
||||||
|
|
|
@ -222,7 +222,7 @@ class DataFactory(object):
|
||||||
return dict
|
return dict
|
||||||
|
|
||||||
# TODO: The getter and setter for this needs to become a config getter/setter for more than just friendlyname
|
# TODO: The getter and setter for this needs to become a config getter/setter for more than just friendlyname
|
||||||
def set_user_friendly_name(self, user=None, user_id=None, friendly_name=None, do_notify=0):
|
def set_user_friendly_name(self, user=None, user_id=None, friendly_name=None, do_notify=0, keep_history=1):
|
||||||
if user_id:
|
if user_id:
|
||||||
if friendly_name.strip() == '':
|
if friendly_name.strip() == '':
|
||||||
friendly_name = None
|
friendly_name = None
|
||||||
|
@ -231,7 +231,8 @@ class DataFactory(object):
|
||||||
|
|
||||||
control_value_dict = {"user_id": user_id}
|
control_value_dict = {"user_id": user_id}
|
||||||
new_value_dict = {"friendly_name": friendly_name,
|
new_value_dict = {"friendly_name": friendly_name,
|
||||||
"do_notify": do_notify}
|
"do_notify": do_notify,
|
||||||
|
"keep_history": keep_history}
|
||||||
try:
|
try:
|
||||||
monitor_db.upsert('users', new_value_dict, control_value_dict)
|
monitor_db.upsert('users', new_value_dict, control_value_dict)
|
||||||
except Exception, e:
|
except Exception, e:
|
||||||
|
@ -244,7 +245,8 @@ class DataFactory(object):
|
||||||
|
|
||||||
control_value_dict = {"username": user}
|
control_value_dict = {"username": user}
|
||||||
new_value_dict = {"friendly_name": friendly_name,
|
new_value_dict = {"friendly_name": friendly_name,
|
||||||
"do_notify": do_notify}
|
"do_notify": do_notify,
|
||||||
|
"keep_history": keep_history}
|
||||||
try:
|
try:
|
||||||
monitor_db.upsert('users', new_value_dict, control_value_dict)
|
monitor_db.upsert('users', new_value_dict, control_value_dict)
|
||||||
except Exception, e:
|
except Exception, e:
|
||||||
|
@ -255,39 +257,44 @@ class DataFactory(object):
|
||||||
monitor_db = database.MonitorDatabase()
|
monitor_db = database.MonitorDatabase()
|
||||||
query = 'select username, ' \
|
query = 'select username, ' \
|
||||||
'(CASE WHEN friendly_name IS NULL THEN username ELSE friendly_name END),' \
|
'(CASE WHEN friendly_name IS NULL THEN username ELSE friendly_name END),' \
|
||||||
'do_notify ' \
|
'do_notify, keep_history ' \
|
||||||
'FROM users WHERE user_id = ?'
|
'FROM users WHERE user_id = ?'
|
||||||
result = monitor_db.select(query, args=[user_id])
|
result = monitor_db.select(query, args=[user_id])
|
||||||
if result:
|
if result:
|
||||||
user_detail = {'user_id': user_id,
|
user_detail = {'user_id': user_id,
|
||||||
'user': result[0][0],
|
'user': result[0][0],
|
||||||
'friendly_name': result[0][1],
|
'friendly_name': result[0][1],
|
||||||
'do_notify': helpers.checked(result[0][2])}
|
'do_notify': helpers.checked(result[0][2]),
|
||||||
|
'keep_history': helpers.checked(result[0][3])
|
||||||
|
}
|
||||||
return user_detail
|
return user_detail
|
||||||
else:
|
else:
|
||||||
user_detail = {'user_id': user_id,
|
user_detail = {'user_id': user_id,
|
||||||
'user': '',
|
'user': '',
|
||||||
'friendly_name': '',
|
'friendly_name': '',
|
||||||
'do_notify': ''}
|
'do_notify': '',
|
||||||
|
'keep_history': ''}
|
||||||
return user_detail
|
return user_detail
|
||||||
elif user:
|
elif user:
|
||||||
monitor_db = database.MonitorDatabase()
|
monitor_db = database.MonitorDatabase()
|
||||||
query = 'select user_id, ' \
|
query = 'select user_id, ' \
|
||||||
'(CASE WHEN friendly_name IS NULL THEN username ELSE friendly_name END),' \
|
'(CASE WHEN friendly_name IS NULL THEN username ELSE friendly_name END),' \
|
||||||
'do_notify ' \
|
'do_notify, keep_history ' \
|
||||||
'FROM users WHERE username = ?'
|
'FROM users WHERE username = ?'
|
||||||
result = monitor_db.select(query, args=[user])
|
result = monitor_db.select(query, args=[user])
|
||||||
if result:
|
if result:
|
||||||
user_detail = {'user_id': result[0][0],
|
user_detail = {'user_id': result[0][0],
|
||||||
'user': user,
|
'user': user,
|
||||||
'friendly_name': result[0][1],
|
'friendly_name': result[0][1],
|
||||||
'do_notify': helpers.checked(result[0][2])}
|
'do_notify': helpers.checked(result[0][2]),
|
||||||
|
'keep_history': helpers.checked(result[0][3])}
|
||||||
return user_detail
|
return user_detail
|
||||||
else:
|
else:
|
||||||
user_detail = {'user_id': None,
|
user_detail = {'user_id': None,
|
||||||
'user': user,
|
'user': user,
|
||||||
'friendly_name': '',
|
'friendly_name': '',
|
||||||
'do_notify': ''}
|
'do_notify': '',
|
||||||
|
'keep_history': ''}
|
||||||
return user_detail
|
return user_detail
|
||||||
|
|
||||||
return None
|
return None
|
||||||
|
|
|
@ -52,7 +52,7 @@ class HTTPHandler(object):
|
||||||
|
|
||||||
if uri:
|
if uri:
|
||||||
if proto.upper() == 'HTTPS':
|
if proto.upper() == 'HTTPS':
|
||||||
if not self.ssl_verify:
|
if not self.ssl_verify and hasattr(ssl, '_create_unverified_context'):
|
||||||
context = ssl._create_unverified_context()
|
context = ssl._create_unverified_context()
|
||||||
handler = HTTPSConnection(host=self.host, port=self.port, timeout=10, context=context)
|
handler = HTTPSConnection(host=self.host, port=self.port, timeout=10, context=context)
|
||||||
logger.warn(u"PlexPy HTTP Handler :: Unverified HTTPS request made. This connection is not secure.")
|
logger.warn(u"PlexPy HTTP Handler :: Unverified HTTPS request made. This connection is not secure.")
|
||||||
|
|
|
@ -179,6 +179,10 @@ class MonitorProcessing(object):
|
||||||
self.db.upsert('sessions', timestamp, keys)
|
self.db.upsert('sessions', timestamp, keys)
|
||||||
|
|
||||||
def write_session_history(self, session=None, import_metadata=None, is_import=False, import_ignore_interval=0):
|
def write_session_history(self, session=None, import_metadata=None, is_import=False, import_ignore_interval=0):
|
||||||
|
from plexpy import datafactory
|
||||||
|
|
||||||
|
data_factory = datafactory.DataFactory()
|
||||||
|
user_details = data_factory.get_user_friendly_name(user=session['user'])
|
||||||
|
|
||||||
if session:
|
if session:
|
||||||
logging_enabled = False
|
logging_enabled = False
|
||||||
|
@ -218,6 +222,10 @@ class MonitorProcessing(object):
|
||||||
(session['rating_key'], str(int(stopped) - session['started']),
|
(session['rating_key'], str(int(stopped) - session['started']),
|
||||||
import_ignore_interval))
|
import_ignore_interval))
|
||||||
|
|
||||||
|
if not user_details['keep_history']:
|
||||||
|
logging_enabled = False
|
||||||
|
logger.debug(u"PlexPy Monitor :: History logging for user '%s' is disabled." % session['user'])
|
||||||
|
|
||||||
if logging_enabled:
|
if logging_enabled:
|
||||||
# logger.debug(u"PlexPy Monitor :: Attempting to write to session_history table...")
|
# logger.debug(u"PlexPy Monitor :: Attempting to write to session_history table...")
|
||||||
query = 'INSERT INTO session_history (started, stopped, rating_key, parent_rating_key, ' \
|
query = 'INSERT INTO session_history (started, stopped, rating_key, parent_rating_key, ' \
|
||||||
|
|
|
@ -179,10 +179,17 @@ class WebInterface(object):
|
||||||
do_notify = kwargs.get('do_notify')
|
do_notify = kwargs.get('do_notify')
|
||||||
else:
|
else:
|
||||||
do_notify = 0
|
do_notify = 0
|
||||||
|
if 'keep_history' in kwargs:
|
||||||
|
keep_history = kwargs.get('keep_history')
|
||||||
|
else:
|
||||||
|
keep_history = 0
|
||||||
if user_id:
|
if user_id:
|
||||||
try:
|
try:
|
||||||
data_factory = datafactory.DataFactory()
|
data_factory = datafactory.DataFactory()
|
||||||
data_factory.set_user_friendly_name(user_id=user_id, friendly_name=friendly_name, do_notify=do_notify)
|
data_factory.set_user_friendly_name(user_id=user_id,
|
||||||
|
friendly_name=friendly_name,
|
||||||
|
do_notify=do_notify,
|
||||||
|
keep_history=keep_history)
|
||||||
|
|
||||||
status_message = "Successfully updated user."
|
status_message = "Successfully updated user."
|
||||||
return status_message
|
return status_message
|
||||||
|
@ -192,7 +199,10 @@ class WebInterface(object):
|
||||||
if user:
|
if user:
|
||||||
try:
|
try:
|
||||||
data_factory = datafactory.DataFactory()
|
data_factory = datafactory.DataFactory()
|
||||||
data_factory.set_user_friendly_name(user=user, friendly_name=friendly_name, do_notify=do_notify)
|
data_factory.set_user_friendly_name(user=user,
|
||||||
|
friendly_name=friendly_name,
|
||||||
|
do_notify=do_notify,
|
||||||
|
keep_history=keep_history)
|
||||||
|
|
||||||
status_message = "Successfully updated user."
|
status_message = "Successfully updated user."
|
||||||
return status_message
|
return status_message
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue