Extension of https://github.com/payloadcms/payload/pull/13213 This PR correctly filters tenants, users and documents based on the users assigned tenants if any are set. If a user is assigned tenants then list results should only show documents with those tenants (when selector is not set). Previously you could construct access results that allows them to see them, but in the confines of the admin panel they should not see them. If you wanted a user to be able to see a "public" tenant while inside the admin panel they either need to be added to the tenant or have no tenants at all. Note that this is for filtering only, access control still controls what documents a user has _access_ to a document. The filters are and always have been a way to filter out results in the list view.
54 lines
1.5 KiB
TypeScript
54 lines
1.5 KiB
TypeScript
import { multiTenantPlugin } from '@payloadcms/plugin-multi-tenant'
|
|
import { fileURLToPath } from 'node:url'
|
|
import path from 'path'
|
|
const filename = fileURLToPath(import.meta.url)
|
|
const dirname = path.dirname(filename)
|
|
|
|
import type { Config as ConfigType } from './payload-types.js'
|
|
|
|
import { buildConfigWithDefaults } from '../buildConfigWithDefaults.js'
|
|
import { Menu } from './collections/Menu.js'
|
|
import { MenuItems } from './collections/MenuItems.js'
|
|
import { Tenants } from './collections/Tenants.js'
|
|
import { Users } from './collections/Users/index.js'
|
|
import { seed } from './seed/index.js'
|
|
import { menuItemsSlug, menuSlug } from './shared.js'
|
|
|
|
export default buildConfigWithDefaults({
|
|
collections: [Tenants, Users, MenuItems, Menu],
|
|
admin: {
|
|
autoLogin: false,
|
|
importMap: {
|
|
baseDir: path.resolve(dirname),
|
|
},
|
|
components: {
|
|
graphics: {
|
|
Logo: '/components/Logo/index.js#Logo',
|
|
Icon: '/components/Icon/index.js#Icon',
|
|
},
|
|
},
|
|
},
|
|
onInit: seed,
|
|
plugins: [
|
|
multiTenantPlugin<ConfigType>({
|
|
userHasAccessToAllTenants: (user) => Boolean(user.roles?.includes('admin')),
|
|
useTenantsCollectionAccess: false,
|
|
tenantField: {
|
|
access: {},
|
|
},
|
|
collections: {
|
|
[menuItemsSlug]: {
|
|
useTenantAccess: false,
|
|
},
|
|
[menuSlug]: {
|
|
isGlobal: true,
|
|
},
|
|
},
|
|
tenantSelectorLabel: { en: 'Site', es: 'Site in es' },
|
|
}),
|
|
],
|
|
typescript: {
|
|
outputFile: path.resolve(dirname, 'payload-types.ts'),
|
|
},
|
|
})
|