fix automation visibility and execution by profile ownership

This commit is contained in:
Mateusz Gruszczyński
2026-06-07 22:52:17 +02:00
parent 79e0ce8051
commit 51e00a4e37
5 changed files with 232 additions and 118 deletions
+4 -5
View File
@@ -260,14 +260,13 @@ def cleanup_automations():
if not profile:
return jsonify({"ok": False, "error": "No profile"}), 400
profile_id = int(profile["id"])
user_id = default_user_id()
with connect() as conn:
exists = conn.execute("SELECT name FROM sqlite_master WHERE type='table' AND name='automation_history'").fetchone()
if not exists:
deleted = 0
else:
# Note: Cleanup panel removes only current-user automation logs for the active profile; saved rules stay intact.
cur = conn.execute("DELETE FROM automation_history WHERE user_id=? AND profile_id=?", (user_id, profile_id))
# Note: Automation history is profile-scoped and can include rules owned by multiple users.
cur = conn.execute("DELETE FROM automation_history WHERE profile_id=?", (profile_id,))
deleted = int(cur.rowcount or 0)
return ok({"deleted": deleted, "cleanup": cleanup_summary()})
@@ -303,8 +302,8 @@ def cleanup_all():
if not exists_auto:
deleted_auto = 0
else:
# Note: Full cleanup clears only the current user's automation history for the active profile.
cur = conn.execute("DELETE FROM automation_history WHERE user_id=? AND profile_id=?", (default_user_id(), active_profile_id))
# Note: Full cleanup clears automation history for the active profile, regardless of rule owner.
cur = conn.execute("DELETE FROM automation_history WHERE profile_id=?", (active_profile_id,))
deleted_auto = int(cur.rowcount or 0)
return ok({"deleted": {"jobs": deleted_jobs, "smart_queue_history": deleted_smart, "operation_logs": deleted_logs, "planner_history": deleted_planner, "automation_history": deleted_auto}, "cleanup": cleanup_summary()})