File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -3,6 +3,8 @@ import { seed } from '@/endpoints/seed'
33import config from '@payload-config'
44import { headers } from 'next/headers'
55
6+ import { checkRole } from '@/access/utilities'
7+
68export const maxDuration = 300 // This function can run for a maximum of 300 seconds
79
810export async function POST ( ) : Promise < Response > {
@@ -12,7 +14,7 @@ export async function POST(): Promise<Response> {
1214 // Authenticate by passing request headers
1315 const { user } = await payload . auth ( { headers : requestHeaders } )
1416
15- if ( ! user ) {
17+ if ( ! user || ! checkRole ( [ 'admin' ] , user ) ) {
1618 return new Response ( 'Action forbidden.' , { status : 403 } )
1719 }
1820
Original file line number Diff line number Diff line change 11import { slugField } from 'payload'
22import type { CollectionConfig } from 'payload'
33
4+ import { adminOnly } from '@/access/adminOnly'
5+
46export const Categories : CollectionConfig = {
57 slug : 'categories' ,
68 access : {
9+ create : adminOnly ,
10+ delete : adminOnly ,
711 read : ( ) => true ,
12+ update : adminOnly ,
813 } ,
914 admin : {
1015 useAsTitle : 'title' ,
Original file line number Diff line number Diff line change 88import path from 'path'
99import { fileURLToPath } from 'url'
1010
11+ import { adminOnly } from '@/access/adminOnly'
12+
1113const filename = fileURLToPath ( import . meta. url )
1214const dirname = path . dirname ( filename )
1315
@@ -17,7 +19,10 @@ export const Media: CollectionConfig = {
1719 } ,
1820 slug : 'media' ,
1921 access : {
22+ create : adminOnly ,
23+ delete : adminOnly ,
2024 read : ( ) => true ,
25+ update : adminOnly ,
2126 } ,
2227 fields : [
2328 {
Original file line number Diff line number Diff line change @@ -15,6 +15,7 @@ export const Users: CollectionConfig = {
1515 create : publicAccess ,
1616 delete : adminOnly ,
1717 read : adminOrSelf ,
18+ unlock : adminOnly ,
1819 update : adminOrSelf ,
1920 } ,
2021 admin : {
Original file line number Diff line number Diff line change 11import type { GlobalConfig } from 'payload'
22
3+ import { adminOnly } from '@/access/adminOnly'
34import { link } from '@/fields/link'
45
56export const Footer : GlobalConfig = {
67 slug : 'footer' ,
78 access : {
89 read : ( ) => true ,
10+ update : adminOnly ,
911 } ,
1012 fields : [
1113 {
Original file line number Diff line number Diff line change 11import type { GlobalConfig } from 'payload'
22
3+ import { adminOnly } from '@/access/adminOnly'
34import { link } from '@/fields/link'
45
56export const Header : GlobalConfig = {
67 slug : 'header' ,
78 access : {
89 read : ( ) => true ,
10+ update : adminOnly ,
911 } ,
1012 fields : [
1113 {
Original file line number Diff line number Diff line change @@ -36,11 +36,22 @@ export const plugins: Plugin[] = [
3636 payment : false ,
3737 } ,
3838 formSubmissionOverrides : {
39+ access : {
40+ delete : isAdmin ,
41+ read : isAdmin ,
42+ update : isAdmin ,
43+ } ,
3944 admin : {
4045 group : 'Content' ,
4146 } ,
4247 } ,
4348 formOverrides : {
49+ access : {
50+ delete : isAdmin ,
51+ read : isAdmin ,
52+ update : isAdmin ,
53+ create : isAdmin ,
54+ } ,
4455 admin : {
4556 group : 'Content' ,
4657 } ,
You can’t perform that action at this time.
0 commit comments