Files
supabase/apps/studio/components/interfaces/Settings/Database/SSLEnforcementConfirmDialog.tsx
Alaister Young 3811e75140 [MUL-1417] feat(studio): show SSL enforcement as always on for HA projects (#49524)
High Availability (Multigres) projects always enforce SSL, and the
management API now rejects any attempt to read or change the setting
(supabase/platform#37484). This makes the Database Settings toggle
reflect that instead of surfacing an error.

**Changed:**
- `SSLConfiguration`: skip the `ssl-enforcement` query for HA projects
(via `useHighAvailability`) and render the "Enforce SSL on incoming
connections" switch checked + disabled with the tooltip "SSL is always
enforced on High Availability projects". Non-HA projects are unchanged.
- `SSLEnforcementConfirmDialog`: add a controlled `open`/`onOpenChange`
mode. The switch now opens the dialog from its own `onCheckedChange`
rather than a wrapping `AlertDialogTrigger`, so a disabled switch can no
longer open the dialog by clicking the row wrapper beside it (this was
reachable for every disabled state, and for HA would have PUT into the
new 400 guardrail). The JIT section's existing trigger-with-children
usage is untouched.

**Added:**
- `SSLConfiguration.test.tsx` (MSW): HA → checked/disabled, tooltip, no
`ssl-enforcement` request, no dialog from switch/wrapper clicks; non-HA
→ reflects fetched config, switch opens the dialog and Cancel leaves it
unchanged.

## To test

On an HA project → Project Settings → Database → SSL configuration:
- Switch is on and disabled, hovering shows "SSL is always enforced on
High Availability projects"
- No request to `/v1/projects/{ref}/ssl-enforcement` fires, no spinner
sticks, no error toast
- Clicking the disabled switch or the empty area beside it does **not**
open the "brief downtime" dialog

On a non-HA project:
- Switch reflects the current config and the GET fires once
- Clicking the switch opens the confirm dialog with Enable/Disable SSL;
Cancel and Escape close it without changing the switch or sending a PUT
- Clicking beside the switch (not on it) does not open the dialog

Linear:
https://linear.app/supabase/issue/MUL-1417/database-settings-disable-ssl-enforcement-toggle

<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->
## Summary by CodeRabbit

- **New Features**
- High Availability projects now show SSL as always enabled, with an
explanatory tooltip.
- SSL settings are protected from changes on High Availability projects.
- SSL confirmation dialogs now open and close reliably when changing
settings.
- Added accessible announcements for SSL configuration loading and
updates.

- **Bug Fixes**
- Improved SSL state handling for standard and High Availability
projects.
- Prevented unnecessary SSL enforcement checks for High Availability
projects.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->

---------

Co-authored-by: Alaister Young <10985857+alaister@users.noreply.github.com>
2026-08-25 08:34:24 +00:00

56 lines
1.8 KiB
TypeScript

import { type PropsWithChildren } from 'react'
import {
AlertDialog,
AlertDialogAction,
AlertDialogCancel,
AlertDialogContent,
AlertDialogDescription,
AlertDialogFooter,
AlertDialogHeader,
AlertDialogTitle,
AlertDialogTrigger,
} from 'ui'
interface SSLEnforcementConfirmDialogProps {
isTargetEnforced: boolean
isSubmitting: boolean
onConfirm: () => Promise<void>
/**
* Controlled mode for callers whose control can't act as the dialog trigger
* (e.g. a switch, where a disabled control must never open the dialog).
* Omit both, and pass `children`, to render the children as the trigger.
*/
open?: boolean
onOpenChange?: (open: boolean) => void
}
export const SSLEnforcementConfirmDialog = ({
isTargetEnforced,
isSubmitting,
onConfirm,
open,
onOpenChange,
children,
}: PropsWithChildren<SSLEnforcementConfirmDialogProps>) => {
return (
<AlertDialog open={open} onOpenChange={onOpenChange}>
{children !== undefined && <AlertDialogTrigger asChild>{children}</AlertDialogTrigger>}
<AlertDialogContent size="medium">
<AlertDialogHeader>
<AlertDialogTitle>Updating SSL enforcement involves a brief downtime</AlertDialogTitle>
<AlertDialogDescription>
A database restart is required for SSL enforcement changes to take place, and this
involves a few minutes of downtime. Confirm to proceed now?
</AlertDialogDescription>
</AlertDialogHeader>
<AlertDialogFooter>
<AlertDialogCancel disabled={isSubmitting}>Cancel</AlertDialogCancel>
<AlertDialogAction variant="warning" disabled={isSubmitting} onClick={onConfirm}>
{isTargetEnforced ? 'Enable SSL' : 'Disable SSL'}
</AlertDialogAction>
</AlertDialogFooter>
</AlertDialogContent>
</AlertDialog>
)
}