Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rename existingItem argument to item for access control functions #4074

Merged
merged 4 commits into from
Oct 30, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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