@@ -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,55 @@ 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 ;
476473 }
477- return ( item ) => (
478- ( isDevMode || context . signedWithPlaygroundAuthSecret || item . isVisible ) &&
479- isMemberVisibleInContext [ item . name ] || false ) ;
474+ return ( item ) => {
475+ item . isVisible = ( item . isVisible && isMemberVisibleInContext [ item . name ] || false ) ;
476+ return item ;
477+ } ;
480478 } ;
481479
482480 return cubes
483481 . map ( ( cube ) => ( {
484482 config : {
485483 ...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 ) ) ,
484+ measures : cube . config . measures ?. map ( visibilityPatcherForCube ( cube ) ) ,
485+ dimensions : cube . config . dimensions ?. map ( visibilityPatcherForCube ( cube ) ) ,
486+ segments : cube . config . segments ?. map ( visibilityPatcherForCube ( cube ) ) ,
489487 } ,
490- } ) ) . filter (
491- cube => cube . config . measures ?. length ||
492- cube . config . dimensions ?. length ||
493- cube . config . segments ?. length
494- ) ;
488+ } ) ) ;
495489 }
496490
497491 async metaConfig ( requestContext , options = { } ) {
498492 const { includeCompilerId, ...restOptions } = options ;
499493 const compilers = await this . getCompilers ( restOptions ) ;
500494 const { cubes } = compilers . metaTransformer ;
501- const filteredCubes = await this . filterVisibilityByAccessPolicy (
495+ const patchedCubes = await this . patchVisibilityByAccessPolicy (
502496 compilers ,
503497 requestContext ,
504498 cubes
505499 ) ;
506500 if ( includeCompilerId ) {
507501 return {
508- cubes : filteredCubes ,
502+ cubes : patchedCubes ,
509503 compilerId : compilers . compilerId ,
510504 } ;
511505 }
512- return filteredCubes ;
506+ return patchedCubes ;
513507 }
514508
515509 async metaConfigExtended ( requestContext , options ) {
516510 const compilers = await this . getCompilers ( options ) ;
517- const filteredCubes = await this . filterVisibilityByAccessPolicy (
511+ const patchedCubes = await this . patchVisibilityByAccessPolicy (
518512 compilers ,
519513 requestContext ,
520514 compilers . metaTransformer ?. cubes
521515 ) ;
522516 return {
523- metaConfig : filteredCubes ,
517+ metaConfig : patchedCubes ,
524518 cubeDefinitions : compilers . metaTransformer ?. cubeEvaluator ?. cubeDefinitions ,
525519 } ;
526520 }
0 commit comments