Skip to content

Commit 5636511

Browse files
committed
refactor: simplify backend-only column visibility checks in REST API
1 parent a74ae1a commit 5636511

File tree

1 file changed

+14
-16
lines changed

1 file changed

+14
-16
lines changed

adminforth/modules/restApi.ts

Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ async function resolveBoolOrFn(
3535
}
3636
): Promise<boolean> {
3737
if (typeof val === 'function') {
38-
return !!(await (val as any)(ctx));
38+
return !!(await (val)(ctx));
3939
}
4040
return !!val;
4141
}
@@ -50,7 +50,7 @@ async function isBackendOnly(
5050
adminforth: IAdminForth;
5151
}
5252
): Promise<boolean> {
53-
return await resolveBoolOrFn(col.backendOnly as BackendOnlyInput, ctx);
53+
return await resolveBoolOrFn(col.backendOnly, ctx);
5454
}
5555

5656
async function isShown(
@@ -404,20 +404,18 @@ export default class AdminForthRestAPI implements IAdminForthRestAPI {
404404

405405
// strip all backendOnly fields or not described in adminForth fields from dbUser
406406
// (when user defines column and does not set backendOnly, we assume it is not backendOnly)
407-
{
408-
const ctx = {
409-
adminUser,
410-
resource: userResource,
411-
meta: {},
412-
source: ActionCheckSource.ShowRequest,
413-
adminforth: this.adminforth,
414-
};
415-
for (const key of Object.keys(adminUser.dbUser)) {
416-
const col = userResource.columns.find((c) => c.name === key);
417-
const bo = col ? await isBackendOnly(col, ctx) : true;
418-
if (!col || bo) {
419-
delete adminUser.dbUser[key];
420-
}
407+
const ctx = {
408+
adminUser,
409+
resource: userResource,
410+
meta: {},
411+
source: ActionCheckSource.ShowRequest,
412+
adminforth: this.adminforth,
413+
};
414+
for (const key of Object.keys(adminUser.dbUser)) {
415+
const col = userResource.columns.find((c) => c.name === key);
416+
const bo = col ? await isBackendOnly(col, ctx) : true;
417+
if (!col || bo) {
418+
delete adminUser.dbUser[key];
421419
}
422420
}
423421

0 commit comments

Comments
 (0)