Skip to content

Commit

Permalink
Rename exitingItem argument to item for access control functions (#4074)
Browse files Browse the repository at this point in the history
  • Loading branch information
JedWatson authored Oct 30, 2020
1 parent d91a638 commit 4afaa99
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 9 deletions.
4 changes: 2 additions & 2 deletions examples-next/auth/schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
10 changes: 5 additions & 5 deletions packages-next/keystone/src/lib/createAccessControlContext.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ async function validateFieldAccessControl({
listKey,
fieldKey,
originalInput,
existingItem,
item,
operation,
session,
gqlName,
Expand All @@ -76,7 +76,7 @@ async function validateFieldAccessControl({
itemId: any;
itemIds: any;
context: any;
existingItem: any;
item: any;
fieldKey: any;
}) {
let result;
Expand All @@ -88,7 +88,7 @@ async function validateFieldAccessControl({
listKey,
fieldKey,
originalInput,
existingItem,
item,
operation,
gqlName,
itemId,
Expand Down Expand Up @@ -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,
Expand Down
8 changes: 6 additions & 2 deletions packages-next/types/src/schema/access-control.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,12 +99,16 @@ type FieldCreateAccessArgs<GeneratedListTypes extends BaseGeneratedListTypes> =
BaseFieldAccessArgs;

type FieldReadAccessArgs<GeneratedListTypes extends BaseGeneratedListTypes> = ReadAccessArgs &
BaseFieldAccessArgs & { existingItem: GeneratedListTypes['backing'] };
BaseFieldAccessArgs & {
item: GeneratedListTypes['backing'];
};

type FieldUpdateAccessArgs<GeneratedListTypes extends BaseGeneratedListTypes> = UpdateAccessArgs<
GeneratedListTypes
> &
BaseFieldAccessArgs & { existingItem: GeneratedListTypes['backing'] };
BaseFieldAccessArgs & {
item: GeneratedListTypes['backing'];
};

type FieldDeleteAccessArgs = DeleteAccessArgs & BaseFieldAccessArgs;

Expand Down

0 comments on commit 4afaa99

Please sign in to comment.