Skip to content

fix(authorization): create implicit organization roots - #106

Merged
gjtorikian merged 6 commits into
workos:mainfrom
henningpokriefke:codex/fix-implicit-organization-root
Sep 9, 2026
Merged

fix(authorization): create implicit organization roots#106
gjtorikian merged 6 commits into
workos:mainfrom
henningpokriefke:codex/fix-implicit-organization-root

Conversation

@henningpokriefke

@henningpokriefke henningpokriefke commented Sep 9, 2026

Copy link
Copy Markdown
Contributor

Fixes #105.

Creating an organization now creates its implicit FGA root, using the configured external ID or falling back to the organization ID. Resources created without explicit parent fields attach to that root, so organization permission checks and discovery can resolve it without a fixture workaround that the hosted API rejects.

Review guide

  • organization-resource.ts contains the shared create/update logic used by organization routes and seed initialization. Updating an organization preserves the root's ID and existing child links.
  • Resource creation defaults to the organization root. Direct creation, modification, and deletion of an organization resource are rejected; deleting the owning organization removes its resources and their assignments.
  • Regression tests cover configured/fallback IDs, default parenting, organization updates, seed/reset, root protection, deletion isolation, and organization-root checks/discovery. Existing list/parent expectations account for the implicit root.

Validation

  • npm exec --offline --package=bun@1.3.14 -- bun test — 1,128 passed, 0 failed for the implementation commit.
  • Follow-up lifecycle tests: npm exec --offline --package=bun@1.3.14 -- bun test src/workos/routes/organization-resource.spec.ts — all 8 passed, including two complete runs with reused external IDs and removal of root/child grants without affecting another organization.
  • bun run typecheck, bun run build, bun run lint, bun run fmt:check, git diff --check — passed.
  • Additional Node SDK v10.8.0 checks against the built emulator confirmed organization-root permission checks and discovery with configured external IDs, matching the hosted-API behavior documented in FGA: implicit organization resource and default organization parenting are missing #105.

No resource-type registry or broader authorization refactor is introduced. The existing update-route HTTP verb behavior is unchanged.

@henningpokriefke henningpokriefke changed the title create implicit organization roots for authorization fix(authorization): create implicit organization roots Sep 9, 2026
@henningpokriefke
henningpokriefke marked this pull request as ready for review September 9, 2026 15:05
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Sep 9, 2026

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review Completed 2026-09-09T16:01:19.659590Z 2d5e01e New commits
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@greptile-apps

greptile-apps Bot commented Sep 9, 2026

Copy link
Copy Markdown

RetriggerView in GreptileConfidence Score: 5/5

The PR appears safe to merge; no actionable correctness, security, or repository-rule violations remain.

Summary

  • Creates roots during organization creation and seed initialization, with lazy creation for organizations inserted directly into the store.
  • Synchronizes root identity when an organization changes while preserving its resource ID and child links.
  • Deletes organization resources and membership-linked grants with their owning organization, membership, or user.
  • Adds regression coverage for permission inheritance, discovery, update behavior, lazy creation, reset behavior, and deletion isolation.

Diagram

%%{init: {'theme': 'neutral'}}%%
flowchart TD
  A[Create or seed organization] --> B[Find or create implicit organization root]
  C[Create resource without explicit parent] --> B
  B --> D[Organization root]
  D --> E[Default child resource]
  F[Update organization] --> G[Sync root name and external ID]
  G --> D
  H[Delete membership or user] --> I[Delete membership role assignments]
  J[Delete organization] --> K[Delete all memberships, grants, resources, and root]
Loading

Comment thread src/workos/routes/organizations.ts

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 9dec9ea313

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread src/workos/routes/authorization-resources.ts Outdated
Comment thread src/workos/organization-resource.ts Outdated

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 57d1320f74

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread src/workos/organization-resource.ts

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 051986e5a9

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread src/workos/routes/authorization-resources.ts Outdated
henningpokriefke and others added 2 commits September 9, 2026 17:56
Production resolves the implicit root with find-or-create wherever it
is needed, not only when the organization is created, so an
organization that reached the store without passing through the routes
still gets a root instead of parentless resources. The create route
also looked the root up by external_id while the sync helper looked it
up by type, so the two could disagree about which row is the root.

While aligning with the production service: its update path has no way
to detach a resource, so `parent_resource_id: null` now leaves the
parent alone (production's update DTO types the field as an optional
string and ignores a null, so this supersedes the clears-to-root
behavior from 2d5e01e); the update/delete guard messages use
production's wording; and role assignments are removed with their
membership on membership and user deletion, the same cascade
organization deletion already performs.
@gjtorikian
gjtorikian merged commit b16cd04 into workos:main Sep 9, 2026
9 checks passed
@gjtorikian

Copy link
Copy Markdown
Collaborator

thanks !

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.

FGA: implicit organization resource and default organization parenting are missing

2 participants