Skip to content

Commit 2bb1d21

Browse files
authored
fix: patch isVisible when applying member level access policies (#8921)
* fix: ignore Data Access Policy-defined visibility in dev-mode and playground * fix: patch isVisible when applying member level policies
1 parent 61c5ac6 commit 2bb1d21

File tree

1 file changed

+19
-21
lines changed

1 file changed

+19
-21
lines changed

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

Lines changed: 19 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import crypto from 'crypto';
22
import R from 'ramda';
3+
import { getEnv } from '@cubejs-backend/shared';
34
import { createQuery, compile, queryClass, PreAggregations, QueryFactory } from '@cubejs-backend/schema-compiler';
45
import { v4 as uuidv4 } from 'uuid';
56
import { NativeInstance } from '@cubejs-backend/native';
@@ -421,12 +422,10 @@ export class CompilerApi {
421422
}
422423

423424
/**
424-
* if RBAC is enabled, this method is used to filter out the cubes that the
425-
* user doesn't have access from meta responses.
426-
* It evaluates all applicable memeberLevel accessPolicies givean a context
427-
* 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.
428427
*/
429-
async filterVisibilityByAccessPolicy(compilers, context, cubes) {
428+
async patchVisibilityByAccessPolicy(compilers, context, cubes) {
430429
const isMemberVisibleInContext = {};
431430
const { cubeEvaluator } = compilers;
432431

@@ -467,56 +466,55 @@ export class CompilerApi {
467466
}
468467
}
469468

470-
const visibilityFilterForCube = (cube) => {
469+
const visibilityPatcherForCube = (cube) => {
471470
const evaluatedCube = cubeEvaluator.cubeFromPath(cube.config.name);
472471
if (!cubeEvaluator.isRbacEnabledForCube(evaluatedCube)) {
473-
return (item) => item.isVisible;
472+
return (item) => item;
474473
}
475-
return (item) => (item.isVisible && isMemberVisibleInContext[item.name] || false);
474+
return (item) => ({
475+
...item,
476+
isVisible: item.isVisible && isMemberVisibleInContext[item.name]
477+
});
476478
};
477479

478480
return cubes
479481
.map((cube) => ({
480482
config: {
481483
...cube.config,
482-
measures: cube.config.measures?.filter(visibilityFilterForCube(cube)),
483-
dimensions: cube.config.dimensions?.filter(visibilityFilterForCube(cube)),
484-
segments: cube.config.segments?.filter(visibilityFilterForCube(cube)),
484+
measures: cube.config.measures?.map(visibilityPatcherForCube(cube)),
485+
dimensions: cube.config.dimensions?.map(visibilityPatcherForCube(cube)),
486+
segments: cube.config.segments?.map(visibilityPatcherForCube(cube)),
485487
},
486-
})).filter(
487-
cube => cube.config.measures?.length ||
488-
cube.config.dimensions?.length ||
489-
cube.config.segments?.length
490-
);
488+
}));
491489
}
492490

493491
async metaConfig(requestContext, options = {}) {
494492
const { includeCompilerId, ...restOptions } = options;
495493
const compilers = await this.getCompilers(restOptions);
496494
const { cubes } = compilers.metaTransformer;
497-
const filteredCubes = await this.filterVisibilityByAccessPolicy(
495+
const patchedCubes = await this.patchVisibilityByAccessPolicy(
498496
compilers,
499497
requestContext,
500498
cubes
501499
);
502500
if (includeCompilerId) {
503501
return {
504-
cubes: filteredCubes,
502+
cubes: patchedCubes,
505503
compilerId: compilers.compilerId,
506504
};
507505
}
508-
return filteredCubes;
506+
return patchedCubes;
509507
}
510508

511509
async metaConfigExtended(requestContext, options) {
512510
const compilers = await this.getCompilers(options);
513-
const filteredCubes = await this.filterVisibilityByAccessPolicy(
511+
const patchedCubes = await this.patchVisibilityByAccessPolicy(
514512
compilers,
515513
requestContext,
516514
compilers.metaTransformer?.cubes
517515
);
518516
return {
519-
metaConfig: filteredCubes,
517+
metaConfig: patchedCubes,
520518
cubeDefinitions: compilers.metaTransformer?.cubeEvaluator?.cubeDefinitions,
521519
};
522520
}

0 commit comments

Comments
 (0)