mirror of
https://github.com/supabase/supabase.git
synced 2026-12-04 15:39:13 +00:00
Resolves FE-4744. Part of the grants rollout; builds on the read/write SQL variants from #53185. ## What - **Data layer:** the database functions, triggers, database webhooks, and event triggers queries now take a `read` grant (exposed as `queryOptions` factories). All 8 create/update/delete mutations take a `write` grant and mark their SQL with `asWriteSql`. - **Guards:** the hand-written FGA checks in the functions, triggers, event triggers, and database webhooks lists, the functions page, the triggers layout/route, and the webhooks integration tab now derive from grants, with denied and error states. - **Other consumers** updated to pass grants: `CreateFunction`, `TriggerSheet`, `EditHookPanel`, `DeleteHookModal`, `ChooseFunctionForm`, `FunctionSelector`, `AutoEnableRLSNotice`, and SQL editor definition/autocomplete hooks. ## Behavior changes - **Webhooks integration tab:** was gated on `database_webhooks_config_read`; now gated on `database_read`, which is what the backend checks for the pg-meta query it uses. Both permissions are granted to the same built-in roles, so there is no change for built-in roles. A permissions-load failure now shows an error alert instead of the content. - **`AutoEnableRLSNotice`:** hidden unless the user has read access, since it can't tell whether the trigger already exists without it. ## Out of scope - User-authored SQL execution in `QueryEditor` / `useSqlEditorExecution` stays `unguarded.migrating` (FE-4750). ## Testing - New tests: query factories and write mutations (`data/database-sql-grants.test.ts`), webhooks tab granted/denied/error, functions list read/write granted/denied/error. - Typecheck, Prettier, lint ratchet, and Studio vitest suites for affected areas pass.
63 lines
1.9 KiB
TypeScript
63 lines
1.9 KiB
TypeScript
import { Maximize2Icon, Minimize2Icon } from 'lucide-react'
|
|
import { Button, cn, FormControl, Tooltip, TooltipContent, TooltipTrigger } from 'ui'
|
|
|
|
import { CodeEditor } from '@/components/ui/CodeEditor/CodeEditor'
|
|
|
|
export const FunctionEditor = ({
|
|
field,
|
|
language,
|
|
focused,
|
|
setFocused,
|
|
isReadOnly = false,
|
|
}: {
|
|
field: any
|
|
language: string
|
|
focused: boolean
|
|
setFocused: (b: boolean) => void
|
|
isReadOnly?: boolean
|
|
}) => {
|
|
return (
|
|
<div className={cn('rounded-md relative group grow')}>
|
|
<FormControl>
|
|
{language !== undefined && (
|
|
<CodeEditor
|
|
id="database-functions-editor"
|
|
language="pgsql"
|
|
placeholder={language === 'plpgsql' ? `BEGIN\n\nEND;` : undefined}
|
|
value={field.value}
|
|
onInputChange={field.onChange}
|
|
isReadOnly={isReadOnly}
|
|
/>
|
|
)}
|
|
</FormControl>
|
|
<div
|
|
className={cn(
|
|
'absolute top-0 right-2 bg-surface-300 border border-strong rounded-sm h-[28px]',
|
|
'opacity-0 group-hover:opacity-100 group-hover:top-2 transition-all'
|
|
)}
|
|
>
|
|
<Tooltip>
|
|
<TooltipTrigger asChild>
|
|
<Button
|
|
variant="text"
|
|
size="tiny"
|
|
className={cn(
|
|
'px-1.5 text-foreground-lighter hover:text-foreground',
|
|
'transition z-50'
|
|
)}
|
|
onClick={() => setFocused(!focused)}
|
|
icon={focused ? <Minimize2Icon /> : <Maximize2Icon />}
|
|
aria-label={focused ? 'Minimize editor' : 'Maximize editor'}
|
|
// Tooltip repeats the label; screen readers would read it twice
|
|
aria-describedby={undefined}
|
|
/>
|
|
</TooltipTrigger>
|
|
<TooltipContent side="bottom">
|
|
{focused ? 'Minimize editor' : 'Maximize editor'}
|
|
</TooltipContent>
|
|
</Tooltip>
|
|
</div>
|
|
</div>
|
|
)
|
|
}
|