|
1 | 1 | import { db } from '@sim/db' |
2 | | -import { member, organization } from '@sim/db/schema' |
| 2 | +import { member, organization, subscription } from '@sim/db/schema' |
3 | 3 | import { createLogger } from '@sim/logger' |
4 | | -import { and, eq } from 'drizzle-orm' |
| 4 | +import { and, eq, inArray } from 'drizzle-orm' |
5 | 5 | import { type NextRequest, NextResponse } from 'next/server' |
6 | 6 | import { z } from 'zod' |
7 | 7 | import { AuditAction, AuditResourceType, recordAudit } from '@/lib/audit/log' |
8 | 8 | import { getSession } from '@/lib/auth' |
9 | | -import { isEnterpriseOrgAdminOrOwner } from '@/lib/billing/core/subscription' |
| 9 | +import { checkEnterprisePlan, USABLE_SUBSCRIPTION_STATUSES } from '@/lib/billing/core/subscription' |
10 | 10 | import type { OrganizationWhitelabelSettings } from '@/lib/branding/types' |
11 | 11 |
|
12 | 12 | const logger = createLogger('WhitelabelAPI') |
@@ -140,9 +140,18 @@ export async function PUT(request: NextRequest, { params }: { params: Promise<{ |
140 | 140 | ) |
141 | 141 | } |
142 | 142 |
|
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) |
144 | 153 |
|
145 | | - if (!hasAccess) { |
| 154 | + if (!orgSubscription || !checkEnterprisePlan(orgSubscription)) { |
146 | 155 | return NextResponse.json( |
147 | 156 | { error: 'Whitelabeling is available on Enterprise plans only' }, |
148 | 157 | { status: 403 } |
|
0 commit comments