diff --git a/examples-next/auth/schema.ts b/examples-next/auth/schema.ts index 46aa266084d..1d94a124b76 100644 --- a/examples-next/auth/schema.ts +++ b/examples-next/auth/schema.ts @@ -28,8 +28,8 @@ export const lists = createSchema({ access: { // Passwords can always be set when creating items // Users can change their own passwords, and Admins can change anyone's password - update: ({ session, existingItem }) => - session && (session.item.isAdmin || session.itemId === existingItem.id), + update: ({ session, item }) => + session && (session.item.isAdmin || session.itemId === item.id), }, admin: { // Based on the same logic as update access, the password field is editable. diff --git a/packages-next/keystone/src/lib/createAccessControlContext.ts b/packages-next/keystone/src/lib/createAccessControlContext.ts index f301f69ea96..57937ff233b 100644 --- a/packages-next/keystone/src/lib/createAccessControlContext.ts +++ b/packages-next/keystone/src/lib/createAccessControlContext.ts @@ -59,7 +59,7 @@ async function validateFieldAccessControl({ listKey, fieldKey, originalInput, - existingItem, + item, operation, session, gqlName, @@ -76,7 +76,7 @@ async function validateFieldAccessControl({ itemId: any; itemIds: any; context: any; - existingItem: any; + item: any; fieldKey: any; }) { let result; @@ -88,7 +88,7 @@ async function validateFieldAccessControl({ listKey, fieldKey, originalInput, - existingItem, + item, operation, gqlName, itemId, @@ -144,14 +144,14 @@ export const accessControlContext = { listKey: any, fieldKey: any, originalInput: any, - existingItem: any, + item: any, operation: any, { gqlName, itemId, itemIds, context }: any = {} ) { return validateFieldAccessControl({ access: access[context.schemaName], originalInput, - existingItem, + item, operation, session: context.session, fieldKey, diff --git a/packages-next/types/src/schema/access-control.ts b/packages-next/types/src/schema/access-control.ts index 07d39159fd5..ad22564459e 100644 --- a/packages-next/types/src/schema/access-control.ts +++ b/packages-next/types/src/schema/access-control.ts @@ -99,12 +99,16 @@ type FieldCreateAccessArgs = BaseFieldAccessArgs; type FieldReadAccessArgs = ReadAccessArgs & - BaseFieldAccessArgs & { existingItem: GeneratedListTypes['backing'] }; + BaseFieldAccessArgs & { + item: GeneratedListTypes['backing']; + }; type FieldUpdateAccessArgs = UpdateAccessArgs< GeneratedListTypes > & - BaseFieldAccessArgs & { existingItem: GeneratedListTypes['backing'] }; + BaseFieldAccessArgs & { + item: GeneratedListTypes['backing']; + }; type FieldDeleteAccessArgs = DeleteAccessArgs & BaseFieldAccessArgs;