Skip to content

fix(authorization): answer a repeated role assignment with the one already held - #210

Open
etiennecoutaud wants to merge 1 commit into
workos:mainfrom
etiennecoutaud:fix/authorization-idempotent-role-assignment
Open

etiennecoutaud wants to merge 1 commit into
workos:mainfrom
etiennecoutaud:fix/authorization-idempotent-role-assignment

Conversation

@etiennecoutaud

Copy link
Copy Markdown

Summary

POST /authorization/organization_memberships/:id/role_assignments inserted a new assignment on every call, so assigning the same role on the same resource twice stored two assignments, and listing the membership's role assignments returned both.

Fixes #208

Behavior

Checked against a WorkOS staging environment:

Call WorkOS Emulator before
assign a role on a resource 201 201
assign the same role on the same resource again 201, the same assignment (same id) 201, a new assignment
list role assignments one assignment two

The emulator now matches every row.

What changed

  • Before inserting, the route looks for an assignment of the same role on the same resource (or the organization, when no resource is given) held by the membership, and answers it with 201 if one exists.
  • docs/behavior.md: the Native group authorization paragraph notes the repeated direct assignment, next to the 409 for a duplicate group assignment.

No other endpoint changes behavior.

Tests

  • New case in authorization-checks.spec.ts: the repeat returns the first assignment's id with 201, the same role on the organization stays a separate assignment, and the list holds two. It fails on main.
  • bun test (2091 pass), bun run typecheck, bun run lint, bun run fmt:check, bun run build, node scripts/check-package.mjs, node scripts/smoke-node.mjs, and the codegen drift check all pass.

@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; no actionable issues were found.

Summary

Repeated direct role assignments now return the existing assignment with 201 instead of creating a duplicate.

  • Repeated role requests return the membership’s existing assignment.

No actionable issues found.

Reviews (1) · Last reviewed commit: "fix(authorization): answer a repeated ro..." · Reviewed by Greptile

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.

Assigning the same role twice on a resource stores two role assignments

1 participant