-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(schema-compiler): make sure view members are resolvable in DAP (#…
- Loading branch information
Showing
10 changed files
with
244 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
30 changes: 30 additions & 0 deletions
30
packages/cubejs-schema-compiler/src/compiler/ViewCompilationGate.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
export class ViewCompilationGate { | ||
private shouldCompile: any; | ||
|
||
public constructor() { | ||
this.shouldCompile = false; | ||
} | ||
|
||
public compile(cubes: any[]) { | ||
// When developing Data Access Policies feature, we've came across a | ||
// limitation that Cube members can't be referenced in access policies defined on Views, | ||
// because views aren't (yet) compiled at the time of access policy evaluation. | ||
// To workaround this limitation and additional compilation pass is necessary, | ||
// however it comes with a significant performance penalty. | ||
// This gate check whether the data model contains views with access policies, | ||
// and only then allows the additional compilation pass. | ||
// | ||
// Check out the DataSchemaCompiler.ts to see how this gate is used. | ||
if (this.viewsHaveAccessPolicies(cubes)) { | ||
this.shouldCompile = true; | ||
} | ||
} | ||
|
||
private viewsHaveAccessPolicies(cubes: any[]) { | ||
return cubes.some(c => c.isView && c.accessPolicy); | ||
} | ||
|
||
public shouldCompileViews() { | ||
return this.shouldCompile; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
13 changes: 13 additions & 0 deletions
13
packages/cubejs-testing/birdbox-fixtures/rbac-python/model/views/users_view.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
views: | ||
- name: users_view | ||
cubes: | ||
- join_path: users | ||
includes: "*" | ||
|
||
access_policy: | ||
- role: '*' | ||
row_level: | ||
filters: | ||
- member: id | ||
operator: gt | ||
values: [10] |
16 changes: 16 additions & 0 deletions
16
packages/cubejs-testing/birdbox-fixtures/rbac/model/views/users.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
view('users_view', { | ||
cubes: [{ | ||
join_path: users, | ||
includes: '*', | ||
}], | ||
accessPolicy: [{ | ||
role: '*', | ||
rowLevel: { | ||
filters: [{ | ||
member: 'id', | ||
operator: 'gt', | ||
values: [10], | ||
}], | ||
}, | ||
}] | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters