Skip to content

Workspaces phase 3e: members and roles (#277) - #337

Merged
antiv merged 1 commit into
mainfrom
workspaces-phase-3e
Nov 12, 2026
Merged

antiv merged 1 commit into
mainfrom
workspaces-phase-3e

Conversation

@antiv

@antiv antiv commented Nov 11, 2026

Copy link
Copy Markdown
Owner

Part of #277. This is phase 3e of documents/design/2.0-plan.md: roles leave users.roles.

The model

Where Holds Edited on
users.roles platform roles: admin, pending, widget Users (platform admins)
workspace_members role (owner/admin/member) and agent_roles per workspace Members (owners)

trigger_runner is the exception. It belongs to no workspace, so it keeps its agent roles in users.roles.

What changes

Members page at /dashboard/members, with its API under /dashboard/api/members:

  • GET lists the current workspace's members. Owners and admins of the workspace can call it, and so can platform admins.
  • PUT /{user_id} sets role and agent_roles. DELETE /{user_id} removes a member; the user record stays. Only an owner or a platform admin may call these; a workspace admin gets 403.
  • POST /leave leaves the current workspace. Anyone may call it, so it is allowlisted in dashboard_authz.py. The account menu shows Leave this workspace to people with more than one workspace.
  • The last owner can't be demoted, removed or leave (409).
  • Agent roles are names of 1–64 characters, and never a platform role (400).
  • Every change writes member.update (with from/to), member.remove or member.leave to the workspace's audit log.

Moving the roles (shared/utils/workspaces.py)

  • Startup. move_roles_to_members() replaces sync_default_members().
    • The first time it runs, it derives the default workspace's memberships the way phase 2 did. For an installation upgrading from 1.x, this also creates the memberships.
    • It then strips agent roles off users.roles and records the run in system_settings (workspaces.roles_moved_to_members).
    • On every later start it only removes the memberships of pending users and widget visitors. A member removed on the Members page stays removed.
  • Inserting a user with agent roles. The 1.x code paths, get_or_create_user (["user"]), the Users page's Add User and the contract test all write users this way. The listener puts those roles on the membership of the user's home workspace and leaves users.roles with only the platform roles.
  • Role changes. Changing platform roles no longer touches memberships. Agent roles written to users.roles later move to the user's default-workspace membership. Approving a pending user who is a member nowhere adds them to the default workspace, with the agent roles the change wrote, or ["user"].

Callers that read agent roles

  • API role check. ALLOWED_API_ROLES is now matched against the user's platform roles plus their agent roles in the request's workspace (pat_auth.api_roles). This applies both when a token is used and when the account menu decides whether to offer one. The check now runs after the workspace is resolved.
  • Slack carry-over. It copies the old id's default-workspace agent roles.
  • Platform → Workspaces. The first owner gets their default-workspace agent roles, or ["user"].
  • Users page. It sets platform roles only. PUT with an agent role is refused and the message points to Members. Add User still takes any roles, and the listener moves the agent roles to the user's default-workspace membership.

For the release notes

  • Downgrade. Going back to 1.x after the first start of this version loses agent roles, because 1.x reads them from users.roles. The plan now says so.
  • Where roles went. Agent roles are now set per workspace on Members. No 1.x client changes roles through the API, so only the notes need to say this.

Tests

test_client_contract.py is unchanged and passes. Its developer user is inserted with ["developer"] and still uses its token.

New TestMembers in test_cross_workspace.py covers:

  • what an owner sees;
  • changing a member's role and agent roles, with audit;
  • agent roles deciding which agents run;
  • the API reading the token's workspace;
  • the refusals;
  • a workspace admin only looking;
  • a plain member getting 403;
  • the last owner staying;
  • remove and leave;
  • the Users page setting platform roles only.

Also:

  • TestEveryRoute calls PUT/DELETE /members/{user_id} from workspace A with B's owner and expects 404.
  • TestMembers in test_workspaces_schema.py is rewritten for the one-time move.
  • Tests that read users.roles for agent roles now read the membership: test_builtin_admin_roles, test_rbac_*, test_slack_user_ids, test_pat_auth and test_dashboard_tokens.

To check the tests catch real bugs, I disabled five guards one at a time, and each one fails a test:

  • the last-owner check;
  • the owner-only check;
  • refusing platform roles as agent roles;
  • the API reading the membership;
  • the leave allowlist.

Results:

  • Full suite: 1940 tests pass, 1 skipped.
  • Members and Users render, and the new scripts pass node --check.
  • I haven't clicked through the pages in a browser.

Docs

Updated:

  • docs/user/users-and-roles.md (platform roles vs agent roles, the Members page, letting a new person in)
  • personal-access-tokens.md, slack.md, workspaces.md, getting-started.md
  • docs/dev/auth-and-access.md, database-and-migrations.md, openai-api-and-mcp.md, openai-compatibility.md, architecture.md

The drift check lists four guides I didn't change. Each is still accurate:

  • docs/user/eu-ai-act.md and usage-and-audit.md: audit_service.py only gained action constants.
  • docs/dev/alerts.md and template-format.md: dashboard_server.py only gained the Members page route and the Users route's validation.

Roles leave users.roles. A membership holds the user's role and agent
roles in its workspace; users.roles keeps the platform roles admin,
pending and widget.

- Workspace settings → Members (/dashboard/members, API under
  /dashboard/api/members): an owner, or a platform administrator, changes
  a member's role and agent roles and removes a member; a workspace admin
  only looks; anyone leaves the current workspace (allowlisted, also in
  the account menu). The last owner can't be demoted, removed or leave.
  Every change is audited (member.update, .remove, .leave).
- move_roles_to_members() replaces sync_default_members() at startup. The
  first time it derives the memberships as phase 2 did and moves agent
  roles off users.roles (recorded in system_settings); every start it
  removes the memberships of pending users and widget visitors.
- A user inserted with agent roles, as 1.x code and get_or_create_user
  write them, gets them on their home workspace's membership. Agent roles
  written to users.roles later go to the default-workspace membership.
  trigger_runner keeps its roles: it belongs to no workspace.
- ALLOWED_API_ROLES is matched on the agent roles of the token's
  workspace, for using a token and for offering one.
- The Users page sets platform roles only. Slack's role carry-over copies
  the old id's default-workspace agent roles. Platform → Workspaces gives
  the first owner their default-workspace agent roles.
@antiv
antiv merged commit 1ab58da into main Nov 12, 2026
2 checks passed
@antiv
antiv deleted the workspaces-phase-3e branch November 12, 2026 07:32
@antiv antiv mentioned this pull request Nov 13, 2026
22 tasks done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant