Skip to content

The Postgres development platform. Supabase gives you a dedicated Postgres database to build your web, mobile, and AI applications.

Add ABAC for organization billing page

Joshen Lim4be52d9c853d
diff --git a/studio/components/interfaces/Organization/BillingSettings/BillingAddress/BillingAddress.tsx b/studio/components/interfaces/Organization/BillingSettings/BillingAddress/BillingAddress.tsx
index cd4cd587954..54db1fe6d9c 100644
--- a/studio/components/interfaces/Organization/BillingSettings/BillingAddress/BillingAddress.tsx
+++ b/studio/components/interfaces/Organization/BillingSettings/BillingAddress/BillingAddress.tsx
@@ -2,12 +2,14 @@ import { FC, useState } from 'react'
import { isEqual } from 'lodash'
import { Dictionary } from 'components/grid'
import { Form, Input, Button, Select } from '@supabase/ui'
+import { PermissionAction } from '@supabase/shared-types/out/constants'
-import { useStore } from 'hooks'
+import { checkPermissions, useStore } from 'hooks'
import { patch } from 'lib/common/fetch'
import { API_URL } from 'lib/constants'
import { COUNTRIES } from './BillingAddress.constants'
import Panel from 'components/ui/Panel'
+import NoPermission from 'components/ui/NoPermission'
interface Props {
loading: boolean
@@ -20,6 +22,12 @@ const BillingAddress: FC<Props> = ({ loading, address, onAddressUpdated }) => {
const orgSlug = ui.selectedOrganization?.slug ?? ''
const { city, country, line1, line2, postal_code, state } = address
+ const canReadBillingAddress = checkPermissions(PermissionAction.BILLING_READ, 'stripe.customer')
+ const canUpdateBillingAddress = checkPermissions(
+ PermissionAction.BILLING_WRITE,
+ 'stripe.customer'
+ )
+
const [isDirty, setIsDirty] = useState(false)
const initialValues = {
city,
@@ -76,6 +84,8 @@ const BillingAddress: FC<Props> = ({ loading, address, onAddressUpdated }) => {
<div className="shimmering-loader rounded py-3 mx-1 w-1/2" />
<div className="shimmering-loader rounded py-3 mx-1 w-1/3" />
</div>
+ ) : !canReadBillingAddress ? (
+ <NoPermission resourceText="view this organization's billing address" />
) : (
<Form
validateOnBlur
@@ -87,10 +97,26 @@ const BillingAddress: FC<Props> = ({ loading, address, onAddressUpdated }) => {
return (
<>
<Panel.Content className="w-3/5 space-y-2">
- <Input id="line1" name="line1" placeholder="Address line 1" />
- <Input id="line2" name="line2" placeholder="Address line 2" />
+ <Input
+ id="line1"
+ name="line1"
+ placeholder="Address line 1"
+ disabled={!canUpdateBillingAddress}
+ />
+ <Input
+ id="line2"
+ name="line2"
+ placeholder="Address line 2"
+ disabled={!canUpdateBillingAddress}
+ />
<div className="flex items-center space-x-2">
- <Select className="w-full" id="country" name="country" placeholder="Country">
+ <Select
+ className="w-full"
+ id="country"
+ name="country"
+ placeholder="Country"
+ disabled={!canUpdateBillingAddress}
+ >
<Select.Option key="empty" value="">
---
</Select.Option>
@@ -105,20 +131,41 @@ const BillingAddress: FC<Props> = ({ loading, address, onAddressUpdated }) => {
id="postal_code"
name="postal_code"
placeholder="Postal code"
+ disabled={!canUpdateBillingAddress}
/>
</div>
<div className="flex items-center space-x-2">
- <Input className="w-full" id="city" name="city" placeholder="City" />
- <Input className="w-full" id="state" name="state" placeholder="State" />
+ <Input
+ className="w-full"
+ id="city"
+ name="city"
+ placeholder="City"
+ disabled={!canUpdateBillingAddress}
+ />
+ <Input
+ className="w-full"
+ id="state"
+ name="state"
+ placeholder="State"
+ disabled={!canUpdateBillingAddress}
+ />
</div>
</Panel.Content>
<div className="border-t border-scale-400" />
- <Panel.Content>
+ <Panel.Content className="flex justify-between">
+ {!canUpdateBillingAddress ? (
+ <p className="text-sm text-scale-1000">
+ You need additional permissions to update this organization's billing
+ address
+ </p>
+ ) : (
+ <div />
+ )}
<div className="flex items-center space-x-4">
<Button
type="default"
htmlType="reset"
- disabled={!isDirty || isSubmitting}
+ disabled={!isDirty || isSubmitting || !canUpdateBillingAddress}
onClick={() => {
handleReset()
setIsDirty(false)
@@ -130,7 +177,7 @@ const BillingAddress: FC<Props> = ({ loading, address, onAddressUpdated }) => {
type="primary"
htmlType="submit"
loading={isSubmitting}
- disabled={!isDirty || isSubmitting}
+ disabled={!isDirty || isSubmitting || !canUpdateBillingAddress}
>
Save changes
</Button>
diff --git a/studio/components/interfaces/Organization/BillingSettings/PaymentMethods.tsx b/studio/components/interfaces/Organization/BillingSettings/PaymentMethods.tsx
index 21d302fe80f..387450491c9 100644
--- a/studio/components/interfaces/Organization/BillingSettings/PaymentMethods.tsx
+++ b/studio/components/interfaces/Organization/BillingSettings/PaymentMethods.tsx
@@ -5,7 +5,6 @@ import {
IconCreditCard,
Button,
Input,
- IconLoader,
Badge,
Modal,
Alert,
@@ -13,13 +12,15 @@ import {
IconX,
} from '@supabase/ui'
import * as Tooltip from '@radix-ui/react-tooltip'
+import { PermissionAction } from '@supabase/shared-types/out/constants'
-import { useStore } from 'hooks'
+import { checkPermissions, useStore, useFlag } from 'hooks'
import { delete_, patch } from 'lib/common/fetch'
import { getURL } from 'lib/helpers'
import { API_URL } from 'lib/constants'
import Panel from 'components/ui/Panel'
import { AddNewPaymentMethodModal } from 'components/interfaces/Billing'
+import NoPermission from 'components/ui/NoPermission'
interface Props {
loading: boolean
@@ -45,6 +46,16 @@ const PaymentMethods: FC<Props> = ({
const [showAddPaymentMethodModal, setShowAddPaymentMethodModal] = useState(false)
const [isUpdatingPaymentMethod, setIsUpdatingPaymentMethod] = useState(false)
+ const enablePermissions = useFlag('enablePermissions')
+
+ const canReadPaymentMethods = checkPermissions(
+ PermissionAction.BILLING_READ,
+ 'stripe.payment_methods'
+ )
+ const canUpdatePaymentMethods = enablePermissions
+ ? checkPermissions(PermissionAction.BILLING_WRITE, 'stripe.payment_methods')
+ : isOwner
+
const onConfirmMakeDefaultPaymentMethod = async () => {
try {
setIsUpdatingPaymentMethod(true)
@@ -97,141 +108,156 @@ const PaymentMethods: FC<Props> = ({
<h4>Payment methods</h4>
<p className="text-sm opacity-50">Charges will be deducted from the default card</p>
</div>
- <Panel
- loading={loading}
- footer={
- !loading && (
- <div>
- <Tooltip.Root delayDuration={0}>
- <Tooltip.Trigger>
- <Button
- key="panel-footer"
- type="default"
- icon={<IconPlus />}
- disabled={!isOwner}
- onClick={() => setShowAddPaymentMethodModal(true)}
- >
- Add new card
- </Button>
- </Tooltip.Trigger>
- {!isOwner && (
- <Tooltip.Content side="right">
- <Tooltip.Arrow className="radix-tooltip-arrow" />
- <div
- className={[
- 'bg-scale-100 rounded py-1 px-2 leading-none shadow', // background
- 'border-scale-200 w-48 border text-center', //border
- ].join(' ')}
- >
- <span className="text-scale-1200 text-xs">
- Only organization owners can update payment methods
- </span>
- </div>
- </Tooltip.Content>
+ {!canReadPaymentMethods ? (
+ <Panel>
+ <NoPermission resourceText="view this organization's payment methods" />
+ </Panel>
+ ) : (
+ <Panel
+ loading={loading}
+ footer={
+ !loading && (
+ <div className="flex justify-between w-full">
+ {!canUpdatePaymentMethods ? (
+ <p className="text-sm text-scale-1000">
+ You need additional permissions to update this organization's payment methods
+ </p>
+ ) : (
+ <div />
)}
- </Tooltip.Root>
- </div>
- )
- }
- >
- {loading && paymentMethods.length === 0 ? (
- <div className="flex flex-col justify-between space-y-2 py-4 px-4">
- <div className="shimmering-loader mx-1 w-2/3 rounded py-3" />
- <div className="shimmering-loader mx-1 w-1/2 rounded py-3" />
- <div className="shimmering-loader mx-1 w-1/3 rounded py-3" />
- </div>
- ) : paymentMethods.length >= 1 ? (
- <Panel.Content>
- <div className="space-y-2">
- {paymentMethods.map((paymentMethod: any) => {
- const isDefault = paymentMethod.id === defaultPaymentMethod
- return (
- <div key={paymentMethod.id} className="flex items-center justify-between">
- <div className="flex items-center space-x-8">
- <img
- src={`/img/payment-methods/${paymentMethod.card.brand
- .replace(' ', '-')
- .toLowerCase()}.png`}
- width="32"
- />
- <Input
- readOnly
- className="w-64"
- size="small"
- value={`•••• •••• •••• ${paymentMethod.card.last4}`}
- />
- {isDefault ? (
- <Badge color="gray">Default</Badge>
- ) : (
- <div className="opacity-0">
- <Badge color="gray">Default</Badge>
+ <div>
+ <Tooltip.Root delayDuration={0}>
+ <Tooltip.Trigger>
+ <Button
+ key="panel-footer"
+ type="default"
+ icon={<IconPlus />}
+ disabled={!canUpdatePaymentMethods}
+ onClick={() => setShowAddPaymentMethodModal(true)}
+ >
+ Add new card
+ </Button>
+ </Tooltip.Trigger>
+ {!canUpdatePaymentMethods && (
+ <Tooltip.Content side="right">
+ <Tooltip.Arrow className="radix-tooltip-arrow" />
+ <div
+ className={[
+ 'bg-scale-100 rounded py-1 px-2 leading-none shadow', // background
+ 'border-scale-200 w-48 border text-center', //border
+ ].join(' ')}
+ >
+ <span className="text-scale-1200 text-xs">
+ Only organization owners can update payment methods
+ </span>
</div>
- )}
- <p className="text-sm tabular-nums">
- Expires: {paymentMethod.card.exp_month}/{paymentMethod.card.exp_year}
- </p>
- </div>
- {isOwner && (
- <>
+ </Tooltip.Content>
+ )}
+ </Tooltip.Root>
+ </div>
+ </div>
+ )
+ }
+ >
+ {loading && paymentMethods.length === 0 ? (
+ <div className="flex flex-col justify-between space-y-2 py-4 px-4">
+ <div className="shimmering-loader mx-1 w-2/3 rounded py-3" />
+ <div className="shimmering-loader mx-1 w-1/2 rounded py-3" />
+ <div className="shimmering-loader mx-1 w-1/3 rounded py-3" />
+ </div>
+ ) : paymentMethods.length >= 1 ? (
+ <Panel.Content>
+ <div className="space-y-2">
+ {paymentMethods.map((paymentMethod: any) => {
+ const isDefault = paymentMethod.id === defaultPaymentMethod
+ return (
+ <div key={paymentMethod.id} className="flex items-center justify-between">
+ <div className="flex items-center space-x-8">
+ <img
+ src={`/img/payment-methods/${paymentMethod.card.brand
+ .replace(' ', '-')
+ .toLowerCase()}.png`}
+ width="32"
+ />
+ <Input
+ readOnly
+ className="w-64"
+ size="small"
+ value={`•••• •••• •••• ${paymentMethod.card.last4}`}
+ />
{isDefault ? (
- <Tooltip.Root delayDuration={0}>
- <Tooltip.Trigger>
- <Button disabled type="outline" icon={<IconX />} />
- </Tooltip.Trigger>
- <Tooltip.Content side="bottom">
- <Tooltip.Arrow className="radix-tooltip-arrow" />
- <div
- className={[
- 'bg-scale-100 rounded py-1 px-2 leading-none shadow', // background
- 'border-scale-200 w-48 border text-center', //border
- ].join(' ')}
- >
- <span className="text-scale-1200 text-xs">
- Your default payment method cannot be deleted
- </span>
- </div>
- </Tooltip.Content>
- </Tooltip.Root>
+ <Badge color="gray">Default</Badge>
) : (
- <Dropdown
- size="tiny"
- overlay={[
- <Dropdown.Item
- onClick={() => setSelectedMethodForDefault(paymentMethod)}
- >
- Make default
- </Dropdown.Item>,
- <Dropdown.Item
- onClick={() => setSelectedMethodToDelete(paymentMethod)}
- >
- Delete
- </Dropdown.Item>,
- ]}
- >
- <Button
- type="outline"
- icon={<IconMoreHorizontal />}
- loading={loading}
- className="hover:border-gray-500"
- />
- </Dropdown>
+ <div className="opacity-0">
+ <Badge color="gray">Default</Badge>
+ </div>
)}
- </>
- )}
- </div>
- )
- })}
- </div>
- </Panel.Content>
- ) : (
- <Panel.Content>
- <div className="flex items-center space-x-2 opacity-50">
- <IconCreditCard />
- <p className="text-sm">No payment methods</p>
- </div>
- </Panel.Content>
- )}
- </Panel>
+ <p className="text-sm tabular-nums">
+ Expires: {paymentMethod.card.exp_month}/{paymentMethod.card.exp_year}
+ </p>
+ </div>
+ {canUpdatePaymentMethods && (
+ <>
+ {isDefault ? (
+ <Tooltip.Root delayDuration={0}>
+ <Tooltip.Trigger>
+ <Button disabled type="outline" icon={<IconX />} />
+ </Tooltip.Trigger>
+ <Tooltip.Content side="bottom">
+ <Tooltip.Arrow className="radix-tooltip-arrow" />
+ <div
+ className={[
+ 'bg-scale-100 rounded py-1 px-2 leading-none shadow', // background
+ 'border-scale-200 w-48 border text-center', //border
+ ].join(' ')}
+ >
+ <span className="text-scale-1200 text-xs">
+ Your default payment method cannot be deleted
+ </span>
+ </div>
+ </Tooltip.Content>
+ </Tooltip.Root>
+ ) : (
+ <Dropdown
+ size="tiny"
+ overlay={[
+ <Dropdown.Item
+ onClick={() => setSelectedMethodForDefault(paymentMethod)}
+ >
+ Make default
+ </Dropdown.Item>,
+ <Dropdown.Item
+ onClick={() => setSelectedMethodToDelete(paymentMethod)}
+ >
+ Delete
+ </Dropdown.Item>,
+ ]}
+ >
+ <Button
+ type="outline"
+ icon={<IconMoreHorizontal />}
+ loading={loading}
+ className="hover:border-gray-500"
+ />
+ </Dropdown>
+ )}
+ </>
+ )}
+ </div>
+ )
+ })}
+ </div>
+ </Panel.Content>
+ ) : (
+ <Panel.Content>
+ <div className="flex items-center space-x-2 opacity-50">
+ <IconCreditCard />
+ <p className="text-sm">No payment methods</p>
+ </div>
+ </Panel.Content>
+ )}
+ </Panel>
+ )}
</div>
<AddNewPaymentMethodModal
diff --git a/studio/components/interfaces/Organization/BillingSettings/TaxID/TaxID.tsx b/studio/components/interfaces/Organization/BillingSettings/TaxID/TaxID.tsx
index 24016cd9e60..c659ac027e3 100644
--- a/studio/components/interfaces/Organization/BillingSettings/TaxID/TaxID.tsx
+++ b/studio/components/interfaces/Organization/BillingSettings/TaxID/TaxID.tsx
@@ -1,13 +1,15 @@
import { FC, useEffect, useState } from 'react'
import { isEqual } from 'lodash'
import { Input, Button, IconPlus, Select, IconX } from '@supabase/ui'
+import { PermissionAction } from '@supabase/shared-types/out/constants'
-import { useStore } from 'hooks'
+import { checkPermissions, useStore } from 'hooks'
import { uuidv4 } from 'lib/helpers'
import { post, delete_ } from 'lib/common/fetch'
import { API_URL } from 'lib/constants'
import Panel from 'components/ui/Panel'
import { TAX_IDS } from './TaxID.constants'
+import NoPermission from 'components/ui/NoPermission'
interface Props {
loading: boolean
@@ -47,6 +49,8 @@ const TaxID: FC<Props> = ({ loading, taxIds, onTaxIdsUpdated }) => {
}, [taxIds])
const hasChanges = !isEqual(taxIdValues, formattedTaxIds)
+ const canReadTaxIds = checkPermissions(PermissionAction.BILLING_READ, 'stripe.tax_ids')
+ const canUpdateTaxIds = checkPermissions(PermissionAction.BILLING_WRITE, 'stripe.tax_ids')
const onUpdateTaxId = (id: string, key: string, value: string) => {
const updatedTaxIds = taxIdValues.map((taxId: any) => {
@@ -132,85 +136,107 @@ const TaxID: FC<Props> = ({ loading, taxIds, onTaxIdsUpdated }) => {
If you would like to include specific tax ID(s) to your invoices
</p>
</div>
- <Panel
- loading={loading}
- footer={
- !loading && (
- <div className="flex items-center space-x-4">
- <Button
- type="default"
- htmlType="reset"
- disabled={!hasChanges || isSaving}
- onClick={() => onResetTaxIds()}
- >
- Cancel
- </Button>
- <Button
- type="primary"
- htmlType="submit"
- loading={isSaving}
- disabled={!hasChanges || isSaving}
- onClick={() => onSaveTaxIds()}
- >
- Save changes
- </Button>
- </div>
- )
- }
- >
- {loading && taxIdValues.length === 0 ? (
- <div className="flex flex-col justify-between space-y-2 py-4 px-4">
- <div className="shimmering-loader rounded py-3 mx-1 w-2/3" />
- <div className="shimmering-loader rounded py-3 mx-1 w-1/2" />
- <div className="shimmering-loader rounded py-3 mx-1 w-1/3" />
- </div>
- ) : (
- <Panel.Content className="w-3/5 space-y-4">
- {taxIdValues.length >= 1 ? (
- <div className="w-full space-y-2">
- {taxIdValues.map((taxId: any, idx: number) => {
- const selectedTaxId = TAX_IDS.find((option) => option.name === taxId.name)
- return (
- <div key={`tax-id-${idx}`} className="flex items-center space-x-2">
- <Select
- value={selectedTaxId?.name}
- onChange={(e: any) => onUpdateTaxId(taxId.id, 'name', e.target.value)}
- >
- {TAX_IDS.map((option) => (
- <Select.Option key={option.name} value={option.name}>
- {option.name}
- </Select.Option>
- ))}
- </Select>
- <Input
- value={taxId.value}
- placeholder={selectedTaxId?.placeholder ?? ''}
- onChange={(e: any) => onUpdateTaxId(taxId.id, 'value', e.target.value)}
- />
- <Button
- type="text"
- icon={<IconX />}
- onClick={() => onRemoveTaxId(taxId.id)}
- ></Button>
- </div>
- )
- })}
- </div>
- ) : (
- <div>
- <p className="flex items-center space-x-2 text-sm text-scale-900">No tax IDs</p>
+
+ {!canReadTaxIds ? (
+ <Panel>
+ <NoPermission resourceText="to view this organization's tax IDs" />
+ </Panel>
+ ) : (
+ <Panel
+ loading={loading}
+ footer={
+ !loading && (
+ <div className="flex justify-between w-full">
+ {!canUpdateTaxIds ? (
+ <p className="text-sm text-scale-1000">
+ You need additional permissions to update this organization's tax IDs
+ </p>
+ ) : (
+ <div />
+ )}
+ <div className="flex items-center space-x-4">
+ <Button
+ type="default"
+ htmlType="reset"
+ disabled={!hasChanges || isSaving}
+ onClick={() => onResetTaxIds()}
+ >
+ Cancel
+ </Button>
+ <Button
+ type="primary"
+ htmlType="submit"
+ loading={isSaving}
+ disabled={!hasChanges || isSaving}
+ onClick={() => onSaveTaxIds()}
+ >
+ Save changes
+ </Button>
+ </div>
</div>
- )}
- <div
- className="flex items-center space-x-2 opacity-50 hover:opacity-100 transition cursor-pointer"
- onClick={() => onAddNewTaxId()}
- >
- <IconPlus size={14} />
- <p className="text-sm">Add another ID</p>
+ )
+ }
+ >
+ {loading && taxIdValues.length === 0 ? (
+ <div className="flex flex-col justify-between space-y-2 py-4 px-4">
+ <div className="shimmering-loader rounded py-3 mx-1 w-2/3" />
+ <div className="shimmering-loader rounded py-3 mx-1 w-1/2" />
+ <div className="shimmering-loader rounded py-3 mx-1 w-1/3" />
</div>
- </Panel.Content>
- )}
- </Panel>
+ ) : (
+ <Panel.Content className="w-3/5 space-y-4">
+ {taxIdValues.length >= 1 ? (
+ <div className="w-full space-y-2">
+ {taxIdValues.map((taxId: any, idx: number) => {
+ const selectedTaxId = TAX_IDS.find((option) => option.name === taxId.name)
+ return (
+ <div key={`tax-id-${idx}`} className="flex items-center space-x-2">
+ <Select
+ value={selectedTaxId?.name}
+ onChange={(e: any) => onUpdateTaxId(taxId.id, 'name', e.target.value)}
+ disabled={!canUpdateTaxIds}
+ >
+ {TAX_IDS.map((option) => (
+ <Select.Option key={option.name} value={option.name}>
+ {option.name}
+ </Select.Option>
+ ))}
+ </Select>
+ <Input
+ value={taxId.value}
+ placeholder={selectedTaxId?.placeholder ?? ''}
+ onChange={(e: any) => onUpdateTaxId(taxId.id, 'value', e.target.value)}
+ disabled={!canUpdateTaxIds}
+ />
+ {canUpdateTaxIds && (
+ <Button
+ type="text"
+ icon={<IconX />}
+ onClick={() => onRemoveTaxId(taxId.id)}
+ />
+ )}
+ </div>
+ )
+ })}
+ </div>
+ ) : (
+ <div>
+ <p className="flex items-center space-x-2 text-sm text-scale-900">No tax IDs</p>
+ </div>
+ )}
+ {canUpdateTaxIds && (
+ <div
+ className="flex items-center space-x-2 opacity-50 hover:opacity-100 transition cursor-pointer"
+ onClick={() => onAddNewTaxId()}
+ >
+ <IconPlus size={14} />
+ <p className="text-sm">Add another ID</p>
+ </div>
+ )}
+ </Panel.Content>
+ )}
+ </Panel>
+ )}
</div>
)
}
diff --git a/studio/components/interfaces/Organization/GeneralSettings/GeneralSettings.tsx b/studio/components/interfaces/Organization/GeneralSettings/GeneralSettings.tsx
index 208cf886778..78d79557f89 100644
--- a/studio/components/interfaces/Organization/GeneralSettings/GeneralSettings.tsx
+++ b/studio/components/interfaces/Organization/GeneralSettings/GeneralSettings.tsx
@@ -29,16 +29,20 @@ const GeneralSettings = observer(() => {
}
const enablePermissions = useFlag('enablePermissions')
- // [Joshen TODO] This is a fallback to original behaviour if permissions is not enabled
+
const canUpdateOrganization = enablePermissions
? checkPermissions(PermissionAction.SQL_UPDATE, 'postgres.public.organizations')
: ui.selectedOrganization?.is_owner
- // [Joshen TODO] This is a fallback to original behaviour if permissions is not enabled
const canDeleteOrganization = enablePermissions
? checkPermissions(PermissionAction.SQL_UPDATE, 'postgres.public.organizations')
: ui.selectedOrganization?.is_owner
+ const canReadBillingEmail = checkPermissions(
+ PermissionAction.SQL_SELECT,
+ 'postgres.public.organizations'
+ )
+
const onUpdateOrganization = async (values: any, { setSubmitting, resetForm }: any) => {
if (!canUpdateOrganization) {
return ui.setNotification({
@@ -109,6 +113,7 @@ const GeneralSettings = observer(() => {
id="billing_email"
size="small"
label="Billing email"
+ type={canReadBillingEmail ? 'text' : 'password'}
disabled={!canUpdateOrganization}
/>
</FormSectionContent>
diff --git a/studio/components/interfaces/Organization/InvoicesSettings/InvoicesSettings.tsx b/studio/components/interfaces/Organization/InvoicesSettings/InvoicesSettings.tsx
index a102f419d92..fb054f6474a 100644
--- a/studio/components/interfaces/Organization/InvoicesSettings/InvoicesSettings.tsx
+++ b/studio/components/interfaces/Organization/InvoicesSettings/InvoicesSettings.tsx
@@ -8,11 +8,13 @@ import {
IconChevronLeft,
IconChevronRight,
} from '@supabase/ui'
+import { PermissionAction } from '@supabase/shared-types/out/constants'
-import { useStore } from 'hooks'
+import { checkPermissions, useStore } from 'hooks'
import { API_URL } from 'lib/constants'
import { get, head } from 'lib/common/fetch'
import Table from 'components/to-be-cleaned/Table'
+import NoPermission from 'components/ui/NoPermission'
const PAGE_LIMIT = 10
@@ -35,7 +37,11 @@ const InvoicesSettings: FC<Props> = ({ organization }) => {
const { stripe_customer_id } = organization
const offset = (page - 1) * PAGE_LIMIT
+ const canReadInvoices = checkPermissions(PermissionAction.SQL_SELECT, 'postgres.public.invoices')
+
useEffect(() => {
+ if (!canReadInvoices) return
+
let cancel = false
const page = 1
@@ -91,6 +97,10 @@ const InvoicesSettings: FC<Props> = ({ organization }) => {
}
}
+ if (!canReadInvoices) {
+ return <NoPermission resourceText="view invoices" />
+ }
+
return (
<div className="my-4 container max-w-4xl space-y-1">
<Loading active={loading}>
diff --git a/studio/components/ui/NoPermission.tsx b/studio/components/ui/NoPermission.tsx
new file mode 100644
index 00000000000..7c192d8725d
--- /dev/null
+++ b/studio/components/ui/NoPermission.tsx
@@ -0,0 +1,34 @@
+import { IconAlertCircle } from '@supabase/ui'
+import { FC } from 'react'
+
+interface Props {
+ resourceText: string
+}
+
+const NoPermission: FC<Props> = ({ resourceText }) => (
+ <div
+ className={[
+ 'block w-full rounded border border-opacity-20 py-4 px-6',
+ 'border-gray-600 bg-gray-100',
+ 'dark:border-gray-300 dark:bg-gray-400',
+ ].join(' ')}
+ >
+ <div className="flex space-x-3">
+ <div className="mt-1">
+ <IconAlertCircle size="large" />
+ </div>
+ <div className="flex w-full items-center justify-between">
+ <div className="space-y-1">
+ <p className="text-sm">You do not have permission to {resourceText}</p>
+ <div>
+ <p className="text-scale-1100 text-sm">
+ Contact your organization owner or adminstrator for assistance.
+ </p>
+ </div>
+ </div>
+ </div>
+ </div>
+ </div>
+)
+
+export default NoPermission
diff --git a/studio/components/ui/UpgradeToPro.tsx b/studio/components/ui/UpgradeToPro.tsx
index a3f6151b067..256188ff527 100644
--- a/studio/components/ui/UpgradeToPro.tsx
+++ b/studio/components/ui/UpgradeToPro.tsx
@@ -1,4 +1,4 @@
-import { Button, IconClock, Typography } from '@supabase/ui'
+import { Button, IconClock } from '@supabase/ui'
import Link from 'next/link'
import { FC } from 'react'
@@ -22,7 +22,7 @@ const UpgradeToPro: FC<Props> = ({ primaryText, projectRef, secondaryText }) =>
</div>
<div className="flex w-full items-center justify-between">
<div className="space-y-1">
- <p>{primaryText}</p>
+ <p className="text-sm">{primaryText}</p>
<div>
<p className="text-scale-1100 text-sm">{secondaryText}</p>
</div>
diff --git a/studio/hooks/queries/usePermissions.ts b/studio/hooks/queries/usePermissions.ts
index fd8f6da153f..43f256df51e 100644
--- a/studio/hooks/queries/usePermissions.ts
+++ b/studio/hooks/queries/usePermissions.ts
@@ -4,6 +4,7 @@ import jsonLogic from 'json-logic-js'
import { useFlag, useStore } from 'hooks'
import { get } from 'lib/common/fetch'
import { API_URL, IS_PLATFORM } from 'lib/constants'
+import { toJS } from 'mobx'
export function usePermissions(returning?: 'minimal') {
let url = `${API_URL}/profile/permissions`
@@ -31,6 +32,15 @@ export function checkPermissions(action: string, resource: string, data?: object
const { ui } = useStore()
+ const xxx = ui.permissions
+ .filter(
+ (p: any) =>
+ p.organization_id === ui.selectedOrganization?.id &&
+ p.resources.filter((r: any) => r.indexOf('postgres.public') > -1)
+ )
+ .map((p: any) => toJS(p))
+ console.log(xxx)
+
return (ui?.permissions ?? [])
.filter(
(permission: {