Skip to content

Commit 59870ac

Browse files
committed
fix(enterprise): scope enterprise plan check to target org in whitelabel PUT
1 parent a2d5e1a commit 59870ac

2 files changed

Lines changed: 15 additions & 6 deletions

File tree

apps/sim/app/api/organizations/[id]/whitelabel/route.ts

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
import { db } from '@sim/db'
2-
import { member, organization } from '@sim/db/schema'
2+
import { member, organization, subscription } from '@sim/db/schema'
33
import { createLogger } from '@sim/logger'
4-
import { and, eq } from 'drizzle-orm'
4+
import { and, eq, inArray } from 'drizzle-orm'
55
import { type NextRequest, NextResponse } from 'next/server'
66
import { z } from 'zod'
77
import { AuditAction, AuditResourceType, recordAudit } from '@/lib/audit/log'
88
import { getSession } from '@/lib/auth'
9-
import { isEnterpriseOrgAdminOrOwner } from '@/lib/billing/core/subscription'
9+
import { checkEnterprisePlan, USABLE_SUBSCRIPTION_STATUSES } from '@/lib/billing/core/subscription'
1010
import type { OrganizationWhitelabelSettings } from '@/lib/branding/types'
1111

1212
const logger = createLogger('WhitelabelAPI')
@@ -140,9 +140,18 @@ export async function PUT(request: NextRequest, { params }: { params: Promise<{
140140
)
141141
}
142142

143-
const hasAccess = await isEnterpriseOrgAdminOrOwner(session.user.id)
143+
const [orgSubscription] = await db
144+
.select()
145+
.from(subscription)
146+
.where(
147+
and(
148+
eq(subscription.referenceId, organizationId),
149+
inArray(subscription.status, USABLE_SUBSCRIPTION_STATUSES)
150+
)
151+
)
152+
.limit(1)
144153

145-
if (!hasAccess) {
154+
if (!orgSubscription || !checkEnterprisePlan(orgSubscription)) {
146155
return NextResponse.json(
147156
{ error: 'Whitelabeling is available on Enterprise plans only' },
148157
{ status: 403 }

apps/sim/ee/whitelabeling/hooks/whitelabel.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ export function useUpdateWhitelabelSettings() {
6666
const { data } = await response.json()
6767
return data as OrganizationWhitelabelSettings
6868
},
69-
onSuccess: (_data, { orgId }) => {
69+
onSettled: (_data, _error, { orgId }) => {
7070
queryClient.invalidateQueries({ queryKey: whitelabelKeys.settings(orgId) })
7171
queryClient.invalidateQueries({ queryKey: organizationKeys.detail(orgId) })
7272
},

0 commit comments

Comments
 (0)