Skip to content

Commit

Permalink
Fix access.filter.* passing listKey: undefined (#8122)
Browse files Browse the repository at this point in the history
Co-authored-by: Daniel Cousens <dcousens@users.noreply.github.com>
  • Loading branch information
dcousens and dcousens committed Nov 25, 2022
1 parent c61c1bd commit a841063
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 8 deletions.
5 changes: 5 additions & 0 deletions .changeset/fix-no-listkey.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@keystone-6/core': patch
---

Fixes `access.filter.*` passing `listKey: undefined`
34 changes: 26 additions & 8 deletions packages/core/src/lib/core/access-control.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,17 +71,35 @@ export async function getOperationAccess(
export async function getAccessFilters(
list: InitialisedList,
context: KeystoneContext,
operation: 'update' | 'query' | 'delete'
operation: keyof typeof list.access.filter
): Promise<boolean | InputFilter> {
const access = list.access.filter[operation];
try {
const filters = await access({
operation,
session: context.session,
list: list.listKey,
context,
} as any); // TODO: FIXME
let filters;
if (operation === 'query') {
filters = await list.access.filter.query({
operation,
session: context.session,
listKey: list.listKey,
context,
});
} else if (operation === 'update') {
filters = await list.access.filter.update({
operation,
session: context.session,
listKey: list.listKey,
context,
});
} else if (operation === 'delete') {
filters = await list.access.filter.delete({
operation,
session: context.session,
listKey: list.listKey,
context,
});
}

if (typeof filters === 'boolean') return filters;
if (!filters) return false; // shouldn't happen, but, Typescript

const schema = context.sudo().graphql.schema;
const whereInput = assertInputObjectType(schema.getType(getGqlNames(list).whereInputName));
Expand Down

0 comments on commit a841063

Please sign in to comment.