Skip to content

Commit f347c0a

Browse files
committed
feat: introduce groups support
1 parent 6275735 commit f347c0a

File tree

14 files changed

+188
-298
lines changed

14 files changed

+188
-298
lines changed

packages/cubejs-backend-native/js/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -527,6 +527,7 @@ export interface PyConfiguration {
527527
scheduledRefreshContexts?: (ctx: unknown) => Promise<string[]>
528528
scheduledRefreshTimeZones?: (ctx: unknown) => Promise<string[]>
529529
contextToRoles?: (ctx: unknown) => Promise<string[]>
530+
contextToGroups?: (ctx: unknown) => Promise<string[]>
530531
}
531532

532533
function simplifyExpressRequest(req: ExpressRequest) {

packages/cubejs-backend-native/python/cube/src/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ class Configuration:
7878
pre_aggregations_schema: Union[Callable[[RequestContext], str], str]
7979
orchestrator_options: Union[Dict, Callable[[RequestContext], Dict]]
8080
context_to_roles: Callable[[RequestContext], list[str]]
81+
context_to_groups: Callable[[RequestContext], list[str]]
8182
fast_reload: bool
8283

8384
def __init__(self):
@@ -128,6 +129,7 @@ def __init__(self):
128129
self.pre_aggregations_schema = None
129130
self.orchestrator_options = None
130131
self.context_to_roles = None
132+
self.context_to_groups = None
131133
self.fast_reload = None
132134

133135
def __call__(self, func):

packages/cubejs-backend-native/src/python/cube_config.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ impl CubeConfigPy {
5252
"context_to_orchestrator_id",
5353
"context_to_cube_store_router_id",
5454
"context_to_roles",
55+
"context_to_groups",
5556
"db_type",
5657
"driver_factory",
5758
"extend_context",

packages/cubejs-backend-native/test/__snapshots__/jinja.test.ts.snap

Lines changed: 0 additions & 294 deletions
This file was deleted.

packages/cubejs-backend-native/test/config.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,3 +106,13 @@ def context_to_roles(ctx):
106106
return [
107107
"admin",
108108
]
109+
110+
111+
@config
112+
def context_to_groups(ctx):
113+
print("[python] context_to_groups", ctx)
114+
115+
return [
116+
"dev",
117+
"analytics",
118+
]

packages/cubejs-backend-native/test/old-config.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,3 +78,15 @@ def logger(msg, params):
7878
print('[python] logger msg', msg, 'params=', params)
7979

8080
settings.logger = logger
81+
82+
def context_to_roles(ctx):
83+
print('[python] context_to_roles', ctx)
84+
return ['admin']
85+
86+
settings.context_to_roles = context_to_roles
87+
88+
def context_to_groups(ctx):
89+
print('[python] context_to_groups', ctx)
90+
return ['dev', 'analytics']
91+
92+
settings.context_to_groups = context_to_groups

packages/cubejs-backend-native/test/python.test.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ suite('Python Config', () => {
6969
repositoryFactory: expect.any(Function),
7070
schemaVersion: expect.any(Function),
7171
contextToRoles: expect.any(Function),
72+
contextToGroups: expect.any(Function),
7273
scheduledRefreshContexts: expect.any(Function),
7374
scheduledRefreshTimeZones: expect.any(Function),
7475
});
@@ -99,6 +100,14 @@ suite('Python Config', () => {
99100
expect(await config.contextToRoles({})).toEqual(['admin']);
100101
});
101102

103+
test('context_to_groups', async () => {
104+
if (!config.contextToGroups) {
105+
throw new Error('contextToGroups was not defined in config.py');
106+
}
107+
108+
expect(await config.contextToGroups({})).toEqual(['dev', 'analytics']);
109+
});
110+
102111
test('context_to_api_scopes', async () => {
103112
if (!config.contextToApiScopes) {
104113
throw new Error('contextToApiScopes was not defined in config.py');
@@ -243,6 +252,7 @@ darwinSuite('Old Python Config', () => {
243252
repositoryFactory: expect.any(Function),
244253
schemaVersion: expect.any(Function),
245254
contextToRoles: expect.any(Function),
255+
contextToGroups: expect.any(Function),
246256
scheduledRefreshContexts: expect.any(Function),
247257
scheduledRefreshTimeZones: expect.any(Function),
248258
});

packages/cubejs-schema-compiler/src/compiler/CubeSymbols.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,9 @@ export type Filter =
118118
};
119119

120120
export type AccessPolicyDefinition = {
121+
role?: string;
122+
group?: string;
123+
groups?: string[];
121124
rowLevel?: {
122125
filters: Filter[];
123126
};

0 commit comments

Comments
 (0)