Self-evolving Context Database for AI Agents. Unify Agent Memory, Knowledge RAG and Skills.
Python agent-contextagent-memoryagent-pluginsagentic-ragcontext-databasedsh-pluginknowledge-basememorymemory-managementself-evolvingvector-database
fix(watches): scope non-ROOT watch access to the owning user (#4802)
dingbene322ecc644d4
diff --git a/openviking/resource/watch_manager.py b/openviking/resource/watch_manager.pyindex ad181aa29..d021761b1 100644--- a/openviking/resource/watch_manager.py+++ b/openviking/resource/watch_manager.py@@ -362,9 +362,10 @@ class WatchManager:True if has permission, False otherwiseNotes:- - ROOT can access all tasks.- - ADMIN can access tasks within the same account.- - USER can only access tasks they created within the same account.+ - ROOT can access all tasks (system/scheduler bypass).+ - Every other role (including ADMIN) is scoped to tasks they own+ within the same account, so callers sharing an account but using+ different user_ids never see each other's tasks."""role_value = (role or "").lower()if role_value == "root":@@ -373,9 +374,6 @@ class WatchManager:if task.account_id != account_id:return False- if role_value == "admin":- return True-return task.user_id == user_id# ── Target index helpers ─────────────────────────────────────────────diff --git a/tests/resource/test_watch_manager.py b/tests/resource/test_watch_manager.pyindex 72df09d3f..d7d670dec 100644--- a/tests/resource/test_watch_manager.py+++ b/tests/resource/test_watch_manager.py@@ -603,6 +603,41 @@ class TestWatchManager:assert len(tasks) == 1assert tasks[0].is_active is True+ @pytest.mark.asyncio+ async def test_get_all_tasks_admin_scoped_to_own_tasks(+ self, watch_manager: WatchManager+ ):+ """ADMIN is scoped to its own tasks; ROOT still sees the whole account."""+ await watch_manager.create_task(path="/test/alice1", user_id="alice")+ await watch_manager.create_task(path="/test/bob1", user_id="bob")+ await watch_manager.create_task(path="/test/alice2", user_id="alice")++ # ROOT keeps the system-wide view.+ all_tasks = await watch_manager.get_all_tasks(+ account_id=TEST_ACCOUNT_ID, user_id="root", role="root"+ )+ assert len(all_tasks) == 3++ # ADMIN no longer sees the whole account — only its own tasks.+ alice_tasks = await watch_manager.get_all_tasks(+ account_id=TEST_ACCOUNT_ID, user_id="alice", role="admin"+ )+ assert {task.user_id for task in alice_tasks} == {"alice"}+ assert len(alice_tasks) == 2++ @pytest.mark.asyncio+ async def test_get_all_tasks_isolates_same_account_users(+ self, watch_manager: WatchManager+ ):+ """Same account, different user_id → each caller sees only its own tasks."""+ await watch_manager.create_task(path="/test/alice1", user_id="alice")+ await watch_manager.create_task(path="/test/bob1", user_id="bob")++ bob_tasks = await watch_manager.get_all_tasks(+ account_id=TEST_ACCOUNT_ID, user_id="bob", role="user"+ )+ assert {task.user_id for task in bob_tasks} == {"bob"}+@pytest.mark.asyncioasync def test_get_task_by_uri(self, watch_manager: WatchManager):"""Test getting a task by URI."""@@ -933,7 +968,7 @@ class TestSharedConnectorTargets:("carol", "user", ()),("bob", "user", (2,)),("alice", "user", (0, 1)),- ("bob", "admin", (0, 1, 2)),+ ("bob", "admin", (2,)),("bob", "root", (0, 1, 2)),],)