Skip to content

Commit e81bfb2

Browse files
committed
fix: patch isVisible when applying member level policies
1 parent c77fe3b commit e81bfb2

File tree

1 file changed

+15
-24
lines changed

1 file changed

+15
-24
lines changed

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

Lines changed: 15 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -422,12 +422,10 @@ export class CompilerApi {
422422
}
423423

424424
/**
425-
* if RBAC is enabled, this method is used to filter out the cubes that the
426-
* user doesn't have access from meta responses.
427-
* It evaluates all applicable memeberLevel accessPolicies givean a context
428-
* and retains members that are allowed by any policy (most permissive set).
425+
* if RBAC is enabled, this method is used to patch isVisible property of cube members
426+
* based on access policies.
429427
*/
430-
async filterVisibilityByAccessPolicy(compilers, context, cubes) {
428+
async patchVisibilityByAccessPolicy(compilers, context, cubes) {
431429
const isMemberVisibleInContext = {};
432430
const { cubeEvaluator } = compilers;
433431

@@ -468,59 +466,52 @@ export class CompilerApi {
468466
}
469467
}
470468

471-
const visibilityFilterForCube = (cube) => {
472-
const isDevMode = getEnv('devMode');
469+
const visibilityPatcherForCube = (cube) => {
473470
const evaluatedCube = cubeEvaluator.cubeFromPath(cube.config.name);
474471
if (!cubeEvaluator.isRbacEnabledForCube(evaluatedCube)) {
475-
return (item) => isDevMode || context.signedWithPlaygroundAuthSecret || item.isVisible;
472+
return (item) => item.isVisible;
476473
}
477-
return (item) => (
478-
(isDevMode || context.signedWithPlaygroundAuthSecret || item.isVisible) &&
479-
isMemberVisibleInContext[item.name] || false);
474+
return (item) => (item.isVisible && isMemberVisibleInContext[item.name] || false);
480475
};
481476

482477
return cubes
483478
.map((cube) => ({
484479
config: {
485480
...cube.config,
486-
measures: cube.config.measures?.filter(visibilityFilterForCube(cube)),
487-
dimensions: cube.config.dimensions?.filter(visibilityFilterForCube(cube)),
488-
segments: cube.config.segments?.filter(visibilityFilterForCube(cube)),
481+
measures: cube.config.measures?.map(visibilityPatcherForCube(cube)),
482+
dimensions: cube.config.dimensions?.map(visibilityPatcherForCube(cube)),
483+
segments: cube.config.segments?.map(visibilityPatcherForCube(cube)),
489484
},
490-
})).filter(
491-
cube => cube.config.measures?.length ||
492-
cube.config.dimensions?.length ||
493-
cube.config.segments?.length
494-
);
485+
}));
495486
}
496487

497488
async metaConfig(requestContext, options = {}) {
498489
const { includeCompilerId, ...restOptions } = options;
499490
const compilers = await this.getCompilers(restOptions);
500491
const { cubes } = compilers.metaTransformer;
501-
const filteredCubes = await this.filterVisibilityByAccessPolicy(
492+
const patchedCubes = await this.patchVisibilityByAccessPolicy(
502493
compilers,
503494
requestContext,
504495
cubes
505496
);
506497
if (includeCompilerId) {
507498
return {
508-
cubes: filteredCubes,
499+
cubes: patchedCubes,
509500
compilerId: compilers.compilerId,
510501
};
511502
}
512-
return filteredCubes;
503+
return patchedCubes;
513504
}
514505

515506
async metaConfigExtended(requestContext, options) {
516507
const compilers = await this.getCompilers(options);
517-
const filteredCubes = await this.filterVisibilityByAccessPolicy(
508+
const patchedCubes = await this.patchVisibilityByAccessPolicy(
518509
compilers,
519510
requestContext,
520511
compilers.metaTransformer?.cubes
521512
);
522513
return {
523-
metaConfig: filteredCubes,
514+
metaConfig: patchedCubes,
524515
cubeDefinitions: compilers.metaTransformer?.cubeEvaluator?.cubeDefinitions,
525516
};
526517
}

0 commit comments

Comments
 (0)