Skip to content

Commit

Permalink
tidy up variable names
Browse files Browse the repository at this point in the history
  • Loading branch information
dcousens committed Oct 5, 2022
1 parent f7a5f74 commit 4d9de0c
Showing 1 changed file with 18 additions and 16 deletions.
34 changes: 18 additions & 16 deletions packages/core/src/lib/core/mutations/access-control.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,20 +67,21 @@ async function enforceListLevelAccessControl({
item: BaseItem | undefined;
inputData: Record<string, unknown>;
}) {
let listResult: unknown; // should be boolean, but dont trust, it might accidentally be a filter
let accepted: unknown; // should be boolean, but dont trust, it might accidentally be a filter
try {
// apply access.item.* controls
if (operation === 'create') {
const listAccessControl = list.access.item[operation];
listResult = await listAccessControl({
const itemAccessControl = list.access.item[operation];
accepted = await itemAccessControl({
operation,
session: context.session,
listKey: list.listKey,
context,
inputData,
});
} else if (operation === 'update' && item !== undefined) {
const listAccessControl = list.access.item[operation];
listResult = await listAccessControl({
const itemAccessControl = list.access.item[operation];
accepted = await itemAccessControl({
operation,
session: context.session,
listKey: list.listKey,
Expand All @@ -89,8 +90,8 @@ async function enforceListLevelAccessControl({
inputData,
});
} else if (operation === 'delete' && item !== undefined) {
const listAccessControl = list.access.item[operation];
listResult = await listAccessControl({
const itemAccessControl = list.access.item[operation];
accepted = await itemAccessControl({
operation,
session: context.session,
listKey: list.listKey,
Expand All @@ -105,13 +106,13 @@ async function enforceListLevelAccessControl({
}

// short circuit the safe path
if (listResult === true) return;
if (accepted === true) return;

if (typeof listResult !== 'boolean') {
if (typeof accepted !== 'boolean') {
throw accessReturnError([
{
tag: `${list.listKey}.access.item.${operation}`,
returned: typeof listResult,
returned: typeof accepted,
},
]);
}
Expand All @@ -138,11 +139,12 @@ async function enforceFieldLevelAccessControl({

await Promise.allSettled(
Object.keys(inputData).map(async fieldKey => {
let fieldResult: unknown; // should be boolean, but dont trust
let accepted: unknown; // should be boolean, but dont trust
try {
// apply fields.[fieldKey].access.* controls
if (operation === 'create') {
const fieldAccessControl = list.fields[fieldKey].access[operation];
fieldResult = await fieldAccessControl({
accepted = await fieldAccessControl({
operation,
session: context.session,
listKey: list.listKey,
Expand All @@ -152,7 +154,7 @@ async function enforceFieldLevelAccessControl({
});
} else if (operation === 'update' && item !== undefined) {
const fieldAccessControl = list.fields[fieldKey].access[operation];
fieldResult = await fieldAccessControl({
accepted = await fieldAccessControl({
operation,
session: context.session,
listKey: list.listKey,
Expand All @@ -168,14 +170,14 @@ async function enforceFieldLevelAccessControl({
}

// short circuit the safe path
if (fieldResult === true) return;
if (accepted === true) return;
fieldsDenied.push(fieldKey);

// wrong type?
if (typeof fieldResult !== 'boolean') {
if (typeof accepted !== 'boolean') {
nonBooleans.push({
tag: `${list.listKey}.${fieldKey}.access.${operation}`,
returned: typeof fieldResult,
returned: typeof accepted,
});
}
})
Expand Down

0 comments on commit 4d9de0c

Please sign in to comment.