generated from autonomic-cooperative/astro-payload-template
Add posts full CRUD for editor role
This commit is contained in:
parent
1ccf660f5b
commit
d7f22fdd5f
12
payload/src/access/isEditor.ts
Normal file
12
payload/src/access/isEditor.ts
Normal file
@ -0,0 +1,12 @@
|
||||
import { Access, FieldAccess } from "payload/types";
|
||||
import { User } from "../payload-types";
|
||||
|
||||
export const isEditor: Access<any, User> = ({ req: { user } }) => {
|
||||
// Return true or false based on if the user has an editor role
|
||||
return Boolean(user?.roles?.includes('editor', 'admin'));
|
||||
}
|
||||
|
||||
export const isEditorFieldLevel: FieldAccess<{ id: string }, unknown, User> = ({ req: { user } }) => {
|
||||
// Return true or false based on if the user has an editor role
|
||||
return Boolean(user?.roles?.includes('editor', 'admin'));
|
||||
}
|
@ -1,4 +1,8 @@
|
||||
import { CollectionConfig } from "payload/types";
|
||||
import { isAdmin } from "@/access/isAdmin";
|
||||
import { isEditor } from "@/access/isEditor";
|
||||
import { isSSG } from "@/access/isSSG";
|
||||
|
||||
const Posts: CollectionConfig = {
|
||||
slug: "posts",
|
||||
versions: true,
|
||||
@ -7,9 +11,11 @@ const Posts: CollectionConfig = {
|
||||
useAsTitle: "title",
|
||||
},
|
||||
access: {
|
||||
//TODO: Author can CRUD own post
|
||||
create: isEditor,
|
||||
read: () => true,
|
||||
create: () => true,
|
||||
update: () => true,
|
||||
update: isEditor,
|
||||
delete: isEditor,
|
||||
},
|
||||
hooks: {
|
||||
afterChange: [
|
||||
@ -84,6 +90,7 @@ const Posts: CollectionConfig = {
|
||||
},
|
||||
{
|
||||
name: "author",
|
||||
//TODO: Add active user as default
|
||||
type: 'relationship',
|
||||
relationTo: 'users',
|
||||
hasMany: false,
|
||||
@ -95,6 +102,7 @@ const Posts: CollectionConfig = {
|
||||
{
|
||||
name: "status",
|
||||
type: "select",
|
||||
required: true,
|
||||
options: [
|
||||
{
|
||||
value: "draft",
|
||||
|
Loading…
Reference in New Issue
Block a user