Skip to content

fix(organisations): don't fetch an organisation with a non-numeric id - #8222

Open
talissoncosta wants to merge 2 commits into
mainfrom
fix/organisation-store-guard-invalid-id
Open

fix(organisations): don't fetch an organisation with a non-numeric id#8222
talissoncosta wants to merge 2 commits into
mainfrom
fix/organisation-store-guard-invalid-id

Conversation

@talissoncosta

@talissoncosta talissoncosta commented Aug 5, 2026

Copy link
Copy Markdown
Contributor
  • I have read the Contributing Guide.
  • I have added information to docs/ if required so people know about the feature.
  • I have filled in the "Changes" section below.
  • I have filled in the "How did you test this code" section below.

Reviewing this: one guard, at organisation-store.js:120, refusing an id the API cannot accept. The judgement call is what is not here: onboarding's refresh, which triggered this, is left alone because nothing reads it. Safe to skim the tests and three lint-driven reformats in the same file (a dead import, a filter reflow, the unnested ternary).

Changes

/getting-started sent organisation=account, giving a 400 on projects/ and a 500 on organisations/{id}/users/, plus a red [object Response] overlay locally.

We send that id ourselves. None of the code below changes in this PR, it is just where the id comes from:

bootstrapOnboarding.ts    AppActions.refreshOrganisation()      // no id
app-actions.js            dispatches GET_ORGANISATION, id absent
organisation-store.js     getOrganisation(action.id || store.id)
organisation-store.js     id: 'account'                          // seed value

getOrganisation now returns early on a non-numeric id, via a new isNumericId. Number() on its own is not enough, since it also accepts [], ['5'] and true, so the input is narrowed to a string or a number first and has to be a positive integer.

Onboarding is left alone, because that refresh has never worked and nothing reads it. The project switcher is RTK (BreadcrumbSeparator.tsx:198) and createProject already invalidates the Project tag. The one Flux consumer of the organisation's project list is the organisation projects page, which fetches on mount (ProjectManageWidget.tsx:63).

The nested ternary in the same file is unnested because the commit hook lints whole staged files. It keeps the original comparison rather than localeCompare, which orders accents differently.

Production hits the same two failures and just renders an empty organisation view.

Screenshots

Before, the local dev overlay:

image

How did you test this code?

  • isNumericId unit tests (21)
  • test:unit (422) clean, and no new typecheck errors in the touched files
  • /getting-started: no red overlay, and no organisation=account request in the network tab
  • Project switcher: the project onboarding creates shows up without a reload
  • Organisation projects page: still lists projects, each with its environments

@vercel

vercel Bot commented Aug 5, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
flagsmith-frontend-preview Ready Ready Preview Aug 6, 2026 6:46pm
flagsmith-frontend-staging Ready Ready Preview Aug 6, 2026 6:46pm
1 Skipped Deployment
Project Deployment Actions Updated (UTC)
docs Ignored Ignored Preview Aug 6, 2026 6:46pm

Request Review

@coderabbitai

coderabbitai Bot commented Aug 5, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: 507ff75c-ac3e-429e-80fa-f0cb39507aae

📥 Commits

Reviewing files that changed from the base of the PR and between bc3c15c and 2e13a42.

📒 Files selected for processing (1)
  • frontend/common/utils/__tests__/isNumericId.test.ts

📝 Walkthrough

Walkthrough

The change adds the exported isNumericId predicate and parameterised tests for valid and invalid IDs. getOrganisation now returns early for non-numeric IDs. Project removal filtering is simplified. The project-name comparator now uses explicit conditional returns with ordering comments.

Estimated code review effort: 2 (Simple) | ~10 minutes


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai 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.

Actionable comments posted: 2


ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: 436d5fec-84ae-43c3-9994-bf9d58c18395

📥 Commits

Reviewing files that changed from the base of the PR and between 3f8978c and 80a5153.

📒 Files selected for processing (3)
  • frontend/common/stores/organisation-store.js
  • frontend/common/utils/__tests__/isNumericId.test.ts
  • frontend/common/utils/isNumericId.ts

Comment thread frontend/common/stores/organisation-store.js Outdated
Comment thread frontend/common/utils/isNumericId.ts Outdated
organisation-store seeds its id to the string 'account', and the
dispatcher falls back to it, so any refresh before an organisation had
loaded sent 'account' as the id. That fanned out into a 400 on projects/
and a 500 on organisations/{id}/users/, which surfaced locally as an
unhandled rejection because _data rejects with the raw Response.

getOrganisation now returns early on a non-numeric id. isNumericId
narrows before converting, since Number() also accepts [], ['5'] and
true, and requires a positive integer because these are serial keys.

Onboarding, where this showed up, is left alone. Its refresh has never
worked: the project switcher reads RTK, and createProject already
invalidates the Project tag, so nothing depended on the failing call.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
@coderabbitai

coderabbitai Bot commented Aug 6, 2026

Copy link
Copy Markdown

Note

GitHub couldn't provide a complete incremental comparison for this pull request, so CodeRabbit is performing a full review instead. This review may take a little longer.

@coderabbitai coderabbitai 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.

Actionable comments posted: 1


ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: f789da4c-a1e3-49d2-b6ec-8ee89a67eeea

📥 Commits

Reviewing files that changed from the base of the PR and between 47e9edf and bc3c15c.

📒 Files selected for processing (3)
  • frontend/common/stores/organisation-store.js
  • frontend/common/utils/__tests__/isNumericId.test.ts
  • frontend/common/utils/isNumericId.ts

Comment thread frontend/common/utils/__tests__/isNumericId.test.ts Outdated
@talissoncosta
talissoncosta marked this pull request as ready for review August 6, 2026 18:42
@talissoncosta
talissoncosta requested a review from a team as a code owner August 6, 2026 18:42
@talissoncosta
talissoncosta requested review from kyle-ssg and removed request for a team August 6, 2026 18:42
'007' is accepted on purpose, since DRF coerces it to the key 7, but
nothing held that in place. Raised by CodeRabbit on #8222.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

fix front-end Issue related to the React Front End Dashboard

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant