Fix importing Plex usernames

* Fixes #1710
* Also import the user title (Full Name)
This commit is contained in:
JonnyWong16 2022-04-08 20:00:48 -07:00
parent e996c4b375
commit aa6592eec7
No known key found for this signature in database
GPG key ID: B1F1F9807184697A
3 changed files with 19 additions and 3 deletions

View file

@ -714,8 +714,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, friendly_name TEXT, '
'thumb TEXT, custom_avatar_url TEXT, email TEXT, is_active INTEGER DEFAULT 1, is_admin INTEGER DEFAULT 0, '
'is_home_user INTEGER DEFAULT NULL, is_allow_sync INTEGER DEFAULT NULL, is_restricted INTEGER DEFAULT NULL, '
'thumb TEXT, custom_avatar_url TEXT, title TEXT, email TEXT, '
'is_active INTEGER DEFAULT 1, is_admin INTEGER DEFAULT 0, 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, deleted_user INTEGER DEFAULT 0, '
'allow_guest INTEGER DEFAULT 0, user_token TEXT, server_token TEXT, shared_libraries TEXT, '
'filter_all TEXT, filter_movies TEXT, filter_tv TEXT, filter_music TEXT, filter_photos TEXT)'
@ -1909,6 +1910,15 @@ def dbcheck():
'ALTER TABLE users ADD COLUMN is_active INTEGER DEFAULT 1'
)
# Upgrade users table from earlier versions
try:
c_db.execute('SELECT title FROM users')
except sqlite3.OperationalError:
logger.debug("Altering database. Updating database table users.")
c_db.execute(
'ALTER TABLE users ADD COLUMN title TEXT'
)
# Upgrade notify_log table from earlier versions
try:
c_db.execute('SELECT poster_url FROM notify_log')

View file

@ -357,6 +357,7 @@ class PlexTV(object):
for a in xml_head:
own_details = {"user_id": helpers.get_xml_attr(a, 'id'),
"username": helpers.get_xml_attr(a, 'username'),
"title": helpers.get_xml_attr(a, 'title'),
"thumb": helpers.get_xml_attr(a, 'thumb'),
"email": helpers.get_xml_attr(a, 'email'),
"is_active": 1,
@ -384,7 +385,8 @@ class PlexTV(object):
for a in xml_head:
friend = {"user_id": helpers.get_xml_attr(a, 'id'),
"username": helpers.get_xml_attr(a, 'title'),
"username": helpers.get_xml_attr(a, 'username'),
"title": helpers.get_xml_attr(a, 'title'),
"thumb": helpers.get_xml_attr(a, 'thumb'),
"email": helpers.get_xml_attr(a, 'email'),
"is_active": 1,

View file

@ -84,6 +84,10 @@ def refresh_users():
else:
item['custom_avatar_url'] = item['thumb']
# Check if title is the same as the username
if item['title'] == item['username']:
item['title'] = None
monitor_db.upsert('users', key_dict=keys_dict, value_dict=item)
query = 'UPDATE users SET is_active = 0 WHERE user_id NOT IN ({})'.format(', '.join(['?'] * len(user_ids)))