Skip to content

Commit 73d0185

Browse files
committed
Revert "feat: filter returned fields based on column showIn visibility"
This reverts commit 2c7fa49.
1 parent c7cb3be commit 73d0185

File tree

1 file changed

+6
-40
lines changed

1 file changed

+6
-40
lines changed

adminforth/modules/restApi.ts

Lines changed: 6 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,10 @@ export async function interpretResource(
2929
meta: any,
3030
source: ActionCheckSource,
3131
adminforth: IAdminForth
32-
): Promise<{ allowedActions: AllowedActionsResolved; visibleColumns: Record<string, boolean> }> {
32+
): Promise<{allowedActions: AllowedActionsResolved}> {
3333
if (process.env.HEAVY_DEBUG) {
3434
console.log('🪲Interpreting resource', resource.resourceId, source, 'adminUser', adminUser);
3535
}
36-
3736
const allowedActions = {} as AllowedActionsResolved;
3837

3938
// we need to compute only allowed actions for this source:
@@ -62,6 +61,8 @@ export async function interpretResource(
6261
allowedActions[key] = false;
6362
return;
6463
}
64+
65+
// if callable then call
6566
if (typeof value === 'function') {
6667
allowedActions[key] = await value({ adminUser, resource, meta, source, adminforth });
6768
} else {
@@ -70,41 +71,7 @@ export async function interpretResource(
7071
})
7172
);
7273

73-
const resolveAllowed = async (val: any): Promise<boolean> => {
74-
if (typeof val === 'boolean') return val;
75-
if (typeof val === 'function') {
76-
const r = val({ adminUser, resource, meta, source, adminforth });
77-
return r instanceof Promise ? await r : !!r;
78-
}
79-
return true;
80-
};
81-
82-
const page: 'list' | 'show' | 'edit' = ({
83-
[ActionCheckSource.ListRequest]: 'list',
84-
[ActionCheckSource.ShowRequest]: 'show',
85-
[ActionCheckSource.EditLoadRequest]: 'edit',
86-
} as const)[source] ?? 'show';
87-
88-
const isColumnVisible = async (col: any): Promise<boolean> => {
89-
const si = col.showIn;
90-
if (!si) return true;
91-
92-
if (Array.isArray(si)) {
93-
return si.includes('all') || si.includes(page);
94-
}
95-
96-
if (si[page] !== undefined) return await resolveAllowed(si[page]);
97-
if (si.all !== undefined) return await resolveAllowed(si.all);
98-
return true;
99-
};
100-
101-
const visibleColumnsEntries = await Promise.all(
102-
resource.columns.map(async (col) => [col.name, await isColumnVisible(col)] as const)
103-
);
104-
105-
const visibleColumns = Object.fromEntries(visibleColumnsEntries) as Record<string, boolean>;
106-
107-
return { allowedActions, visibleColumns };
74+
return { allowedActions };
10875
}
10976

11077
export default class AdminForthRestAPI implements IAdminForthRestAPI {
@@ -635,7 +602,7 @@ export default class AdminForthRestAPI implements IAdminForthRestAPI {
635602
meta.pk = body.filters.find((f) => f.field === resource.columns.find((col) => col.primaryKey).name)?.value;
636603
}
637604

638-
const { allowedActions, visibleColumns } = await interpretResource(
605+
const { allowedActions } = await interpretResource(
639606
adminUser,
640607
resource,
641608
meta,
@@ -837,8 +804,7 @@ export default class AdminForthRestAPI implements IAdminForthRestAPI {
837804
// remove all columns which are not defined in resources, or defined but backendOnly
838805
data.data.forEach((item) => {
839806
Object.keys(item).forEach((key) => {
840-
console.log(visibleColumns?.[key], key);
841-
if (!resource.columns.find((col) => col.name === key) || resource.columns.find((col) => col.name === key && col.backendOnly) || visibleColumns?.[key] === false ) {
807+
if (!resource.columns.find((col) => col.name === key) || resource.columns.find((col) => col.name === key && col.backendOnly)) {
842808
delete item[key];
843809
}
844810
})

0 commit comments

Comments
 (0)