|
1 | 1 | import crypto from 'crypto'; |
2 | 2 | import R from 'ramda'; |
| 3 | +import { getEnv } from '@cubejs-backend/shared'; |
3 | 4 | import { createQuery, compile, queryClass, PreAggregations, QueryFactory } from '@cubejs-backend/schema-compiler'; |
4 | 5 | import { v4 as uuidv4 } from 'uuid'; |
5 | 6 | import { NativeInstance } from '@cubejs-backend/native'; |
@@ -421,12 +422,10 @@ export class CompilerApi { |
421 | 422 | } |
422 | 423 |
|
423 | 424 | /** |
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. |
428 | 427 | */ |
429 | | - async filterVisibilityByAccessPolicy(compilers, context, cubes) { |
| 428 | + async patchVisibilityByAccessPolicy(compilers, context, cubes) { |
430 | 429 | const isMemberVisibleInContext = {}; |
431 | 430 | const { cubeEvaluator } = compilers; |
432 | 431 |
|
@@ -467,56 +466,55 @@ export class CompilerApi { |
467 | 466 | } |
468 | 467 | } |
469 | 468 |
|
470 | | - const visibilityFilterForCube = (cube) => { |
| 469 | + const visibilityPatcherForCube = (cube) => { |
471 | 470 | const evaluatedCube = cubeEvaluator.cubeFromPath(cube.config.name); |
472 | 471 | if (!cubeEvaluator.isRbacEnabledForCube(evaluatedCube)) { |
473 | | - return (item) => item.isVisible; |
| 472 | + return (item) => item; |
474 | 473 | } |
475 | | - return (item) => (item.isVisible && isMemberVisibleInContext[item.name] || false); |
| 474 | + return (item) => ({ |
| 475 | + ...item, |
| 476 | + isVisible: item.isVisible && isMemberVisibleInContext[item.name] |
| 477 | + }); |
476 | 478 | }; |
477 | 479 |
|
478 | 480 | return cubes |
479 | 481 | .map((cube) => ({ |
480 | 482 | config: { |
481 | 483 | ...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)), |
485 | 487 | }, |
486 | | - })).filter( |
487 | | - cube => cube.config.measures?.length || |
488 | | - cube.config.dimensions?.length || |
489 | | - cube.config.segments?.length |
490 | | - ); |
| 488 | + })); |
491 | 489 | } |
492 | 490 |
|
493 | 491 | async metaConfig(requestContext, options = {}) { |
494 | 492 | const { includeCompilerId, ...restOptions } = options; |
495 | 493 | const compilers = await this.getCompilers(restOptions); |
496 | 494 | const { cubes } = compilers.metaTransformer; |
497 | | - const filteredCubes = await this.filterVisibilityByAccessPolicy( |
| 495 | + const patchedCubes = await this.patchVisibilityByAccessPolicy( |
498 | 496 | compilers, |
499 | 497 | requestContext, |
500 | 498 | cubes |
501 | 499 | ); |
502 | 500 | if (includeCompilerId) { |
503 | 501 | return { |
504 | | - cubes: filteredCubes, |
| 502 | + cubes: patchedCubes, |
505 | 503 | compilerId: compilers.compilerId, |
506 | 504 | }; |
507 | 505 | } |
508 | | - return filteredCubes; |
| 506 | + return patchedCubes; |
509 | 507 | } |
510 | 508 |
|
511 | 509 | async metaConfigExtended(requestContext, options) { |
512 | 510 | const compilers = await this.getCompilers(options); |
513 | | - const filteredCubes = await this.filterVisibilityByAccessPolicy( |
| 511 | + const patchedCubes = await this.patchVisibilityByAccessPolicy( |
514 | 512 | compilers, |
515 | 513 | requestContext, |
516 | 514 | compilers.metaTransformer?.cubes |
517 | 515 | ); |
518 | 516 | return { |
519 | | - metaConfig: filteredCubes, |
| 517 | + metaConfig: patchedCubes, |
520 | 518 | cubeDefinitions: compilers.metaTransformer?.cubeEvaluator?.cubeDefinitions, |
521 | 519 | }; |
522 | 520 | } |
|
0 commit comments