fix disk monitor preferences profile ownership
This commit is contained in:
@@ -28,7 +28,7 @@ PROFILE_BACKUP_TABLES = [
|
||||
PROFILE_TABLE_SCOPES = {
|
||||
"rtorrent_profiles": "profile_id",
|
||||
"profile_preferences": "user_profile",
|
||||
"disk_monitor_preferences": "user_profile",
|
||||
"disk_monitor_preferences": "profile",
|
||||
"labels": "profile",
|
||||
"ratio_groups": "profile",
|
||||
"rss_feeds": "profile",
|
||||
@@ -44,7 +44,7 @@ PROFILE_TABLE_SCOPES = {
|
||||
PROFILE_TABLE_FILTERS = {
|
||||
"rtorrent_profiles": "id=?",
|
||||
"profile_preferences": "user_id=? AND profile_id=?",
|
||||
"disk_monitor_preferences": "user_id=? AND profile_id=?",
|
||||
"disk_monitor_preferences": "profile_id=?",
|
||||
"labels": "profile_id=?",
|
||||
"ratio_groups": "profile_id=?",
|
||||
"rss_feeds": "profile_id=?",
|
||||
@@ -273,6 +273,12 @@ def restore_app_backup(backup_id: int, user_id: int | None = None) -> dict:
|
||||
return {"restored": restored, "backup_type": "app"}
|
||||
|
||||
|
||||
def _single_profile_row(rows: list[dict]) -> list[dict]:
|
||||
if not rows:
|
||||
return []
|
||||
return [sorted(rows, key=lambda row: str(row.get("updated_at") or row.get("created_at") or ""), reverse=True)[0]]
|
||||
|
||||
|
||||
def _rewrite_profile_row(table: str, row: dict, user_id: int, target_profile_id: int) -> dict:
|
||||
clean = dict(row)
|
||||
if table == "rtorrent_profiles":
|
||||
@@ -305,6 +311,8 @@ def restore_profile_backup(backup_id: int, target_profile_id: int, user_id: int
|
||||
try:
|
||||
for table in PROFILE_BACKUP_TABLES:
|
||||
rows = tables.get(table) or []
|
||||
if table == "disk_monitor_preferences":
|
||||
rows = _single_profile_row([dict(row) for row in rows])
|
||||
where = PROFILE_TABLE_FILTERS.get(table)
|
||||
params = _profile_filter_params(table, user_id, int(target_profile_id))
|
||||
conn.execute(f"DELETE FROM {table} WHERE {where}", params)
|
||||
|
||||
Reference in New Issue
Block a user