Skip to content

feat(authorization): support PATCH for membership role assignments - #212

Open
csrbarber wants to merge 1 commit into
mainfrom
ent-8219-emulate-membership-role-assignments-patch
Open

csrbarber wants to merge 1 commit into
mainfrom
ent-8219-emulate-membership-role-assignments-patch

Conversation

@csrbarber

@csrbarber csrbarber commented Nov 18, 2026 •

Copy link
Copy Markdown

Summary

Clients can now add and remove direct membership role assignments in one atomic PATCH against emulate, without falling back to separate POST and DELETE requests. A failed entry leaves all assignments unchanged.

Proof

With a local emulator seeded with a membership and a viewer grant, I ran:

curl -i -X PATCH 'http://127.0.0.1:4189/authorization/organization_memberships/om_00000000000000000000000819/role_assignments' \
  -H 'Authorization: Bearer sk_test_default' \
  -H 'Content-Type: application/json' \
  --data '{"add":[{"role_slug":"editor","resource_type_slug":"doc","resource_external_id":"patch-smoke"}],"remove":[{"role_slug":"viewer","resource_id":"authz_resource_01M7R38A4T137ZM79CV0BXVYBA"}]}'
HTTP/1.1 204 No Content

The response body was empty. GET listed only viewer before and only editor after.

  • Route tests: mixed add/remove, skipped existing add and missing remove, 0/101 entry bounds, overlap with same and mixed selectors, missing role/membership and cross-organization resource, missing selector, and shadowed role removal. Rejected updates leave grants unchanged.
  • bun test, bun run typecheck, bun run lint, bun run fmt:check, and bun run gen:supported passed.

The pinned @workos/openapi-spec@0.160.0 omits this operation, so regenerating the support table produced no diff. bun run check:coverage with the pinned spec still exits nonzero for the same 82 missing operations as main and reports this PATCH as emulator-only.

Refs ENT-8219

Link to Devin session: https://workos.devinenterprise.com/sessions/6de12c49e35e45c2a9b60989946dc291
Open in Devin Desktop: https://workos.devinenterprise.com/desktop/session/6de12c49e35e45c2a9b60989946dc291?variant=devin
Requested by: @csrbarber


🟢 Devin Review found nothing to fix · View findings

Devin Review

Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
@linear-code

linear-code Bot commented Nov 18, 2026

Copy link
Copy Markdown

ENT-8219

@greptile-apps

greptile-apps Bot commented Nov 18, 2026 •

Copy link
Copy Markdown

RetriggerView in GreptileConfidence Score: 5/5

[Medium impact] The PR appears safe to merge.

Summary

Adds one-request updates for direct membership role assignments, with checks before any grants change.

  • Membership role grants can now be added and removed in one PATCH.

No actionable issues found.

Reviews (1) · Last reviewed commit: "feat(authorization): support PATCH for m..." · Reviewed by Greptile

@devin-ai-integration

Copy link
Copy Markdown
Contributor

I'll fix CI failures and address comments from users with write access. I'll skip comments containing "(aside)".

  • Disable automatic comment, CI, and merge conflict monitoring

Original prompt from Colin

Implement the following handoff exactly. Follow its Branches, Delivery and Done sections.

# Handoff: Support the membership role assignments PATCH in emulate

Ticket: https://linear.app/workos/issue/ENT-8219/add-and-remove-organization-membership-role-assignments-in-one-request
Context: production implementation https://github.com/workos/workos/pull/80133 (write path) and https://github.com/workos/workos/pull/80615 (endpoint); API reference https://workos.com/docs/reference/fga/role-assignment`#`update-role-assignments-for-an-organization-membership
Repo: workos/emulate (Bun). Line numbers are against main at ed58c45 (November 18, 2026).
Read CLAUDE.md (where docs go, gen:supported) and docs/behavior.md before starting.

#``# Outcome

PATCH /authorization/organization_memberships/:id/role_assignments works in emulate the way it does in production: it takes add and remove lists of role assignments, applies them all or none, and returns 204. Customers testing against emulate can switch from per-assignment POST/DELETE to PATCH without their tests breaking.

#``# The rule

Validate every entry before writing anything. A request that fails any check changes nothing.

#``# Background the agent needs

  • The existing membership handlers are in src/workos/routes/authorization-checks.ts: GET (line 299), POST (line 430), DELETE /:assignmentId (line 472), and DELETE by criteria (line 487).
  • POST resolves the role with resolvePrimaryRole(ws, membership.organization_id, roleSlug) (404 Role when missing or belonging to another organization) and the resource with resolveResourceTarget(ws, body, membership.organization_id), then inserts into ws.roleAssignments.
  • DELETE by criteria matches by resolved role.id and resource_id, not slug, because an organization role can shadow an environment role of the same slug. Copy that matching.
  • Membership role assignments (ws.roleAssignments) and group role assignments (ws.groupRoleAssignments) are separ... (4609 chars truncated...)

@devin-ai-integration devin-ai-integration Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ Devin Review: No Issues Found

Devin Review analyzed this PR and found no bugs or issues to report.

Devin Review

@csrbarber
csrbarber requested a review from gjtorikian November 19, 2026 13:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

1 participant