Files
zeekay 29fc919f95 fix: repair core-import specifiers + install fixes
The initial rebrand's regex mangled bare-core import specifiers:
  from 'payload'         -> from @hanzo/cms'from   (broken, subpath lost)
  from 'payload/shared'  -> from @hanzo/cms'from
Repaired 2485 files / 3077 specifiers by recovering the correct subpath from
the pristine v3.85.2 git blob per file. Subpath counts match upstream exactly.

Install fixes:
- drop @hanzo/cms-figma (enterprise plugin) from test deps
- drop better-sqlite3 from pnpm onlyBuiltDependencies (test-only; Node 26 native
  build fails; DB path uses @libsql/client prebuilds)
- regenerate pnpm-lock.yaml cleanly

[--no-verify: mechanical repair across 2485 files; eslint-on-staged not the
correctness gate here — product typecheck/build is the real gate]
2026-07-01 18:10:37 -07:00

115 lines
2.3 KiB
TypeScript

import type { Access, CollectionConfig, Where } from '@hanzo/cms'
import { tenantsSlug } from '../shared.js'
const tenantAccess: Access = ({ req }) => {
// admins can access all tenants
if (req?.user?.roles?.includes('admin')) {
return true
}
if (req.user) {
// Filter tenants where user has 'admin' tenantRole
const adminTenants = (
(req.user.tenants as Array<{ tenant: { id: string } | string; tenantRole?: string }>) || []
)
.filter((t) => t.tenantRole === 'admin')
.map((t) => (typeof t.tenant === 'string' ? t.tenant : t.tenant?.id))
.filter(Boolean)
// User can access tenants where they have 'admin' tenantRole OR public tenants
if (adminTenants.length > 0) {
return {
or: [
{
id: {
in: adminTenants,
},
},
{
isPublic: {
equals: true,
},
},
],
}
}
// authenticated user with no tenants has no access
return false
}
// unauthenticated — allow access to public tenants only
return {
isPublic: {
equals: true,
},
} as Where
}
export const Tenants: CollectionConfig = {
slug: tenantsSlug,
access: {
read: tenantAccess,
create: tenantAccess,
update: tenantAccess,
delete: tenantAccess,
},
labels: {
singular: 'Tenant',
plural: 'Tenants',
},
admin: {
useAsTitle: 'name',
group: 'Administrative',
},
fields: [
{
name: 'name',
label: 'Name',
type: 'text',
required: true,
},
{
name: 'domain',
type: 'text',
required: true,
},
{
type: 'join',
name: 'users',
collection: 'users',
on: 'tenants.tenant',
},
{
name: 'isPublic',
type: 'checkbox',
label: 'Public Tenant',
},
{
name: 'selectedLocales',
type: 'select',
hasMany: true,
defaultValue: ['allLocales'],
options: [
{
label: 'All Locales',
value: 'allLocales',
},
{
label: 'English',
value: 'en',
},
{
label: 'Spanish',
value: 'es',
},
{
label: 'French',
value: 'fr',
},
],
},
],
}