Merge branch 'master' of github.com:trouble/payload

This commit is contained in:
Jarrod Flesch
2020-11-19 16:52:40 -05:00
33 changed files with 327 additions and 464 deletions

View File

@@ -16,10 +16,19 @@ const accessPromise = async ({
}) => {
const resultingData = data;
if (field.access && field.access[operation]) {
const result = overrideAccess ? true : await field.access[operation]({ req, id });
let accessOperation;
if (!result && operation === 'update' && originalDoc[field.name] !== undefined) {
if (hook === 'afterRead') {
accessOperation = 'read';
} else if (hook === 'beforeValidate') {
if (operation === 'update') accessOperation = 'update';
if (operation === 'create') accessOperation = 'create';
}
if (field.access && field.access[accessOperation]) {
const result = overrideAccess ? true : await field.access[accessOperation]({ req, id });
if (!result && accessOperation === 'update' && originalDoc[field.name] !== undefined) {
resultingData[field.name] = originalDoc[field.name];
} else if (!result) {
delete resultingData[field.name];

View File

@@ -23,7 +23,7 @@ const hookPromise = async ({
data: fullData,
operation,
req,
});
}) || data[field.name];
if (hookedValue !== undefined) {
resultingData[field.name] = hookedValue;

View File

@@ -6,7 +6,7 @@ const validationPromise = async ({
field,
path,
}) => {
if (hook === 'beforeValidate') return true;
if (hook !== 'beforeChange') return true;
const hasCondition = field.admin && field.admin.condition;
const shouldValidate = field.validate && !hasCondition;