The Postgres development platform. Supabase gives you a dedicated Postgres database to build your web, mobile, and AI applications.
TypeScript aialternativeauthdatabasedenoembeddingsexamplefirebasenextjsoauth2pgvectorpostgispostgrespostgresqlpostgrestrealtimesupabasevectorswebsockets
Implement ABAC to restrict users from updating authentication SMTP settings
Joshen Limcfc9866f132b
diff --git a/studio/components/interfaces/Auth/EmailTemplates/TemplateEditor.tsx b/studio/components/interfaces/Auth/EmailTemplates/TemplateEditor.tsxindex b47625733ea..90931aee2cc 100644--- a/studio/components/interfaces/Auth/EmailTemplates/TemplateEditor.tsx+++ b/studio/components/interfaces/Auth/EmailTemplates/TemplateEditor.tsx@@ -2,8 +2,9 @@ import ReactMarkdown from 'react-markdown'import { FC, useState, useEffect } from 'react'import { observer } from 'mobx-react-lite'import { Input, Form } from '@supabase/ui'+import { PermissionAction } from '@supabase/shared-types/out/constants'-import { useStore } from 'hooks'+import { useStore, checkPermissions } from 'hooks'import { FormSchema } from 'types'import { FormActions, FormSection, FormSectionContent, FormSectionLabel } from 'components/ui/Forms'import CodeEditor from 'components/ui/CodeEditor'@@ -22,6 +23,7 @@ const TemplateEditor: FC<Props> = ({ template }) => {const formId = `auth-config-email-templates-${id}`const INITIAL_VALUES: { [x: string]: string } = {}+ const canUpdateConfig = checkPermissions(PermissionAction.UPDATE, 'custom_config_gotrue')useEffect(() => {if (isLoaded) {@@ -107,6 +109,7 @@ const TemplateEditor: FC<Props> = ({ template }) => {</ReactMarkdown>) : null}+ disabled={!canUpdateConfig}/></div>)@@ -138,6 +141,7 @@ const TemplateEditor: FC<Props> = ({ template }) => {id="code-id"loading={!isLoaded}language="html"+ isReadOnly={!canUpdateConfig}className="!mb-0 h-96 overflow-hidden rounded border"onInputChange={(e: string | undefined) => setBodyValue(e ?? '')}options={{ wordWrap: 'off', contextmenu: false }}@@ -158,6 +162,12 @@ const TemplateEditor: FC<Props> = ({ template }) => {form={formId}isSubmitting={isSubmitting}hasChanges={hasChanges}+ disabled={!canUpdateConfig}+ helper={+ !canUpdateConfig+ ? 'You need additional permissions to update authentication settings'+ : undefined+ }/></div></FormSectionContent>diff --git a/studio/components/interfaces/Auth/SmtpForm/SmtpForm.tsx b/studio/components/interfaces/Auth/SmtpForm/SmtpForm.tsxindex 0bfda3a58e8..e77eea41c47 100644--- a/studio/components/interfaces/Auth/SmtpForm/SmtpForm.tsx+++ b/studio/components/interfaces/Auth/SmtpForm/SmtpForm.tsx@@ -1,6 +1,7 @@import { observer } from 'mobx-react-lite'import { useEffect, useState } from 'react'import { number, object, string } from 'yup'+import { PermissionAction } from '@supabase/shared-types/out/constants'import { Alert, Button, Form, Input, InputNumber, Toggle, IconEye, IconEyeOff } from '@supabase/ui'import {@@ -11,7 +12,7 @@ import {FormSectionContent,FormSectionLabel,} from 'components/ui/Forms'-import { useStore } from 'hooks'+import { useStore, checkPermissions } from 'hooks'import { domainRegex } from './../Auth.constants'import { defaultDisabledSmtpFormValues } from './SmtpForm.constants'import { generateFormValues, isSmtpEnabled } from './SmtpForm.utils'@@ -25,6 +26,7 @@ const SmtpForm = () => {const formId = 'auth-config-smtp-form'const initialValues = generateFormValues(authConfig.config)+ const canUpdateConfig = checkPermissions(PermissionAction.UPDATE, 'custom_config_gotrue')useEffect(() => {if (isLoaded && isSmtpEnabled(config)) {@@ -149,6 +151,12 @@ const SmtpForm = () => {isSubmitting={isSubmitting}hasChanges={hasChanges}handleReset={onResetForm}+ disabled={!canUpdateConfig}+ helper={+ !canUpdateConfig+ ? 'You need additional permissions to update authentication settings'+ : undefined+ }/></div>}@@ -161,6 +169,7 @@ const SmtpForm = () => {label="Enable Custom SMTP"layout="flex"checked={enableSmtp}+ disabled={!canUpdateConfig}// @ts-ignoreonChange={(value: boolean) => setEnableSmtp(value)}descriptionText="Emails will be sent using your custom SMTP provider"@@ -188,6 +197,7 @@ const SmtpForm = () => {label="Sender email"descriptionText="This is the email address the emails are sent from"placeholder="[email protected]"+ disabled={!canUpdateConfig}/><Inputname="SMTP_SENDER_NAME"@@ -195,6 +205,7 @@ const SmtpForm = () => {label="Sender name"descriptionText="Name displayed in the recipient's inbox"placeholder="The name shown on the email"+ disabled={!canUpdateConfig}/></FormSectionContent></FormSection>@@ -218,6 +229,7 @@ const SmtpForm = () => {id="SMTP_HOST"label="Host"descriptionText="Hostname or IP address of your SMTP server."+ disabled={!canUpdateConfig}/><InputNumbername="SMTP_PORT"@@ -236,6 +248,7 @@ const SmtpForm = () => {</span></>}+ disabled={!canUpdateConfig}/><InputNumberid="SMTP_MAX_FREQUENCY"@@ -243,6 +256,7 @@ const SmtpForm = () => {label="Minimum interval between emails being sent"descriptionText="How long between each email can a new email be sent via your SMTP server."actions={<span className="text-scale-900 mr-3">seconds</span>}+ disabled={!canUpdateConfig}/><InputNumbername="RATE_LIMIT_EMAIL_SENT"@@ -251,12 +265,14 @@ const SmtpForm = () => {label="Rate limit for sending emails"descriptionText="How many emails can be sent per hour."actions={<span className="text-scale-900 mr-3">emails per hour</span>}+ disabled={!canUpdateConfig}/><Inputname="SMTP_USER"id="SMTP_USER"label="Username"placeholder="SMTP Username"+ disabled={!canUpdateConfig}/><Inputname="SMTP_PASS"@@ -271,6 +287,7 @@ const SmtpForm = () => {onClick={() => setHidden(!hidden)}/>}+ disabled={!canUpdateConfig}/></FormSectionContent></FormSection>