Skip to content

Commit

Permalink
fix: omit field default value if read access returns false (#4518)
Browse files Browse the repository at this point in the history
  • Loading branch information
JarrodMFlesch committed Dec 15, 2023
1 parent 2650c70 commit 3e9ef84
Showing 1 changed file with 3 additions and 0 deletions.
3 changes: 3 additions & 0 deletions packages/payload/src/fields/hooks/afterRead/promise.ts
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,7 @@ export const promise = async ({
}

// Execute access control
let allowDefaultValue = true
if (triggerAccessControl && field.access && field.access.read) {
const result = overrideAccess
? true
Expand All @@ -262,13 +263,15 @@ export const promise = async ({
})

if (!result) {
allowDefaultValue = false
delete siblingDoc[field.name]
}
}

// Set defaultValue on the field for globals being returned without being first created
// or collection documents created prior to having a default
if (
allowDefaultValue &&
typeof siblingDoc[field.name] === 'undefined' &&
typeof field.defaultValue !== 'undefined'
) {
Expand Down

0 comments on commit 3e9ef84

Please sign in to comment.