diff --git a/backend/app/gateway/scheduled_task_access.py b/backend/app/gateway/scheduled_task_access.py index 56fb7e0e8b..33d9482019 100644 --- a/backend/app/gateway/scheduled_task_access.py +++ b/backend/app/gateway/scheduled_task_access.py @@ -212,7 +212,7 @@ async def _owner(owner_id: str, token_version: int, *, auth_disabled_owner: bool user = get_auth_disabled_user() if is_auth_disabled() and owner_id == AUTH_DISABLED_USER_ID else None else: user = await get_local_provider().get_user(owner_id) - if user is None or str(user.id) != owner_id or getattr(user, "token_version", 0) != token_version or getattr(user, "needs_setup", False) or getattr(user, "system_role", None) == INTERNAL_SYSTEM_ROLE: + if user is None or str(user.id) != owner_id or getattr(user, "disabled", False) or getattr(user, "token_version", 0) != token_version or getattr(user, "needs_setup", False) or getattr(user, "system_role", None) == INTERNAL_SYSTEM_ROLE: return None return user diff --git a/backend/tests/test_scheduler_capability_access.py b/backend/tests/test_scheduler_capability_access.py index aa7e603bec..e950fabb39 100644 --- a/backend/tests/test_scheduler_capability_access.py +++ b/backend/tests/test_scheduler_capability_access.py @@ -18,8 +18,8 @@ from deerflow.persistence.scheduled_tasks import ActiveScheduledTaskMutationConf _PERMISSIONS = ("threads:read", "threads:write", "runs:create") -def _user(*, user_id="alice", token_version=0, role="user"): - return SimpleNamespace(id=user_id, token_version=token_version, system_role=role, needs_setup=False) +def _user(*, user_id="alice", token_version=0, role="user", disabled=False): + return SimpleNamespace(id=user_id, token_version=token_version, system_role=role, needs_setup=False, disabled=disabled) _FUTURE = (datetime.now(UTC) + timedelta(days=1)).replace(microsecond=0).isoformat() @@ -157,6 +157,21 @@ async def test_deleted_changed_or_revoked_owner_cannot_use_an_existing_grant(mon repo.list_manageable_from_thread.assert_not_awaited() +@pytest.mark.asyncio +async def test_suspended_owner_loses_existing_schedule_write_authority(monkeypatch): + prepare, repo, _, _, _, provider, resolve, _ = _setup(monkeypatch) + capability = await prepare() + provider.get_user.return_value = _user(disabled=True) + resolve.reset_mock() + + result = await capability.manage(action="create", request={}) + + assert result["status_code"] == 401 + repo.create.assert_not_awaited() + resolve.assert_not_awaited() + assert await prepare() is None + + @pytest.mark.asyncio async def test_live_permission_revocation_is_honored_each_action(monkeypatch): prepare, repo, _, _, _, _, resolve, _ = _setup(monkeypatch) diff --git a/docs/guide/scheduled-tasks.md b/docs/guide/scheduled-tasks.md index d41aba4f2f..f34620143e 100644 --- a/docs/guide/scheduled-tasks.md +++ b/docs/guide/scheduled-tasks.md @@ -121,6 +121,9 @@ live card with the schedule, the stop condition and buttons, and the agent replies in one or two sentences; IM and other non-web turns describe the schedule, the next run and the stop condition in plain text. +Conversation scheduling actions require an active owner account. The Gateway +returns `authority_expired` when the account is no longer active. + - **Which tasks a conversation manages.** The tasks created in it, and, in a run conversation (the chat a scheduled run posted into), the task that run belongs to: “pause this” or “move it to 10:00” work there too. This applies only to