Skip to content

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

Revert is owner check

Joshen Limdb2eab934d01
diff --git a/studio/components/interfaces/Billing/Subscription/Subscription.tsx b/studio/components/interfaces/Billing/Subscription/Subscription.tsx
index c18eabca6ce..e530c8fca30 100644
--- a/studio/components/interfaces/Billing/Subscription/Subscription.tsx
+++ b/studio/components/interfaces/Billing/Subscription/Subscription.tsx
@@ -5,7 +5,7 @@ import { useRouter } from 'next/router'
import { Button, Loading } from '@supabase/ui'
import { PermissionAction } from '@supabase/shared-types/out/constants'
-import { checkPermissions, useFlag, checkIsOwner } from 'hooks'
+import { checkPermissions, useStore, useFlag } from 'hooks'
import { STRIPE_PRODUCT_IDS } from 'lib/constants'
import { formatBytes } from 'lib/helpers'
@@ -35,8 +35,9 @@ const Subscription: FC<Props> = ({
currentPeriodStart,
currentPeriodEnd,
}) => {
+ const { ui } = useStore()
const router = useRouter()
- const isOrgOwner = checkIsOwner()
+ const isOrgOwner = ui.selectedOrganization?.is_owner
const projectUpdateDisabled = useFlag('disableProjectCreationAndUpdate')
const canChangeSubscription = checkPermissions(
diff --git a/studio/components/interfaces/Organization/BillingSettings/PaymentMethods.tsx b/studio/components/interfaces/Organization/BillingSettings/PaymentMethods.tsx
index bf0bedd485d..21d302fe80f 100644
--- a/studio/components/interfaces/Organization/BillingSettings/PaymentMethods.tsx
+++ b/studio/components/interfaces/Organization/BillingSettings/PaymentMethods.tsx
@@ -14,7 +14,7 @@ import {
} from '@supabase/ui'
import * as Tooltip from '@radix-ui/react-tooltip'
-import { useStore, checkIsOwner } from 'hooks'
+import { useStore } from 'hooks'
import { delete_, patch } from 'lib/common/fetch'
import { getURL } from 'lib/helpers'
import { API_URL } from 'lib/constants'
@@ -38,7 +38,7 @@ const PaymentMethods: FC<Props> = ({
}) => {
const { ui } = useStore()
const orgSlug = ui.selectedOrganization?.slug ?? ''
- const isOwner = checkIsOwner()
+ const isOwner = ui.selectedOrganization?.is_owner
const [selectedMethodForDefault, setSelectedMethodForDefault] = useState<any>()
const [selectedMethodToDelete, setSelectedMethodToDelete] = useState<any>()
diff --git a/studio/components/interfaces/Organization/GeneralSettings/GeneralSettings.tsx b/studio/components/interfaces/Organization/GeneralSettings/GeneralSettings.tsx
index 3c8672356a7..208cf886778 100644
--- a/studio/components/interfaces/Organization/GeneralSettings/GeneralSettings.tsx
+++ b/studio/components/interfaces/Organization/GeneralSettings/GeneralSettings.tsx
@@ -3,7 +3,7 @@ import { observer } from 'mobx-react-lite'
import { Form, Input } from '@supabase/ui'
import { PermissionAction } from '@supabase/shared-types/out/constants'
-import { useFlag, useStore, checkPermissions, checkIsOwner } from 'hooks'
+import { useFlag, useStore, checkPermissions } from 'hooks'
import { API_URL } from 'lib/constants'
import { patch } from 'lib/common/fetch'
@@ -32,12 +32,12 @@ const GeneralSettings = observer(() => {
// [Joshen TODO] This is a fallback to original behaviour if permissions is not enabled
const canUpdateOrganization = enablePermissions
? checkPermissions(PermissionAction.SQL_UPDATE, 'postgres.public.organizations')
- : checkIsOwner()
+ : 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')
- : checkIsOwner()
+ : ui.selectedOrganization?.is_owner
const onUpdateOrganization = async (values: any, { setSubmitting, resetForm }: any) => {
if (!canUpdateOrganization) {
diff --git a/studio/hooks/queries/usePermissions.ts b/studio/hooks/queries/usePermissions.ts
index 6d2f065d17b..66944873b70 100644
--- a/studio/hooks/queries/usePermissions.ts
+++ b/studio/hooks/queries/usePermissions.ts
@@ -55,32 +55,3 @@ export function checkPermissions(action: string, resource: string, data?: object
condition === null || jsonLogic.apply(condition, data)
)
}
-
-// [Joshen TODO] This method is just to support legacy permissions where
-// a couple of the UI was checking only if the user is an owner or not
-// Will deprecate once ABAC is fully rolled out.
-export function checkIsOwner() {
- const { app, ui } = useStore()
- const router = useRouter()
-
- let organization: Organization | undefined
- const { ref, slug } = router.query
-
- if (ref) {
- const project = find(app.projects.list(), { ref }) as Project | undefined
- organization = find(app.organizations.list(), { id: project?.organization_id })
- } else if (slug) {
- organization = find(app.organizations.list(), { slug }) as Organization | undefined
- }
-
- if (!organization) return false
-
- const { roles } = useOrganizationRoles(slug as string)
- const { members } = useOrganizationDetail(slug as string)
-
- const userMember = (members || []).find((member) => member.gotrue_id === ui?.profile?.gotrue_id)
- const [memberRoleId] = userMember?.role_ids ?? []
- const memberRole = (roles || []).find((role) => role.id === memberRoleId)
-
- return memberRole?.name === 'Owner'
-}
diff --git a/studio/pages/new/[slug].tsx b/studio/pages/new/[slug].tsx
index 287209f9900..f177926ae00 100644
--- a/studio/pages/new/[slug].tsx
+++ b/studio/pages/new/[slug].tsx
@@ -22,16 +22,7 @@ import {
DEFAULT_FREE_PROJECTS_LIMIT,
PRICING_TIER_PRODUCT_IDS,
} from 'lib/constants'
-import {
- useStore,
- useFlag,
- withAuth,
- useSubscriptionStats,
- checkIsOwner,
- checkPermissions,
- useOrganizationDetail,
- useOrganizationRoles,
-} from 'hooks'
+import { useStore, useFlag, withAuth, useSubscriptionStats, checkPermissions } from 'hooks'
import { WizardLayoutWithoutAuth } from 'components/layouts'
import Panel from 'components/ui/Panel'
@@ -66,7 +57,7 @@ const Wizard: NextPageWithLayout = () => {
const currentOrg = organizations.find((o: any) => o.slug === slug)
const stripeCustomerId = currentOrg?.stripe_customer_id
- const isOrganizationOwner = checkIsOwner()
+ const isOrganizationOwner = ui.selectedOrganization?.is_owner
const totalFreeProjects = subscriptionStats.total_active_free_projects
const freeProjectsLimit = ui.profile?.free_project_limit ?? DEFAULT_FREE_PROJECTS_LIMIT
diff --git a/studio/types/base.ts b/studio/types/base.ts
index 986b07ac4a8..8068ca7cbb7 100644
--- a/studio/types/base.ts
+++ b/studio/types/base.ts
@@ -5,7 +5,7 @@ export interface Organization {
slug: string
name: string
billing_email: string
- is_owner?: boolean // [Joshen] This will be deprecated after ABAC full roll out
+ is_owner?: boolean
stripe_customer_id?: string
}