mirror of
https://github.com/supabase/supabase.git
synced 2026-12-04 15:39:13 +00:00
## Context Building on top of https://github.com/supabase/supabase/pull/54192, there was a missing piece to the JIT DB access UI which was showing the assigned access to the user if any (On staging it just shows an error, on the previous PR we show a "Contact your project admin" CTA). So this PR addresses that - there's a couple of cases to consider and I'd love for design to feedback / adjust as well as I'm not convinced this is the best way to do things. Am deliberately leaving out the "copyable connection strings" part for now as Danny's investigating into that one ### If you're a non-owner If not assigned a role: <img width="500" alt="image" src="https://github.com/user-attachments/assets/111d7c4f-0083-4bd5-88d5-ec45974ccf4d" /> If assigned a single role: <img width="500" alt="image" src="https://github.com/user-attachments/assets/1b4b1f3c-9a20-4010-bff8-7bf68a455e26" /> If assigned multiple roles: <img width="500" alt="image" src="https://github.com/user-attachments/assets/42cc66f6-4604-42eb-ab30-f58b1396ca6b" /> <img width="500" alt="image" src="https://github.com/user-attachments/assets/0914e1a3-9c7d-463e-851d-65f6b9793bb7" /> If (all) access expired: <img width="500" alt="image" src="https://github.com/user-attachments/assets/bda0fc65-e22a-49d9-b444-fc5d58a4745a" /> ### If you're an owner If not assigned a role: Status quo <img width="500" alt="image" src="https://github.com/user-attachments/assets/435abe70-ae88-49bb-86b9-7a03963b5b66" /> If yourself is assigned a role: <img width="500" alt="image" src="https://github.com/user-attachments/assets/9fafc74a-1a33-489e-a7da-70f57356a034" /> If yourself is assigned multiple roles: <img width="500" alt="image" src="https://github.com/user-attachments/assets/f4af901b-a24e-4272-b573-9ccb474bb7e2" /> If (all) access expired: Same as not assigned a role, just refer back to the table
243 lines
8.8 KiB
TypeScript
243 lines
8.8 KiB
TypeScript
import { useParams } from 'common'
|
|
import { EllipsisVerticalIcon, PencilIcon, PlusIcon, Trash2Icon } from 'lucide-react'
|
|
import {
|
|
Badge,
|
|
Button,
|
|
Card,
|
|
CardContent,
|
|
CardDescription,
|
|
CardFooter,
|
|
CardHeader,
|
|
CardTitle,
|
|
DropdownMenu,
|
|
DropdownMenuContent,
|
|
DropdownMenuItem,
|
|
DropdownMenuSeparator,
|
|
DropdownMenuTrigger,
|
|
Skeleton,
|
|
Table,
|
|
TableBody,
|
|
TableCell,
|
|
TableHead,
|
|
TableHeader,
|
|
TableRow,
|
|
} from 'ui'
|
|
|
|
import type { JitUserRule } from './JitDbAccess.types'
|
|
import { getJitStatusDisplay } from './JitDbAccess.utils'
|
|
import { JitDbAccessInfo } from './JitDbAccessInfo'
|
|
import { ButtonTooltip } from '@/components/ui/ButtonTooltip'
|
|
import { useJitDbAccessStatusQuery } from '@/data/jit-db-access/jit-db-access-status-query'
|
|
import { FGA_PERMISSIONS, useAsyncCheckPermissionsV2 } from '@/hooks/misc/useCheckPermissionsV2'
|
|
|
|
interface JitDbAccessRulesTableProps {
|
|
users: JitUserRule[]
|
|
isLoading?: boolean
|
|
canUpdate: boolean
|
|
disableActions?: boolean
|
|
allProjectMembersHaveRules?: boolean
|
|
onAddRule: () => void
|
|
onEditRule: (user: JitUserRule) => void
|
|
onDeleteRule: (user: JitUserRule) => void
|
|
}
|
|
|
|
export function JitDbAccessRulesTable({
|
|
users,
|
|
isLoading = false,
|
|
canUpdate,
|
|
disableActions = false,
|
|
allProjectMembersHaveRules = false,
|
|
onAddRule,
|
|
onEditRule,
|
|
onDeleteRule,
|
|
}: JitDbAccessRulesTableProps) {
|
|
const { ref: projectRef } = useParams()
|
|
|
|
const addDisabled = disableActions || !canUpdate || allProjectMembersHaveRules
|
|
const addRuleTooltip = !canUpdate
|
|
? 'Additional permissions required'
|
|
: allProjectMembersHaveRules
|
|
? 'All project members already have temporary access rules'
|
|
: undefined
|
|
|
|
const { can: canManageJitDbAccess } = useAsyncCheckPermissionsV2(
|
|
FGA_PERMISSIONS.PROJECT.DATABASE_JIT_WRITE
|
|
)
|
|
|
|
const { data: jitDbAccess, isPending: isLoadingUserJitDbAccess } = useJitDbAccessStatusQuery({
|
|
projectRef,
|
|
})
|
|
|
|
if (isLoading || isLoadingUserJitDbAccess) {
|
|
return (
|
|
<Card>
|
|
<CardContent className="space-y-4 p-4">
|
|
<div className="flex items-center justify-between">
|
|
<div className="space-y-2">
|
|
<Skeleton className="h-4 w-32" />
|
|
<Skeleton className="h-4 w-64" />
|
|
</div>
|
|
<Skeleton className="h-9 w-24" />
|
|
</div>
|
|
<Skeleton className="h-32 w-full" />
|
|
</CardContent>
|
|
</Card>
|
|
)
|
|
}
|
|
|
|
return (
|
|
<Card>
|
|
<CardContent className="p-0">
|
|
<CardHeader className="flex flex-row items-center justify-between">
|
|
<div className="flex flex-col gap-y-0.5 mb-0">
|
|
<CardTitle>Temporary access rules</CardTitle>
|
|
<CardDescription>
|
|
Manage member access, allowed roles, and expiry settings.
|
|
</CardDescription>
|
|
</div>
|
|
{canManageJitDbAccess && (
|
|
<ButtonTooltip
|
|
icon={<PlusIcon />}
|
|
onClick={onAddRule}
|
|
disabled={addDisabled}
|
|
tooltip={{ content: { side: 'bottom', text: addRuleTooltip } }}
|
|
>
|
|
Add rule
|
|
</ButtonTooltip>
|
|
)}
|
|
</CardHeader>
|
|
|
|
<JitDbAccessInfo />
|
|
|
|
{canManageJitDbAccess && (
|
|
<Table>
|
|
<TableHeader>
|
|
<TableRow>
|
|
<TableHead>Member</TableHead>
|
|
<TableHead>Roles</TableHead>
|
|
<TableHead>Status</TableHead>
|
|
<TableHead className="w-1">
|
|
<span className="sr-only">Actions</span>
|
|
</TableHead>
|
|
</TableRow>
|
|
</TableHeader>
|
|
<TableBody>
|
|
{users.length === 0 ? (
|
|
<TableRow className="[&>td]:hover:bg-inherit">
|
|
<TableCell colSpan={4}>
|
|
<p className="text-sm text-foreground">No rules yet</p>
|
|
<p className="text-sm text-foreground-lighter">
|
|
Add your first temporary access rule above
|
|
</p>
|
|
</TableCell>
|
|
</TableRow>
|
|
) : (
|
|
users.map((user) => {
|
|
const statusDisplay = getJitStatusDisplay(user.status)
|
|
const enabledGrants = user.grants.filter((grant) => grant.enabled)
|
|
const rowIsInteractive = canUpdate && !disableActions
|
|
|
|
return (
|
|
<TableRow
|
|
key={user.id}
|
|
className={
|
|
rowIsInteractive ? 'relative focus-inset cursor-pointer' : undefined
|
|
}
|
|
onClick={
|
|
rowIsInteractive
|
|
? (event) => {
|
|
if ((event.target as HTMLElement).closest('button')) return
|
|
onEditRule(user)
|
|
}
|
|
: undefined
|
|
}
|
|
onKeyDown={
|
|
rowIsInteractive
|
|
? (event) => {
|
|
if ((event.target as HTMLElement).closest('button')) return
|
|
if (event.key === 'Enter' || event.key === ' ') {
|
|
event.preventDefault()
|
|
onEditRule(user)
|
|
}
|
|
}
|
|
: undefined
|
|
}
|
|
tabIndex={rowIsInteractive ? 0 : undefined}
|
|
>
|
|
<TableCell className="text-sm">
|
|
{user.name && <p>{user.name}</p>}
|
|
<p className="text-foreground-lighter">{user.email}</p>
|
|
</TableCell>
|
|
<TableCell className="text-sm text-foreground-light">
|
|
{enabledGrants.length} role
|
|
{enabledGrants.length === 1 ? '' : <span>s</span>}
|
|
</TableCell>
|
|
<TableCell className="text-sm text-foreground-light">
|
|
{statusDisplay.badges.length > 0 ? (
|
|
<span className="flex flex-wrap gap-1.5">
|
|
{statusDisplay.badges.map((badge) => (
|
|
<Badge key={badge.label} variant={badge.variant}>
|
|
{badge.label}
|
|
</Badge>
|
|
))}
|
|
</span>
|
|
) : null}
|
|
</TableCell>
|
|
<TableCell className="text-right">
|
|
<DropdownMenu>
|
|
<DropdownMenuTrigger asChild>
|
|
<Button
|
|
icon={<EllipsisVerticalIcon />}
|
|
aria-label="More actions"
|
|
size="tiny"
|
|
className="w-7 hit-area-2"
|
|
disabled={!canUpdate || disableActions}
|
|
/>
|
|
</DropdownMenuTrigger>
|
|
<DropdownMenuContent align="end" side="bottom" className="w-40">
|
|
<DropdownMenuItem
|
|
className="gap-x-2"
|
|
onClick={(event) => {
|
|
event.stopPropagation()
|
|
onEditRule(user)
|
|
}}
|
|
disabled={!canUpdate || disableActions}
|
|
>
|
|
<PencilIcon size={14} className="text-foreground-lighter" />
|
|
Edit
|
|
</DropdownMenuItem>
|
|
<DropdownMenuSeparator />
|
|
<DropdownMenuItem
|
|
className="gap-x-2"
|
|
onClick={(event) => {
|
|
event.stopPropagation()
|
|
onDeleteRule(user)
|
|
}}
|
|
disabled={!canUpdate || disableActions}
|
|
>
|
|
<Trash2Icon size={14} className="text-foreground-lighter" />
|
|
Delete
|
|
</DropdownMenuItem>
|
|
</DropdownMenuContent>
|
|
</DropdownMenu>
|
|
</TableCell>
|
|
</TableRow>
|
|
)
|
|
})
|
|
)}
|
|
</TableBody>
|
|
</Table>
|
|
)}
|
|
</CardContent>
|
|
|
|
{!canManageJitDbAccess && jitDbAccess?.user_id !== undefined && (
|
|
<CardFooter>
|
|
<p className="text-foreground-lighter text-sm">
|
|
You need additional permissions to manage temporary database access
|
|
</p>
|
|
</CardFooter>
|
|
)}
|
|
</Card>
|
|
)
|
|
}
|