-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathindex.ts
More file actions
59 lines (57 loc) · 1.69 KB
/
index.ts
File metadata and controls
59 lines (57 loc) · 1.69 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
import type { CollectionConfig } from 'payload'
import { byGlobalRole } from '@/access/byGlobalRole'
import { byTenantRole } from '@/access/byTenantRole'
import { filterByTenant } from '@/access/filterByTenant'
import { contentHashField } from '@/fields/contentHashField'
import { tenantField } from '@/fields/tenantField'
import { titleField } from '@/fields/title'
import { populatePublishedAt } from '@/hooks/populatePublishedAt'
import { getTenantSlugFromCookie } from '@/utilities/tenancy/getTenantFromCookie'
export const BuiltInPages: CollectionConfig<'pages'> = {
slug: 'builtInPages',
labels: {
singular: 'Built-In Page',
plural: 'Built-In Pages',
},
access: {
create: ({ req }) => {
const tenantSlug = getTenantSlugFromCookie(req.headers)
return tenantSlug ? byGlobalRole('create', 'builtInPages')({ req }) : false
},
read: byTenantRole('read', 'builtInPages'),
update: byGlobalRole('update', 'builtInPages'),
delete: ({ req }) => {
if (!byGlobalRole('delete', 'builtInPages')({ req })) return false
return { isInNav: { not_equals: true } }
},
},
admin: {
group: 'Content',
useAsTitle: 'title',
baseListFilter: filterByTenant,
defaultColumns: ['title', 'url', 'tenant'],
},
fields: [
titleField(),
{
name: 'url',
label: 'URL',
type: 'text',
required: true,
},
{
name: 'isInNav',
type: 'checkbox',
defaultValue: false,
admin: {
hidden: true,
description: 'Pages used in navigation cannot be deleted to prevent broken links.',
},
},
tenantField(),
contentHashField(),
],
hooks: {
beforeChange: [populatePublishedAt],
},
}