Skip to content

Commit 2526a03

Browse files
committed
refactor: rename resolveAllowed to resolveVisible and update page handling logic
1 parent 2c7fa49 commit 2526a03

File tree

1 file changed

+11
-5
lines changed

1 file changed

+11
-5
lines changed

adminforth/modules/restApi.ts

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ export async function interpretResource(
7070
})
7171
);
7272

73-
const resolveAllowed = async (val: any): Promise<boolean> => {
73+
const resolveVisible = async (val: any): Promise<boolean> => {
7474
if (typeof val === 'boolean') return val;
7575
if (typeof val === 'function') {
7676
const r = val({ adminUser, resource, meta, source, adminforth });
@@ -79,11 +79,17 @@ export async function interpretResource(
7979
return true;
8080
};
8181

82-
const page: 'list' | 'show' | 'edit' = ({
82+
const pageMap = {
8383
[ActionCheckSource.ListRequest]: 'list',
8484
[ActionCheckSource.ShowRequest]: 'show',
8585
[ActionCheckSource.EditLoadRequest]: 'edit',
86-
} as const)[source] ?? 'show';
86+
} as const;
87+
88+
const page = pageMap[source as keyof typeof pageMap] as ('list'|'show'|'edit') | undefined;
89+
90+
if (!page) {
91+
return { allowedActions, visibleColumns: {} };
92+
}
8793

8894
const isColumnVisible = async (col: any): Promise<boolean> => {
8995
const si = col.showIn;
@@ -93,8 +99,8 @@ export async function interpretResource(
9399
return si.includes('all') || si.includes(page);
94100
}
95101

96-
if (si[page] !== undefined) return await resolveAllowed(si[page]);
97-
if (si.all !== undefined) return await resolveAllowed(si.all);
102+
if (si[page] !== undefined) return await resolveVisible(si[page]);
103+
if (si.all !== undefined) return await resolveVisible(si.all);
98104
return true;
99105
};
100106

0 commit comments

Comments
 (0)