Skip to content

Commit 74b91d5

Browse files
bsod90marianore-muttdata
authored andcommitted
chore(cubejs-server-core): make sure DAP doesn't generate empty filters (cube-js#9317)
while empty filters are technically allowed, they still have potential for breaking things downstream (like some UIs in Cube Cloud) which weren't designed with empty filters in mind.
1 parent 500a08f commit 74b91d5

File tree

1 file changed

+18
-4
lines changed

1 file changed

+18
-4
lines changed

packages/cubejs-server-core/src/core/CompilerApi.js

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -339,11 +339,25 @@ export class CompilerApi {
339339
viewFiltersPerCubePerRole,
340340
hasAllowAllForCube
341341
);
342-
query.filters = query.filters || [];
343-
query.filters.push(rlsFilter);
342+
if (rlsFilter) {
343+
query.filters = query.filters || [];
344+
query.filters.push(rlsFilter);
345+
}
344346
return { query, denied: false };
345347
}
346348

349+
removeEmptyFilters(filter) {
350+
if (filter?.and) {
351+
const and = filter.and.map(f => this.removeEmptyFilters(f)).filter(f => f);
352+
return and.length > 1 ? { and } : and.at(0) || null;
353+
}
354+
if (filter?.or) {
355+
const or = filter.or.map(f => this.removeEmptyFilters(f)).filter(f => f);
356+
return or.length > 1 ? { or } : or.at(0) || null;
357+
}
358+
return filter;
359+
}
360+
347361
buildFinalRlsFilter(cubeFiltersPerCubePerRole, viewFiltersPerCubePerRole, hasAllowAllForCube) {
348362
// - delete all filters for cubes where the user has allowAll
349363
// - combine the rest into per role maps
@@ -369,7 +383,7 @@ export class CompilerApi {
369383
{}
370384
);
371385

372-
return {
386+
return this.removeEmptyFilters({
373387
and: [{
374388
or: Object.keys(cubeFiltersPerRole).map(role => ({
375389
and: cubeFiltersPerRole[role]
@@ -379,7 +393,7 @@ export class CompilerApi {
379393
and: viewFiltersPerRole[role]
380394
}))
381395
}]
382-
};
396+
});
383397
}
384398

385399
async compilerCacheFn(requestId, key, path) {

0 commit comments

Comments
 (0)