Build 2602262159: restore jellyfin-first user source
This commit is contained in:
@@ -681,9 +681,9 @@ def get_all_users() -> list[Dict[str, Any]]:
|
||||
ORDER BY username COLLATE NOCASE
|
||||
"""
|
||||
).fetchall()
|
||||
results: list[Dict[str, Any]] = []
|
||||
all_rows: list[Dict[str, Any]] = []
|
||||
for row in rows:
|
||||
results.append(
|
||||
all_rows.append(
|
||||
{
|
||||
"id": row[0],
|
||||
"username": row[1],
|
||||
@@ -702,6 +702,55 @@ def get_all_users() -> list[Dict[str, Any]]:
|
||||
"is_expired": _is_datetime_in_past(row[11]),
|
||||
}
|
||||
)
|
||||
# Admin user management uses Jellyfin as the source of truth for non-admin
|
||||
# user objects. Jellyseerr rows are treated as enrichment-only and hidden
|
||||
# from admin/user-management views to avoid duplicate accounts in the UI.
|
||||
def _provider_rank(user: Dict[str, Any]) -> int:
|
||||
provider = str(user.get("auth_provider") or "local").strip().lower()
|
||||
if provider == "jellyfin":
|
||||
return 0
|
||||
if provider == "local":
|
||||
return 1
|
||||
if provider == "jellyseerr":
|
||||
return 2
|
||||
return 2
|
||||
|
||||
visible_candidates = [
|
||||
user
|
||||
for user in all_rows
|
||||
if not (
|
||||
str(user.get("auth_provider") or "local").strip().lower() == "jellyseerr"
|
||||
and str(user.get("role") or "user").strip().lower() != "admin"
|
||||
)
|
||||
]
|
||||
|
||||
visible_candidates.sort(
|
||||
key=lambda user: (
|
||||
0 if str(user.get("role") or "user").strip().lower() == "admin" else 1,
|
||||
0 if isinstance(user.get("jellyseerr_user_id"), int) else 1,
|
||||
_provider_rank(user),
|
||||
0 if user.get("last_login_at") else 1,
|
||||
int(user.get("id") or 0),
|
||||
)
|
||||
)
|
||||
seen_usernames: set[str] = set()
|
||||
seen_jellyseerr_ids: set[int] = set()
|
||||
results: list[Dict[str, Any]] = []
|
||||
for user in visible_candidates:
|
||||
username = str(user.get("username") or "").strip()
|
||||
if not username:
|
||||
continue
|
||||
username_key = username.lower()
|
||||
jellyseerr_user_id = user.get("jellyseerr_user_id")
|
||||
if isinstance(jellyseerr_user_id, int) and jellyseerr_user_id in seen_jellyseerr_ids:
|
||||
continue
|
||||
if username_key in seen_usernames:
|
||||
continue
|
||||
results.append(user)
|
||||
seen_usernames.add(username_key)
|
||||
if isinstance(jellyseerr_user_id, int):
|
||||
seen_jellyseerr_ids.add(jellyseerr_user_id)
|
||||
results.sort(key=lambda user: str(user.get("username") or "").lower())
|
||||
return results
|
||||
|
||||
|
||||
@@ -725,6 +774,17 @@ def set_user_jellyseerr_id(username: str, jellyseerr_user_id: Optional[int]) ->
|
||||
)
|
||||
|
||||
|
||||
def set_user_auth_provider(username: str, auth_provider: str) -> None:
|
||||
provider = (auth_provider or "local").strip().lower() or "local"
|
||||
with _connect() as conn:
|
||||
conn.execute(
|
||||
"""
|
||||
UPDATE users SET auth_provider = ? WHERE username = ?
|
||||
""",
|
||||
(provider, username),
|
||||
)
|
||||
|
||||
|
||||
def set_last_login(username: str) -> None:
|
||||
timestamp = datetime.now(timezone.utc).isoformat()
|
||||
with _connect() as conn:
|
||||
|
||||
Reference in New Issue
Block a user