mirror of
https://github.com/supabase/supabase.git
synced 2026-12-06 08:29:01 +00:00
## Problem Gracefully handles 403s when getting org invitations as a project-scoped org member. The backend currently returns an empty list with a 200 status, but that will be changing soon - so this PR aims to fix the issue in advance. ## Solution Pretty self explanatory - but here is a before/after (with backend changes) ### Before <img width="2480" height="688" alt="CleanShot 2026-09-24 at 11 02 34 AM@2x" src="https://github.com/user-attachments/assets/13c6ed9e-7580-4962-9920-f49ede9c4592" /> ### After <img width="2466" height="820" alt="CleanShot 2026-09-24 at 11 07 13 AM@2x" src="https://github.com/user-attachments/assets/248f7bb5-1743-41c9-823f-f776a608dd17" /> <!-- ## Preview links If relevant, include links to changed pages for easy review access. Copy the preview base URL from the Vercel bot comment on this PR. Use the following table as an example template. | Site | Live | Preview | Search for | | -------------- | ------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------ | ----------------------------- | | WWW | [/blog/your-post](https://supabase.com/blog/your-post) | [/blog/your-post](https://zone-www-dot-com-git-branch-name-supabase.vercel.app/blog/your-post) | unique phrase from the change | | Docs | [/docs/guides/your-page](https://supabase.com/docs/guides/your-page) | [/docs/guides/your-page](https://docs-git-branch-name-supabase.vercel.app/docs/guides/your-page) | unique phrase from the change | | Studio | [/dashboard](https://supabase.com/dashboard) | [/dashboard](https://studio-git-branch-name-supabase.vercel.app/dashboard) | unique phrase from the change | | Design system | [/design-system](https://supabase.com/design-system) | [/design-system](https://design-system-git-branch-name-supabase.vercel.app/design-system) | unique phrase from the change | | UI library | [/library](https://supabase.com/library) | [/library](https://ui-library-git-branch-name-supabase.vercel.app/library) | unique phrase from the change | | Knowledge base | [/kb/guides/your-page](https://supabase.com/kb/guides/your-page) | [/kb/guides/your-page](https://kb-git-branch-name-supabase.vercel.app/kb/guides/your-page) | unique phrase from the change | --> <!-- ## Additional context Optionally add any other context or screenshots. --> ## Review instructions 1. Open the preview 2. Navigate to the `Team` tab in `Organization` 3. Invite a project-scoped member 4. Accept the project-scoped member invite in another browser 5. Navigate to the same `Team` tab as that project-scoped member. ## Checklist Check all before review: - [x] I have read [CONTRIBUTING.md](https://github.com/supabase/supabase/blob/master/CONTRIBUTING.md) - [x] If I wrote a new docs topic or edited an existing topic, I used the `/write-the-docs` or `/edit-the-docs` skill, which references [WORD_LIST](https://github.com/supabase/supabase/blob/master/apps/docs/WORD_LIST.md) and the docs [CONTRIBUTING](https://github.com/supabase/supabase/blob/master/apps/docs/CONTRIBUTING.md) guide <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **Bug Fixes** * Organization member lists now load even when invitation details aren’t accessible. * Missing invitation data no longer prevents member lists from loading. * Invitation errors other than access-denied errors, and errors loading members, continue to be reported. <!-- end of auto-generated comment: release notes by coderabbit.ai -->
111 lines
3.3 KiB
TypeScript
111 lines
3.3 KiB
TypeScript
import { HttpResponse } from 'msw'
|
|
import { describe, expect, it } from 'vitest'
|
|
|
|
import { getOrganizationMembers } from './organization-members-query'
|
|
import type { components } from '@/data/api'
|
|
import { addAPIMock, type APIErrorBody } from '@/tests/lib/msw'
|
|
|
|
type Member = components['schemas']['Member_Output']
|
|
type InvitationResponse = components['schemas']['InvitationResponse_Output']
|
|
|
|
const member: Member = {
|
|
avatar_url: null,
|
|
gotrue_id: 'gotrue-id',
|
|
is_sso_user: false,
|
|
metadata: {},
|
|
mfa_enabled: false,
|
|
primary_email: 'member@example.com',
|
|
role_ids: [1],
|
|
username: 'member',
|
|
}
|
|
|
|
describe('getOrganizationMembers', () => {
|
|
it('merges members with pending invitations', async () => {
|
|
addAPIMock({
|
|
method: 'get',
|
|
path: '/platform/organizations/:slug/members',
|
|
response: [member],
|
|
})
|
|
addAPIMock({
|
|
method: 'get',
|
|
path: '/platform/organizations/:slug/members/invitations',
|
|
response: {
|
|
invitations: [
|
|
{
|
|
id: 1,
|
|
invited_at: '2026-01-01T00:00:00Z',
|
|
invited_email: 'invitee@example.com',
|
|
role_id: 2,
|
|
},
|
|
],
|
|
} satisfies InvitationResponse,
|
|
})
|
|
|
|
const result = await getOrganizationMembers({ slug: 'org-slug' })
|
|
|
|
expect(result).toEqual([
|
|
member,
|
|
{
|
|
invited_at: '2026-01-01T00:00:00Z',
|
|
invited_id: 1,
|
|
mfa_enabled: false,
|
|
username: 'i',
|
|
primary_email: 'invitee@example.com',
|
|
role_ids: [2],
|
|
},
|
|
])
|
|
})
|
|
|
|
it('treats a 403 on invitations as no visible invitations, instead of failing the members list', async () => {
|
|
// Project-scoped members are not permitted to read org invitations
|
|
// The members list itself must still load.
|
|
addAPIMock({
|
|
method: 'get',
|
|
path: '/platform/organizations/:slug/members',
|
|
response: [member],
|
|
})
|
|
addAPIMock({
|
|
method: 'get',
|
|
path: '/platform/organizations/:slug/members/invitations',
|
|
response: () => HttpResponse.json<APIErrorBody>({ message: 'Forbidden' }, { status: 403 }),
|
|
})
|
|
|
|
const result = await getOrganizationMembers({ slug: 'org-slug' })
|
|
|
|
expect(result).toEqual([member])
|
|
})
|
|
|
|
it('rethrows a non-403 error on the invitations call', async () => {
|
|
addAPIMock({
|
|
method: 'get',
|
|
path: '/platform/organizations/:slug/members',
|
|
response: [member],
|
|
})
|
|
addAPIMock({
|
|
method: 'get',
|
|
path: '/platform/organizations/:slug/members/invitations',
|
|
response: () =>
|
|
HttpResponse.json<APIErrorBody>({ message: 'Internal Server Error' }, { status: 500 }),
|
|
})
|
|
|
|
await expect(getOrganizationMembers({ slug: 'org-slug' })).rejects.toThrowError(
|
|
'Internal Server Error'
|
|
)
|
|
})
|
|
|
|
it('rethrows an error on the members call even if invitations succeed', async () => {
|
|
addAPIMock({
|
|
method: 'get',
|
|
path: '/platform/organizations/:slug/members',
|
|
response: () => HttpResponse.json<APIErrorBody>({ message: 'Forbidden' }, { status: 403 }),
|
|
})
|
|
addAPIMock({
|
|
method: 'get',
|
|
path: '/platform/organizations/:slug/members/invitations',
|
|
response: { invitations: [] } satisfies InvitationResponse,
|
|
})
|
|
|
|
await expect(getOrganizationMembers({ slug: 'org-slug' })).rejects.toThrowError('Forbidden')
|
|
})
|
|
})
|