Skip to content

Commit 8a796f8

Browse files
authored
chore!: Remove support for USER_CONTEXT (#8705)
BREAKING CHANGE: This functionality was deprecated starting from v0.26.0. Please migrate to SECURITY_CONTEXT.
1 parent 0f0ab9e commit 8a796f8

File tree

8 files changed

+97
-128
lines changed

8 files changed

+97
-128
lines changed

DEPRECATION.md

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ features:
4646
| Deprecated | [`checkAuthMiddleware`](#checkauthmiddleware) | v0.26.0 | v0.36.0 |
4747
| Removed | [Node.js 10](#nodejs-10) | v0.26.0 | v0.29.0 |
4848
| Removed | [Node.js 15](#nodejs-15) | v0.26.0 | v0.32.0 |
49-
| Deprecated | [`USER_CONTEXT`](#user_context) | v0.26.0 | v0.36.0 |
49+
| Removed | [`USER_CONTEXT`](#user_context) | v0.26.0 | v0.36.0 |
5050
| Deprecated | [`authInfo`](#authinfo) | v0.26.0 | |
5151
| Deprecated | [Prefix Redis environment variables with `CUBEJS_`](#prefix-redis-environment-variables-with-cubejs_) | v0.27.0 | v0.36.0 |
5252
| Removed | [Node.js 12](#nodejs-12) | v0.29.0 | v0.32.0 |
@@ -211,14 +211,6 @@ no more updates. Please upgrade to Node.js 12 or higher.
211211

212212
`USER_CONTEXT` has been renamed to `SECURITY_CONTEXT`.
213213

214-
Deprecated:
215-
216-
```js
217-
cube(`visitors`, {
218-
sql: `select * from visitors WHERE ${USER_CONTEXT.source.filter("source")}`,
219-
});
220-
```
221-
222214
You should use:
223215

224216
```js

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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ import { BaseQuery } from '../adapter';
99

1010
const FunctionRegex = /function\s+\w+\(([A-Za-z0-9_,]*)|\(([\s\S]*?)\)\s*=>|\(?(\w+)\)?\s*=>/;
1111
const CONTEXT_SYMBOLS = {
12-
USER_CONTEXT: 'securityContext',
1312
SECURITY_CONTEXT: 'securityContext',
1413
FILTER_PARAMS: 'filterParams',
1514
FILTER_GROUP: 'filterGroup',
@@ -495,6 +494,11 @@ export class CubeSymbols {
495494

496495
resolveSymbol(cubeName, name) {
497496
const { sqlResolveFn, contextSymbols, collectJoinHints } = this.resolveSymbolsCallContext || {};
497+
498+
if (name === 'USER_CONTEXT') {
499+
throw new Error('Support for USER_CONTEXT was removed, please migrate to SECURITY_CONTEXT.');
500+
}
501+
498502
if (CONTEXT_SYMBOLS[name]) {
499503
// always resolves if contextSymbols aren't passed for transpile step
500504
const symbol = contextSymbols && contextSymbols[CONTEXT_SYMBOLS[name]] || {};

packages/cubejs-schema-compiler/src/compiler/transpilers/ValidationTranspiler.ts

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,17 @@
1-
/* eslint-disable no-restricted-syntax */
2-
import { TranspilerInterface, TraverseObject } from './transpiler.interface';
3-
import { ErrorReporter } from '../ErrorReporter';
1+
import type { TranspilerInterface, TraverseObject } from './transpiler.interface';
2+
import type { ErrorReporter } from '../ErrorReporter';
43

5-
// @todo It's not possible to do a warning inside CubeSymbols.resolveSymbol,
6-
// because it doesnt have ErrorReporter, restructure?
74
export class ValidationTranspiler implements TranspilerInterface {
85
public traverseObject(reporter: ErrorReporter): TraverseObject {
96
return {
107
Identifier: path => {
118
if (path.node.name === 'USER_CONTEXT') {
12-
reporter.warning({
13-
message: 'USER_CONTEXT was deprecated in favor of SECURITY_CONTEXT.',
14-
loc: path.node.loc,
15-
});
9+
reporter.error(
10+
'Support for USER_CONTEXT was removed, please migrate to SECURITY_CONTEXT.',
11+
path.node.loc?.filename,
12+
path.node.loc?.start.line,
13+
path.node.loc?.start.column,
14+
);
1615
}
1716
}
1817
};

packages/cubejs-schema-compiler/test/integration/clickhouse/clickhouse-graph-builder.test.ts

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,13 @@ describe('ClickHouse JoinGraph', () => {
1818
type: 'number',
1919
sql: new Function('visitor_revenue', 'visitor_count', 'return visitor_revenue + "/" + visitor_count')
2020
}
21-
21+
2222
cube(\`visitors\`, {
2323
sql: \`
24-
select * from visitors WHERE \${USER_CONTEXT.source.filter('source')} AND
25-
\${USER_CONTEXT.sourceArray.filter(sourceArray => \`source in (\${sourceArray.join(',')})\`)}
24+
select * from visitors WHERE \${SECURITY_CONTEXT.source.filter('source')} AND
25+
\${SECURITY_CONTEXT.sourceArray.filter(sourceArray => \`source in (\${sourceArray.join(',')})\`)}
2626
\`,
27-
27+
2828
refreshKey: {
2929
sql: 'SELECT 1',
3030
},
@@ -113,24 +113,24 @@ describe('ClickHouse JoinGraph', () => {
113113
type: 'time',
114114
sql: 'created_at'
115115
},
116-
116+
117117
createdAtSqlUtils: {
118118
type: 'time',
119119
sql: SQL_UTILS.convertTz('created_at')
120120
},
121-
121+
122122
checkins: {
123123
sql: \`\${visitor_checkins.visitor_checkins_count}\`,
124124
type: \`number\`,
125125
subQuery: true
126126
},
127-
127+
128128
subQueryFail: {
129129
sql: '2',
130130
type: \`number\`,
131131
subQuery: true
132132
},
133-
133+
134134
doubledCheckings: {
135135
sql: \`\${checkins} * 2\`,
136136
type: 'number'
@@ -210,7 +210,7 @@ describe('ClickHouse JoinGraph', () => {
210210
subQuery: true
211211
},
212212
},
213-
213+
214214
// preAggregations: {
215215
// checkinSource: {
216216
// type: 'rollup',
@@ -255,27 +255,27 @@ describe('ClickHouse JoinGraph', () => {
255255
}
256256
}
257257
})
258-
258+
259259
cube('ReferenceVisitors', {
260260
sql: \`
261-
select * from \${visitors.sql()} as t
261+
select * from \${visitors.sql()} as t
262262
WHERE \${FILTER_PARAMS.ReferenceVisitors.createdAt.filter(\`addDays(t.created_at, 28)\`)} AND
263263
\${FILTER_PARAMS.ReferenceVisitors.createdAt.filter((from, to) => \`(addDays(t.created_at,28)) >= parseDateTimeBestEffort(\${from}) AND (addDays(t.created_at, 28)) <= parseDateTimeBestEffort(\${to})\`)}
264264
\`,
265-
265+
266266
measures: {
267267
count: {
268268
type: 'count'
269269
},
270-
270+
271271
googleSourcedCount: {
272272
type: 'count',
273273
filters: [{
274274
sql: \`\${CUBE}.source = 'google'\`
275275
}]
276276
},
277277
},
278-
278+
279279
dimensions: {
280280
createdAt: {
281281
type: 'time',

packages/cubejs-schema-compiler/test/integration/mssql/mssql-ungrouped.test.ts

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,15 @@ describe('MSSqlUngrouped', () => {
1616
type: 'number',
1717
sql: new Function('visitor_revenue', 'visitor_count', 'return visitor_revenue + "/" + visitor_count')
1818
}
19-
19+
2020
cube(\`visitors\`, {
2121
sql: \`
22-
select * from ##visitors WHERE \${USER_CONTEXT.source.filter('source')} AND
23-
\${USER_CONTEXT.sourceArray.filter(sourceArray => \`source in (\${sourceArray.join(',')})\`)}
22+
select * from ##visitors WHERE \${SECURITY_CONTEXT.source.filter('source')} AND
23+
\${SECURITY_CONTEXT.sourceArray.filter(sourceArray => \`source in (\${sourceArray.join(',')})\`)}
2424
\`,
25-
25+
2626
rewriteQueries: true,
27-
27+
2828
refreshKey: {
2929
sql: 'SELECT 1',
3030
},
@@ -122,37 +122,37 @@ describe('MSSqlUngrouped', () => {
122122
type: 'time',
123123
sql: 'created_at'
124124
},
125-
125+
126126
createdAtSqlUtils: {
127127
type: 'time',
128128
sql: SQL_UTILS.convertTz('created_at')
129129
},
130-
130+
131131
checkins: {
132132
sql: \`\${visitor_checkins.visitor_checkins_count}\`,
133133
type: \`number\`,
134134
subQuery: true
135135
},
136-
136+
137137
checkinsRolling: {
138138
sql: \`\${visitor_checkins.visitorCheckinsRolling}\`,
139139
type: \`number\`,
140140
subQuery: true
141141
},
142-
142+
143143
checkinsWithPropagation: {
144144
sql: \`\${visitor_checkins.visitor_checkins_count}\`,
145145
type: \`number\`,
146146
subQuery: true,
147147
propagateFiltersToSubQuery: true
148148
},
149-
149+
150150
subQueryFail: {
151151
sql: '2',
152152
type: \`number\`,
153153
subQuery: true
154154
},
155-
155+
156156
doubledCheckings: {
157157
sql: \`\${checkins} * 2\`,
158158
type: 'number'
@@ -181,11 +181,11 @@ describe('MSSqlUngrouped', () => {
181181
182182
cube('visitor_checkins', {
183183
sql: \`
184-
select * from ##visitor_checkins WHERE
184+
select * from ##visitor_checkins WHERE
185185
\${FILTER_PARAMS.visitor_checkins.created_at.filter('created_at')} AND
186186
\${FILTER_GROUP(FILTER_PARAMS.visitor_checkins.created_at.filter("dateadd(day, -3, created_at)"), FILTER_PARAMS.visitor_checkins.source.filter('source'))}
187187
\`,
188-
188+
189189
rewriteQueries: true,
190190
191191
joins: {
@@ -199,14 +199,14 @@ describe('MSSqlUngrouped', () => {
199199
visitor_checkins_count: {
200200
type: 'count'
201201
},
202-
202+
203203
visitorCheckinsRolling: {
204204
type: 'count',
205205
rollingWindow: {
206206
trailing: 'unbounded'
207207
}
208208
},
209-
209+
210210
revenue_per_checkin: {
211211
type: 'number',
212212
sql: \`\${visitors.visitor_revenue} / \${visitor_checkins_count}\`
@@ -259,7 +259,7 @@ describe('MSSqlUngrouped', () => {
259259
subQuery: true
260260
},
261261
},
262-
262+
263263
preAggregations: {
264264
checkinSource: {
265265
type: 'rollup',
@@ -331,9 +331,9 @@ describe('MSSqlUngrouped', () => {
331331
}
332332
}
333333
})
334-
335-
336-
334+
335+
336+
337337
`);
338338

339339
async function runQueryTest(q, expectedResult) {

0 commit comments

Comments
 (0)