Skip to content

Commit ecf8d57

Browse files
imorjoshenlim
andauthored
fix: only enable install/uninstall button when user has permissions (supabase#43088)
Enable the install/uninstall integration button on the stripe sync engine only if the user has permissions to create/delete edge function secrets. This fixes a problem when non-admin/non-owner users try to install the integration but it fails due to lack of permissions. For a user without appropriate permissions a tool tip will be shown: <img width="1344" height="977" alt="image" src="https://github.com/user-attachments/assets/49c950cc-d76b-40b4-ab6e-cb8f193561cc" /> --------- Co-authored-by: Joshen Lim <joshenlimek@gmail.com>
1 parent 3f7d62e commit ecf8d57

1 file changed

Lines changed: 25 additions & 4 deletions

File tree

apps/studio/components/interfaces/Integrations/templates/StripeSyncEngine/InstallationOverview.tsx

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
import { zodResolver } from '@hookform/resolvers/zod'
2+
import { PermissionAction } from '@supabase/shared-types/out/constants'
23
import { ButtonTooltip } from 'components/ui/ButtonTooltip'
34
import { useStripeSyncInstallMutation } from 'data/database-integrations/stripe/stripe-sync-install-mutation'
45
import { useStripeSyncUninstallMutation } from 'data/database-integrations/stripe/stripe-sync-uninstall-mutation'
56
import { useSchemasQuery } from 'data/database/schemas-query'
67
import { formatRelative } from 'date-fns'
8+
import { useAsyncCheckPermissions } from 'hooks/misc/useCheckPermissions'
79
import { useSelectedProjectQuery } from 'hooks/misc/useSelectedProject'
810
import { useTrack } from 'lib/telemetry/track'
911
import { AlertCircle, BadgeCheck, Check, ExternalLink, RefreshCwIcon } from 'lucide-react'
@@ -73,6 +75,12 @@ export const StripeSyncInstallationPage = () => {
7375
connectionString: project?.connectionString,
7476
})
7577

78+
// Check permissions for managing function secrets
79+
const { can: canManageSecrets } = useAsyncCheckPermissions(
80+
PermissionAction.FUNCTIONS_SECRET_WRITE,
81+
'*'
82+
)
83+
7684
const isSyncing = isSyncRunning(syncState)
7785

7886
const installed = isInstalled(installationStatus)
@@ -328,12 +336,14 @@ export const StripeSyncInstallationPage = () => {
328336
<ButtonTooltip
329337
type="primary"
330338
onClick={() => setShouldShowInstallSheet(true)}
331-
disabled={!canInstall}
339+
disabled={!canInstall || !canManageSecrets}
332340
tooltip={{
333341
content: {
334342
text: !canInstall
335343
? 'Your database already uses a schema named "stripe"'
336-
: undefined,
344+
: !canManageSecrets
345+
? 'You need additional permissions to install the Stripe Sync Engine.'
346+
: undefined,
337347
},
338348
}}
339349
>
@@ -343,9 +353,20 @@ export const StripeSyncInstallationPage = () => {
343353
</>
344354
) : installed && !uninstalling ? (
345355
<div className="flex justify-end mt-4">
346-
<Button type="default" onClick={() => setShowUninstallModal(true)}>
356+
<ButtonTooltip
357+
type="default"
358+
onClick={() => setShowUninstallModal(true)}
359+
disabled={!canManageSecrets}
360+
tooltip={{
361+
content: {
362+
text: !canManageSecrets
363+
? 'You need additional permissions to uninstall the Stripe Sync Engine.'
364+
: undefined,
365+
},
366+
}}
367+
>
347368
Uninstall integration
348-
</Button>
369+
</ButtonTooltip>
349370
</div>
350371
) : null
351372
}

0 commit comments

Comments
 (0)