The Postgres development platform. Supabase gives you a dedicated Postgres database to build your web, mobile, and AI applications.
TypeScript aialternativeauthdatabasedenoembeddingsexamplefirebasenextjsoauth2pgvectorpostgispostgrespostgresqlpostgrestrealtimesupabasevectorswebsockets
Add no perms state for if role has no read access to an org's projects
Joshen Lim62b0a2e741a1
diff --git a/studio/components/interfaces/Home/ProjectList/ProjectList.tsx b/studio/components/interfaces/Home/ProjectList/ProjectList.tsxindex 3664536aee5..26e683843c1 100644--- a/studio/components/interfaces/Home/ProjectList/ProjectList.tsx+++ b/studio/components/interfaces/Home/ProjectList/ProjectList.tsx@@ -3,11 +3,12 @@ import { Button, IconPlus } from '@supabase/ui'import { useRouter } from 'next/router'import { observer } from 'mobx-react-lite'-import { useStore } from 'hooks'+import { checkPermissions, useStore } from 'hooks'import { Organization, Project } from 'types'import { makeRandomString } from 'lib/helpers'import ProjectCard from './ProjectCard'import ShimmeringCard from './ShimmeringCard'+import { PermissionAction } from '@supabase/shared-types/out/constants'interface Props {rewriteHref?: (projectRef: string) => string@@ -27,6 +28,9 @@ const ProjectList: FC<Props> = ({ rewriteHref }) => {({ organization_id }: Project) => organization_id == id)const isEmpty = sortedProjects?.length == 0+ const canReadProjects = checkPermissions(PermissionAction.READ, 'projects', undefined, id)+ console.log('canReadProjects', name, canReadProjects)+return (<div className="space-y-3" key={makeRandomString(5)}><h4 className="text-lg">{name}</h4>@@ -37,7 +41,16 @@ const ProjectList: FC<Props> = ({ rewriteHref }) => {</ul>) : (<ul className="mx-auto grid grid-cols-1 gap-4 sm:grid-cols-1 md:grid-cols-1 lg:grid-cols-2 xl:grid-cols-3 2xl:grid-cols-4 ">- {!isLoadingProjects && isEmpty && (+ {!canReadProjects ? (+ <div className="col-span-4 max-w-4xl space-y-4 rounded-lg border-2 border-dashed border-gray-300 p-6 text-center">+ <div className="space-y-1">+ <p>You need additional permissions to view projects from this organization</p>+ <p className="text-scale-1100 text-sm">+ Contact your organization owner or adminstrator for assistance.+ </p>+ </div>+ </div>+ ) : isEmpty ? (<div className="col-span-4 max-w-4xl space-y-4 rounded-lg border-2 border-dashed border-gray-300 p-6 text-center"><div className="space-y-1"><p>No projects</p>@@ -51,14 +64,15 @@ const ProjectList: FC<Props> = ({ rewriteHref }) => {</Button></div></div>+ ) : (+ sortedProjects?.map((project: Project) => (+ <ProjectCard+ key={makeRandomString(5)}+ project={project}+ rewriteHref={rewriteHref ? rewriteHref(project.ref) : undefined}+ />+ )))}- {sortedProjects?.map((project: Project) => (- <ProjectCard- key={makeRandomString(5)}- project={project}- rewriteHref={rewriteHref ? rewriteHref(project.ref) : undefined}- />- ))}</ul>)}</div>diff --git a/studio/hooks/queries/usePermissions.ts b/studio/hooks/queries/usePermissions.tsindex 7d4307a10e5..b9d1bab6c00 100644--- a/studio/hooks/queries/usePermissions.ts+++ b/studio/hooks/queries/usePermissions.ts@@ -23,13 +23,19 @@ export function usePermissions(returning?: 'minimal') {}}-export function checkPermissions(action: string, resource: string, data?: object) {+export function checkPermissions(+ action: string,+ resource: string,+ data?: object,+ organizationId?: number+) {if (!IS_PLATFORM) return trueconst enablePermissions = useFlag('enablePermissions')if (!enablePermissions) return trueconst { ui } = useStore()+ const orgid = organizationId ?? ui?.selectedOrganization?.idreturn (ui?.permissions ?? []).filter(@@ -45,7 +51,7 @@ export function checkPermissions(action: string, resource: string, data?: objectpermission.resources.some((res) =>resource.match(res.replace('.', '.').replace('%', '.*'))) &&- permission.organization_id === ui?.selectedOrganization?.id+ permission.organization_id === orgid).some(({ condition }: { condition: jsonLogic.RulesLogic }) =>