Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions docs/en/api/08-admin.md
Original file line number Diff line number Diff line change
Expand Up @@ -1395,6 +1395,8 @@ ov admin register-user acme bob-private --role user \

List active users in a workspace. Users with deletion in progress are omitted.

Both HTTP and MCP `list_users` read the current process's in-memory user registry without refreshing files during the query. User changes completed in this process are immediately visible; changes from other processes become visible after the background watcher synchronizes them or the registry is reloaded.

**Processing Flow:**
1. Verify requester has ROOT privileges or is an ADMIN of the account
2. Call API Key Manager to get active users list (in creation order)
Expand Down
2 changes: 2 additions & 0 deletions docs/zh/api/08-admin.md
Original file line number Diff line number Diff line change
Expand Up @@ -1272,6 +1272,8 @@ ov admin register-user acme bob-private --role user \

列出工作区中的活跃用户。正在删除中的用户不会返回。

HTTP 和 MCP 的 `list_users` 都直接读取当前进程的内存用户登记信息,查询时不刷新文件。本进程完成的用户修改立即可见;其他进程的修改在后台 watcher 同步或登记信息重新加载后可见。

**处理流程:**
1. 验证请求者具有 ROOT 权限,或为本账户的 ADMIN
2. 调用 API Key Manager 获取活跃用户列表(按创建顺序排列)
Expand Down
3 changes: 0 additions & 3 deletions openviking/server/mcp_endpoint.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,6 @@
_extract_api_key,
get_api_key_manager_or_raise,
normalize_actor_peer_header,
registry_watcher_running,
resolve_identity,
should_expose_user_key,
)
Expand Down Expand Up @@ -373,8 +372,6 @@ async def list_users(
if include_credentials and not should_expose_user_key(request):
raise PermissionDeniedError("Credential disclosure is disabled in trusted auth mode")
manager = get_api_key_manager_or_raise(request)
if not registry_watcher_running(request):
await manager.refresh_account_users_from_store(ctx.account_id)
result = manager.get_users_page(
ctx.account_id,
limit=limit,
Expand Down
2 changes: 0 additions & 2 deletions openviking/server/routers/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -889,8 +889,6 @@ async def list_users(
"""List users in an account, in creation order. `name` supports wildcard (* and ?) matching."""
_check_account_access(ctx, account_id)
manager = _get_api_key_manager(request)
if not registry_watcher_running(request):
await manager.refresh_account_users_from_store(account_id)
expose_key = should_expose_user_key(request)
users = manager.get_users_page(
account_id,
Expand Down
41 changes: 29 additions & 12 deletions tests/server/test_admin_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -2004,34 +2004,51 @@ async def _record_read(path: str):
assert read_paths == ["/local/_system/accounts.json"]


async def test_list_users_without_watcher_reads_only_target_user_registry(
async def test_list_users_reads_memory_without_storage(
lightweight_admin_client: httpx.AsyncClient,
lightweight_admin_app: FastAPI,
monkeypatch: pytest.MonkeyPatch,
):
"""Without a watcher, user listing must not load unrelated registries."""
"""HTTP and MCP list locally registered users even when storage is unavailable."""
from types import SimpleNamespace

from openviking.server import mcp_endpoint

acct = _uid()
await lightweight_admin_client.post(
"/api/v1/admin/accounts",
json={"account_id": acct, "admin_user_id": "alice"},
headers=root_headers(),
)
manager = lightweight_admin_app.state.api_key_manager
original_read_json = manager._legacy._read_json
read_paths: list[str] = []

async def _record_read(path: str):
read_paths.append(path)
return await original_read_json(path)

monkeypatch.setattr(manager._legacy, "_read_json", _record_read)
created = await lightweight_admin_client.post(
f"/api/v1/admin/accounts/{acct}/users",
json={"user_id": "bob", "role": "user"},
headers=root_headers(),
)
assert created.status_code == 200, created.text
monkeypatch.setattr(
lightweight_admin_app.state.fake_service.viking_fs.agfs,
"read",
Mock(side_effect=OSError("registry storage unavailable")),
)

resp = await lightweight_admin_client.get(
f"/api/v1/admin/accounts/{acct}/users", headers=root_headers()
)

assert resp.status_code == 200, resp.text
assert read_paths == [f"/local/{acct}/_system/users.json"]
assert [user["user_id"] for user in resp.json()["result"]] == ["alice", "bob"]

request = FastAPIRequest({"type": "http", "app": lightweight_admin_app})
context = SimpleNamespace(request_context=SimpleNamespace(request=request))
token = mcp_endpoint._mcp_ctx.set(RequestContext(UserIdentifier(acct, "alice"), Role.ADMIN))
try:
assert await mcp_endpoint.list_users(context) == {
"users": [{"user_id": "alice"}, {"user_id": "bob"}],
"total": 2,
}
finally:
mcp_endpoint._mcp_ctx.reset(token)


async def test_list_users_for_default_account_without_users_file_returns_empty_list(
Expand Down