mirror of
https://github.com/Tautulli/Tautulli.git
synced 2025-07-11 15:56:07 -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
|
@ -386,7 +386,8 @@ def dbcheck():
|
|||
'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, '
|
||||
'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
|
||||
|
@ -540,6 +541,15 @@ def dbcheck():
|
|||
'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()
|
||||
c_db.close()
|
||||
|
||||
|
|
|
@ -222,7 +222,7 @@ class DataFactory(object):
|
|||
return dict
|
||||
|
||||
# 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 friendly_name.strip() == '':
|
||||
friendly_name = None
|
||||
|
@ -231,7 +231,8 @@ class DataFactory(object):
|
|||
|
||||
control_value_dict = {"user_id": user_id}
|
||||
new_value_dict = {"friendly_name": friendly_name,
|
||||
"do_notify": do_notify}
|
||||
"do_notify": do_notify,
|
||||
"keep_history": keep_history}
|
||||
try:
|
||||
monitor_db.upsert('users', new_value_dict, control_value_dict)
|
||||
except Exception, e:
|
||||
|
@ -244,7 +245,8 @@ class DataFactory(object):
|
|||
|
||||
control_value_dict = {"username": user}
|
||||
new_value_dict = {"friendly_name": friendly_name,
|
||||
"do_notify": do_notify}
|
||||
"do_notify": do_notify,
|
||||
"keep_history": keep_history}
|
||||
try:
|
||||
monitor_db.upsert('users', new_value_dict, control_value_dict)
|
||||
except Exception, e:
|
||||
|
@ -255,39 +257,44 @@ class DataFactory(object):
|
|||
monitor_db = database.MonitorDatabase()
|
||||
query = 'select username, ' \
|
||||
'(CASE WHEN friendly_name IS NULL THEN username ELSE friendly_name END),' \
|
||||
'do_notify ' \
|
||||
'do_notify, keep_history ' \
|
||||
'FROM users WHERE user_id = ?'
|
||||
result = monitor_db.select(query, args=[user_id])
|
||||
if result:
|
||||
user_detail = {'user_id': user_id,
|
||||
'user': result[0][0],
|
||||
'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
|
||||
else:
|
||||
user_detail = {'user_id': user_id,
|
||||
'user': '',
|
||||
'friendly_name': '',
|
||||
'do_notify': ''}
|
||||
'do_notify': '',
|
||||
'keep_history': ''}
|
||||
return user_detail
|
||||
elif user:
|
||||
monitor_db = database.MonitorDatabase()
|
||||
query = 'select user_id, ' \
|
||||
'(CASE WHEN friendly_name IS NULL THEN username ELSE friendly_name END),' \
|
||||
'do_notify ' \
|
||||
'do_notify, keep_history ' \
|
||||
'FROM users WHERE username = ?'
|
||||
result = monitor_db.select(query, args=[user])
|
||||
if result:
|
||||
user_detail = {'user_id': result[0][0],
|
||||
'user': user,
|
||||
'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
|
||||
else:
|
||||
user_detail = {'user_id': None,
|
||||
'user': user,
|
||||
'friendly_name': '',
|
||||
'do_notify': ''}
|
||||
'do_notify': '',
|
||||
'keep_history': ''}
|
||||
return user_detail
|
||||
|
||||
return None
|
||||
|
|
|
@ -52,7 +52,7 @@ class HTTPHandler(object):
|
|||
|
||||
if uri:
|
||||
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()
|
||||
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.")
|
||||
|
|
|
@ -179,6 +179,10 @@ class MonitorProcessing(object):
|
|||
self.db.upsert('sessions', timestamp, keys)
|
||||
|
||||
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:
|
||||
logging_enabled = False
|
||||
|
@ -218,6 +222,10 @@ class MonitorProcessing(object):
|
|||
(session['rating_key'], str(int(stopped) - session['started']),
|
||||
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:
|
||||
# logger.debug(u"PlexPy Monitor :: Attempting to write to session_history table...")
|
||||
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')
|
||||
else:
|
||||
do_notify = 0
|
||||
if 'keep_history' in kwargs:
|
||||
keep_history = kwargs.get('keep_history')
|
||||
else:
|
||||
keep_history = 0
|
||||
if user_id:
|
||||
try:
|
||||
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."
|
||||
return status_message
|
||||
|
@ -192,7 +199,10 @@ class WebInterface(object):
|
|||
if user:
|
||||
try:
|
||||
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."
|
||||
return status_message
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue