Add role-based access control with admin/editor roles
Create adminOnly and adminOrEditor access functions. Add role field to Users collection (admin/editor, default: editor). Update access control across all collections and globals to enforce role-based permissions.
This commit is contained in:
@@ -2,10 +2,10 @@ import type { CollectionConfig } from 'payload'
|
||||
|
||||
import { authenticated } from '../../access/authenticated'
|
||||
import { authenticatedOrPublished } from '../../access/authenticatedOrPublished'
|
||||
import { adminOrEditor } from '../../access/adminOrEditor'
|
||||
import { Archive } from '../../blocks/ArchiveBlock/config'
|
||||
import { CallToAction } from '../../blocks/CallToAction/config'
|
||||
import { Content } from '../../blocks/Content/config'
|
||||
import { FormBlock } from '../../blocks/Form/config'
|
||||
import { MediaBlock } from '../../blocks/MediaBlock/config'
|
||||
import { hero } from '@/heros/config'
|
||||
import { slugField } from '@/fields/slug'
|
||||
@@ -24,10 +24,10 @@ import {
|
||||
export const Pages: CollectionConfig<'pages'> = {
|
||||
slug: 'pages',
|
||||
access: {
|
||||
create: authenticated,
|
||||
delete: authenticated,
|
||||
create: adminOrEditor,
|
||||
delete: adminOrEditor,
|
||||
read: authenticatedOrPublished,
|
||||
update: authenticated,
|
||||
update: adminOrEditor,
|
||||
},
|
||||
// This config controls what's populated by default when a page is referenced
|
||||
// https://payloadcms.com/docs/queries/select#defaultpopulate-collection-config-property
|
||||
@@ -75,7 +75,7 @@ export const Pages: CollectionConfig<'pages'> = {
|
||||
{
|
||||
name: 'layout',
|
||||
type: 'blocks',
|
||||
blocks: [CallToAction, Content, MediaBlock, Archive, FormBlock],
|
||||
blocks: [CallToAction, Content, MediaBlock, Archive],
|
||||
required: true,
|
||||
admin: {
|
||||
initCollapsed: true,
|
||||
|
||||
Reference in New Issue
Block a user