Skip to content

Commit

Permalink
Remove default values from validation functions (#4861)
Browse files Browse the repository at this point in the history
  • Loading branch information
timleslie authored Feb 16, 2021
1 parent ca19c65 commit 6f985ac
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 25 deletions.
6 changes: 6 additions & 0 deletions .changeset/large-dots-attack.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
'@keystonejs/access-control': major
'@keystonejs/keystone': patch
---

The functions `validate*AccessControl` no longer set default values for the `authentication` value. If you are calling these functions directly you will need to make sure you pass in a value for `authentication`. If you are not directly calling these functions then there are no changes required.
29 changes: 8 additions & 21 deletions packages/access-control/src/access-control.ts
Original file line number Diff line number Diff line change
Expand Up @@ -293,22 +293,15 @@ export async function validateCustomAccessControl({
context,
info,
access,
authentication = {},
authentication,
gqlName,
}: { access: CustomAccess<CustomAccessArgs> } & CustomAccessArgs) {
// Either a boolean or an object describing a where clause
let result: Static | Declarative = false;
if (typeof access !== 'function') {
result = access;
} else {
result = await access({
item,
args,
context,
info,
authentication: authentication.item ? authentication : {},
gqlName,
});
result = await access({ item, args, context, info, authentication, gqlName });
}

if (!['object', 'boolean'].includes(typeof result)) {
Expand All @@ -323,7 +316,7 @@ export async function validateListAccessControl({
access,
listKey,
operation,
authentication = {},
authentication,
originalInput,
gqlName,
itemId,
Expand All @@ -337,7 +330,7 @@ export async function validateListAccessControl({
result = acc;
} else {
result = await acc({
authentication: authentication.item ? authentication : {},
authentication,
listKey,
operation,
originalInput,
Expand Down Expand Up @@ -371,7 +364,7 @@ export async function validateFieldAccessControl({
originalInput,
existingItem,
operation,
authentication = {},
authentication,
gqlName,
itemId,
itemIds,
Expand All @@ -383,7 +376,7 @@ export async function validateFieldAccessControl({
result = acc;
} else {
result = await acc({
authentication: authentication.item ? authentication : {},
authentication,
listKey,
fieldKey,
originalInput,
Expand All @@ -408,7 +401,7 @@ export async function validateFieldAccessControl({
export async function validateAuthAccessControl({
access,
listKey,
authentication = {},
authentication,
gqlName,
context,
}: { access: AuthAccess<AuthAccessArgs> } & Omit<AuthAccessArgs, 'operation'>) {
Expand All @@ -419,13 +412,7 @@ export async function validateAuthAccessControl({
if (typeof acc !== 'function') {
result = acc;
} else {
result = await acc({
authentication: authentication.item ? authentication : {},
listKey,
operation,
gqlName,
context,
});
result = await acc({ authentication, listKey, operation, gqlName, context });
}

if (!['object', 'boolean'].includes(typeof result)) {
Expand Down
8 changes: 4 additions & 4 deletions packages/keystone/lib/Keystone/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ module.exports = class Keystone {
context,
info,
access: access[schemaName],
authentication,
authentication: authentication && authentication.item ? authentication : {},
gqlName,
});
},
Expand All @@ -125,7 +125,7 @@ module.exports = class Keystone {
access: access[schemaName],
originalInput,
operation,
authentication,
authentication: authentication && authentication.item ? authentication : {},
listKey,
gqlName,
itemId,
Expand All @@ -151,7 +151,7 @@ module.exports = class Keystone {
originalInput,
existingItem,
operation,
authentication,
authentication: authentication && authentication.item ? authentication : {},
fieldKey,
listKey,
gqlName,
Expand All @@ -167,7 +167,7 @@ module.exports = class Keystone {
async (access, listKey, { gqlName, context } = {}) => {
return validateAuthAccessControl({
access: access[schemaName],
authentication,
authentication: authentication && authentication.item ? authentication : {},
listKey,
gqlName,
context,
Expand Down

1 comment on commit 6f985ac

@vercel
Copy link

@vercel vercel bot commented on 6f985ac Feb 16, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.