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 { CollectionConfig } from "payload/types";
|
||||||
|
import { isAdmin } from "@/access/isAdmin";
|
||||||
|
import { isEditor } from "@/access/isEditor";
|
||||||
|
import { isSSG } from "@/access/isSSG";
|
||||||
|
|
||||||
const Posts: CollectionConfig = {
|
const Posts: CollectionConfig = {
|
||||||
slug: "posts",
|
slug: "posts",
|
||||||
versions: true,
|
versions: true,
|
||||||
@ -7,9 +11,11 @@ const Posts: CollectionConfig = {
|
|||||||
useAsTitle: "title",
|
useAsTitle: "title",
|
||||||
},
|
},
|
||||||
access: {
|
access: {
|
||||||
|
//TODO: Author can CRUD own post
|
||||||
|
create: isEditor,
|
||||||
read: () => true,
|
read: () => true,
|
||||||
create: () => true,
|
update: isEditor,
|
||||||
update: () => true,
|
delete: isEditor,
|
||||||
},
|
},
|
||||||
hooks: {
|
hooks: {
|
||||||
afterChange: [
|
afterChange: [
|
||||||
@ -84,6 +90,7 @@ const Posts: CollectionConfig = {
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "author",
|
name: "author",
|
||||||
|
//TODO: Add active user as default
|
||||||
type: 'relationship',
|
type: 'relationship',
|
||||||
relationTo: 'users',
|
relationTo: 'users',
|
||||||
hasMany: false,
|
hasMany: false,
|
||||||
@ -95,6 +102,7 @@ const Posts: CollectionConfig = {
|
|||||||
{
|
{
|
||||||
name: "status",
|
name: "status",
|
||||||
type: "select",
|
type: "select",
|
||||||
|
required: true,
|
||||||
options: [
|
options: [
|
||||||
{
|
{
|
||||||
value: "draft",
|
value: "draft",
|
||||||
|
Loading…
x
Reference in New Issue
Block a user