Add user feature permissions and unified account management
Magent CI/CD / verify (push) Canceled after 1m19s
Magent CI/CD / deploy-prod (push) Canceled after 0s
Magent CI/CD / deploy-beta (push) Canceled after 0s

This commit is contained in:
2026-09-11 12:31:25 +12:00
parent e2be8b3872
commit ec0a866ef3
32 changed files with 650 additions and 214 deletions
+17 -7
View File
@@ -187,6 +187,9 @@ def _has_secure_bootstrap_admin_credentials() -> bool:
def init_db() -> None:
with _connect() as conn:
conn.execute("""CREATE TABLE IF NOT EXISTS user_feature_permissions (
user_id INTEGER NOT NULL, feature TEXT NOT NULL, enabled INTEGER NOT NULL,
PRIMARY KEY(user_id, feature))""")
conn.execute("""
CREATE TABLE IF NOT EXISTS jellyfin_user_links (
source TEXT NOT NULL, local_user_id INTEGER NOT NULL, jellyfin_user_id TEXT NOT NULL,
@@ -747,11 +750,16 @@ def init_db() -> None:
init_recap_schema(conn)
from .services.newsletter_store import init_schema as init_newsletter_schema
init_newsletter_schema(conn)
conn.execute("""CREATE TRIGGER IF NOT EXISTS delete_user_feature_permissions
AFTER DELETE ON users BEGIN
DELETE FROM user_feature_permissions WHERE user_id = OLD.id;
END""")
_backfill_auth_providers()
ensure_admin_user()
_backfill_request_repairs()
def start_request_repair(tracking: Dict[str, Any]) -> None:
"""Persist the new collection cycle before a managed file is removed."""
with _connect() as conn:
@@ -3823,21 +3831,23 @@ def list_portal_item_activity(item_id: int, *, limit: int = 300) -> list[Dict[st
]
def get_portal_overview() -> Dict[str, Any]:
def get_portal_overview(kind: Optional[str] = None) -> Dict[str, Any]:
with _connect() as conn:
kind_rows = conn.execute(
"""
SELECT kind, COUNT(*)
FROM portal_items
WHERE (? IS NULL OR kind = ?)
GROUP BY kind
"""
""", (kind, kind)
).fetchall()
status_rows = conn.execute(
"""
SELECT status, COUNT(*)
FROM portal_items
WHERE (? IS NULL OR kind = ?)
GROUP BY status
"""
""", (kind, kind)
).fetchall()
request_workflow_rows = conn.execute(
"""
@@ -3846,12 +3856,12 @@ def get_portal_overview() -> Dict[str, Any]:
COALESCE(workflow_media_status, ''),
COUNT(*)
FROM portal_items
WHERE kind = 'request'
WHERE kind = 'request' AND (? IS NULL OR kind = ?)
GROUP BY workflow_request_status, workflow_media_status
"""
""", (kind, kind)
).fetchall()
total_items_row = conn.execute("SELECT COUNT(*) FROM portal_items").fetchone()
total_comments_row = conn.execute("SELECT COUNT(*) FROM portal_comments").fetchone()
total_items_row = conn.execute("SELECT COUNT(*) FROM portal_items WHERE (? IS NULL OR kind = ?)", (kind, kind)).fetchone()
total_comments_row = conn.execute("SELECT COUNT(*) FROM portal_comments c JOIN portal_items i ON i.id = c.item_id WHERE (? IS NULL OR i.kind = ?)", (kind, kind)).fetchone()
request_workflow: Dict[str, Dict[str, int]] = {}
for row in request_workflow_rows:
request_status = str(row[0] or "")