Repository navigation
Workspaces phase 3e: members and roles (#277) - #337
Merged
Merged
Conversation
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Part of #277. This is phase 3e of
documents/design/2.0-plan.md: roles leaveusers.roles.The model
users.rolesadmin,pending,widgetworkspace_membersrole(owner/admin/member) andagent_rolesper workspacetrigger_runneris the exception. It belongs to no workspace, so it keeps its agent roles inusers.roles.What changes
Members page at
/dashboard/members, with its API under/dashboard/api/members:GETlists the current workspace's members. Owners and admins of the workspace can call it, and so can platform admins.PUT /{user_id}setsroleandagent_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 /leaveleaves the current workspace. Anyone may call it, so it is allowlisted indashboard_authz.py. The account menu shows Leave this workspace to people with more than one workspace.member.update(withfrom/to),member.removeormember.leaveto the workspace's audit log.Moving the roles (
shared/utils/workspaces.py)move_roles_to_members()replacessync_default_members().users.rolesand records the run insystem_settings(workspaces.roles_moved_to_members).pendingusers and widget visitors. A member removed on the Members page stays removed.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 leavesusers.roleswith only the platform roles.users.roleslater move to the user's default-workspace membership. Approving apendinguser 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
ALLOWED_API_ROLESis 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.["user"].PUTwith 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
users.roles. The plan now says so.Tests
test_client_contract.pyis unchanged and passes. Its developer user is inserted with["developer"]and still uses its token.New
TestMembersintest_cross_workspace.pycovers:Also:
TestEveryRoutecallsPUT/DELETE /members/{user_id}from workspace A with B's owner and expects 404.TestMembersintest_workspaces_schema.pyis rewritten for the one-time move.users.rolesfor agent roles now read the membership:test_builtin_admin_roles,test_rbac_*,test_slack_user_ids,test_pat_authandtest_dashboard_tokens.To check the tests catch real bugs, I disabled five guards one at a time, and each one fails a test:
Results:
node --check.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.mddocs/dev/auth-and-access.md,database-and-migrations.md,openai-api-and-mcp.md,openai-compatibility.md,architecture.mdThe drift check lists four guides I didn't change. Each is still accurate:
docs/user/eu-ai-act.mdandusage-and-audit.md:audit_service.pyonly gained action constants.docs/dev/alerts.mdandtemplate-format.md:dashboard_server.pyonly gained the Members page route and the Users route's validation.