Team management RPC adapters. This domain is a thin proxy to the hosted backend: every operation forwards an authenticated HTTP request to the OpenHuman backend (/teams/*) and returns the raw JSON response verbatim. It owns no local state, no domain types, and no server-side authorization — the backend enforces team ownership, role permissions, and tenant isolation; non-authorized callers receive the backend's 401/403 surfaced as an RPC error string. Covers team CRUD, membership, role changes, invites, usage, and active-team switching.
- Fetch the current user's active-team usage (
/teams/me/usage). - List teams for the authenticated user, fetch a single team, create / update / delete teams.
- Switch the active team, leave a team, join a team via invite code.
- List, create, and revoke team invites.
- Remove members and change member roles.
- Validate inputs (non-empty trimmed ids/names/codes) before any network call, with deterministic field-precedence in error messages.
- Percent-encode path segments safely (no path-injection via team/user ids).
| File | Role |
|---|---|
src/openhuman/team/mod.rs |
Export-only: declares ops/schemas, re-exports all ops fns and the controller-schema pair. |
src/openhuman/team/ops.rs |
Business logic — async fns that build a path, attach the session JWT, call the backend, and wrap the response in RpcOutcome::single_log. Contains URL-path builder + id-normalization helpers and their unit tests. |
src/openhuman/team/schemas.rs |
Controller schemas (all_team_controller_schemas, all_team_registered_controllers, team_schemas), param structs, and handle_* adapters that load config, deserialize params, and delegate to ops. |
src/openhuman/team/schemas_tests.rs |
Sibling test module for schemas.rs (wired via #[path]). |
Re-exported from mod.rs:
- Ops (all
async fn(... ) -> Result<RpcOutcome<Value>, String>):get_usage,list_members,list_teams,get_team,create_team,update_team,delete_team,switch_team,leave_team,join_team,create_invite,remove_member,change_member_role,list_invites,revoke_invite. - Schemas:
all_team_controller_schemas,all_team_registered_controllers,team_schemas.
Internal helpers in ops.rs (require_token, normalize_id, build_api_path, get_authed_value) are private.
Namespace team. Registered controllers (RPC method openhuman.team_<function>):
| Method | Backend call | Required inputs | Optional |
|---|---|---|---|
team_get_usage |
GET /teams/me/usage |
— | — |
team_list_members |
GET /teams/:teamId/members |
teamId |
— |
team_list_teams |
GET /teams |
— | — |
team_get_team |
GET /teams/:teamId |
teamId |
— |
team_create_team |
POST /teams |
name |
— |
team_update_team |
PUT /teams/:teamId |
teamId |
name |
team_delete_team |
DELETE /teams/:teamId |
teamId |
— |
team_switch_team |
POST /teams/:teamId/switch |
teamId |
— |
team_leave_team |
POST /teams/:teamId/leave |
teamId |
— |
team_join_team |
POST /teams/join |
code |
— |
team_create_invite |
POST /teams/:teamId/invites |
teamId |
maxUses, expiresInDays |
team_list_invites |
GET /teams/:teamId/invites |
teamId |
— |
team_revoke_invite |
DELETE /teams/:teamId/invites/:inviteId |
teamId, inviteId |
— |
team_remove_member |
DELETE /teams/:teamId/members/:userId |
teamId, userId |
— |
team_change_member_role |
PUT /teams/:teamId/members/:userId/role |
teamId, userId, role |
— |
Outputs are raw backend JSON (result field; array for list endpoints). Params are camelCase; handle_* fns deserialize via serde_json::from_value and surface invalid params: … on failure.
None. This domain exposes no agent tools.
None. No bus.rs; publishes/subscribes to no DomainEvents.
None local. State lives in the hosted backend. The only stored value it reads is the app-session JWT, fetched via crate::api::jwt::get_session_token (written by auth_store_session); it is sent as Authorization: Bearer … and never logged.
crate::api::config::effective_backend_api_url— resolves the backend base URL fromConfig.api_url.crate::api::jwt::get_session_token— pulls the session JWT used to authenticate every request.crate::api::BackendOAuthClient— HTTP client;authed_json(token, method, path, body)performs the authed call.crate::openhuman::config::Config— config passed into every op;config::rpc::load_config_with_timeoutloads it inside eachhandle_*.crate::core::all::{ControllerFuture, RegisteredController}andcrate::core::{ControllerSchema, FieldSchema, TypeSchema}— controller registry types.crate::rpc::RpcOutcome— return wrapper (single_log).reqwest(Method,Url) for HTTP + path building;serde/serde_jsonfor params and bodies.
src/core/all.rs— registersall_team_registered_controllers()into the controller registry andall_team_controller_schemas()into the schema list (the standard controller-only exposure path). No domain branches incli.rs/jsonrpc.rs.
- Pure proxy. No type modeling of teams/members/invites — everything is
serde_json::Valuepassthrough; the backend is the source of truth. - Error rendering:
get_authed_valuemaps failures with{e:#}(full anyhow chain), deliberately note.to_string(), so the underlying cause (DNS/TLS/timeout/non-2xx) is preserved for Sentry rather than the truncatedbackend request GET /teamslabel (see the in-code note referencing OPENHUMAN-TAURI-AD / TAURI-B2). - Path safety:
build_api_pathclears and pushes segments throughurl::path_segments_mut, percent-encoding reserved chars, spaces, and Unicode — ids liketeam/with?reservedcannot escape their segment. - Validation precedence is deterministic (tested):
team_idis normalized beforeuser_idbeforerole, so error messages are stable regardless of which other fields are also invalid. update_teamonly includesnamein the body when present and non-empty after trimming; an empty/whitespace name is dropped rather than sent.- Missing/blank session token yields
no backend session token; run auth_store_session firstbefore any network attempt.