Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore!: Remove support for USER_CONTEXT #8705

Merged
merged 2 commits into from
Sep 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 1 addition & 9 deletions DEPRECATION.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ features:
| Deprecated | [`checkAuthMiddleware`](#checkauthmiddleware) | v0.26.0 | v0.36.0 |
| Removed | [Node.js 10](#nodejs-10) | v0.26.0 | v0.29.0 |
| Removed | [Node.js 15](#nodejs-15) | v0.26.0 | v0.32.0 |
| Deprecated | [`USER_CONTEXT`](#user_context) | v0.26.0 | v0.36.0 |
| Removed | [`USER_CONTEXT`](#user_context) | v0.26.0 | v0.36.0 |
| Deprecated | [`authInfo`](#authinfo) | v0.26.0 | |
| Deprecated | [Prefix Redis environment variables with `CUBEJS_`](#prefix-redis-environment-variables-with-cubejs_) | v0.27.0 | v0.36.0 |
| Removed | [Node.js 12](#nodejs-12) | v0.29.0 | v0.32.0 |
Expand Down Expand Up @@ -211,14 +211,6 @@ no more updates. Please upgrade to Node.js 12 or higher.

`USER_CONTEXT` has been renamed to `SECURITY_CONTEXT`.

Deprecated:

```js
cube(`visitors`, {
sql: `select * from visitors WHERE ${USER_CONTEXT.source.filter("source")}`,
});
```

You should use:

```js
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import { BaseQuery } from '../adapter';

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

resolveSymbol(cubeName, name) {
const { sqlResolveFn, contextSymbols, collectJoinHints } = this.resolveSymbolsCallContext || {};

if (name === 'USER_CONTEXT') {
throw new Error('Support for USER_CONTEXT was removed, please migrate to SECURITY_CONTEXT.');
}

if (CONTEXT_SYMBOLS[name]) {
// always resolves if contextSymbols aren't passed for transpile step
const symbol = contextSymbols && contextSymbols[CONTEXT_SYMBOLS[name]] || {};
Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,17 @@
/* eslint-disable no-restricted-syntax */
import { TranspilerInterface, TraverseObject } from './transpiler.interface';
import { ErrorReporter } from '../ErrorReporter';
import type { TranspilerInterface, TraverseObject } from './transpiler.interface';
import type { ErrorReporter } from '../ErrorReporter';

// @todo It's not possible to do a warning inside CubeSymbols.resolveSymbol,
// because it doesnt have ErrorReporter, restructure?
export class ValidationTranspiler implements TranspilerInterface {
public traverseObject(reporter: ErrorReporter): TraverseObject {
return {
Identifier: path => {
if (path.node.name === 'USER_CONTEXT') {
reporter.warning({
message: 'USER_CONTEXT was deprecated in favor of SECURITY_CONTEXT.',
loc: path.node.loc,
});
reporter.error(
'Support for USER_CONTEXT was removed, please migrate to SECURITY_CONTEXT.',
path.node.loc?.filename,
path.node.loc?.start.line,
path.node.loc?.start.column,
);
}
}
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,13 @@ describe('ClickHouse JoinGraph', () => {
type: 'number',
sql: new Function('visitor_revenue', 'visitor_count', 'return visitor_revenue + "/" + visitor_count')
}

cube(\`visitors\`, {
sql: \`
select * from visitors WHERE \${USER_CONTEXT.source.filter('source')} AND
\${USER_CONTEXT.sourceArray.filter(sourceArray => \`source in (\${sourceArray.join(',')})\`)}
select * from visitors WHERE \${SECURITY_CONTEXT.source.filter('source')} AND
\${SECURITY_CONTEXT.sourceArray.filter(sourceArray => \`source in (\${sourceArray.join(',')})\`)}
\`,

refreshKey: {
sql: 'SELECT 1',
},
Expand Down Expand Up @@ -113,24 +113,24 @@ describe('ClickHouse JoinGraph', () => {
type: 'time',
sql: 'created_at'
},

createdAtSqlUtils: {
type: 'time',
sql: SQL_UTILS.convertTz('created_at')
},

checkins: {
sql: \`\${visitor_checkins.visitor_checkins_count}\`,
type: \`number\`,
subQuery: true
},

subQueryFail: {
sql: '2',
type: \`number\`,
subQuery: true
},

doubledCheckings: {
sql: \`\${checkins} * 2\`,
type: 'number'
Expand Down Expand Up @@ -210,7 +210,7 @@ describe('ClickHouse JoinGraph', () => {
subQuery: true
},
},

// preAggregations: {
// checkinSource: {
// type: 'rollup',
Expand Down Expand Up @@ -255,27 +255,27 @@ describe('ClickHouse JoinGraph', () => {
}
}
})

cube('ReferenceVisitors', {
sql: \`
select * from \${visitors.sql()} as t
select * from \${visitors.sql()} as t
WHERE \${FILTER_PARAMS.ReferenceVisitors.createdAt.filter(\`addDays(t.created_at, 28)\`)} AND
\${FILTER_PARAMS.ReferenceVisitors.createdAt.filter((from, to) => \`(addDays(t.created_at,28)) >= parseDateTimeBestEffort(\${from}) AND (addDays(t.created_at, 28)) <= parseDateTimeBestEffort(\${to})\`)}
\`,

measures: {
count: {
type: 'count'
},

googleSourcedCount: {
type: 'count',
filters: [{
sql: \`\${CUBE}.source = 'google'\`
}]
},
},

dimensions: {
createdAt: {
type: 'time',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,15 @@ describe('MSSqlUngrouped', () => {
type: 'number',
sql: new Function('visitor_revenue', 'visitor_count', 'return visitor_revenue + "/" + visitor_count')
}

cube(\`visitors\`, {
sql: \`
select * from ##visitors WHERE \${USER_CONTEXT.source.filter('source')} AND
\${USER_CONTEXT.sourceArray.filter(sourceArray => \`source in (\${sourceArray.join(',')})\`)}
select * from ##visitors WHERE \${SECURITY_CONTEXT.source.filter('source')} AND
\${SECURITY_CONTEXT.sourceArray.filter(sourceArray => \`source in (\${sourceArray.join(',')})\`)}
\`,

rewriteQueries: true,

refreshKey: {
sql: 'SELECT 1',
},
Expand Down Expand Up @@ -122,37 +122,37 @@ describe('MSSqlUngrouped', () => {
type: 'time',
sql: 'created_at'
},

createdAtSqlUtils: {
type: 'time',
sql: SQL_UTILS.convertTz('created_at')
},

checkins: {
sql: \`\${visitor_checkins.visitor_checkins_count}\`,
type: \`number\`,
subQuery: true
},

checkinsRolling: {
sql: \`\${visitor_checkins.visitorCheckinsRolling}\`,
type: \`number\`,
subQuery: true
},

checkinsWithPropagation: {
sql: \`\${visitor_checkins.visitor_checkins_count}\`,
type: \`number\`,
subQuery: true,
propagateFiltersToSubQuery: true
},

subQueryFail: {
sql: '2',
type: \`number\`,
subQuery: true
},

doubledCheckings: {
sql: \`\${checkins} * 2\`,
type: 'number'
Expand Down Expand Up @@ -181,11 +181,11 @@ describe('MSSqlUngrouped', () => {

cube('visitor_checkins', {
sql: \`
select * from ##visitor_checkins WHERE
select * from ##visitor_checkins WHERE
\${FILTER_PARAMS.visitor_checkins.created_at.filter('created_at')} AND
\${FILTER_GROUP(FILTER_PARAMS.visitor_checkins.created_at.filter("dateadd(day, -3, created_at)"), FILTER_PARAMS.visitor_checkins.source.filter('source'))}
\`,

rewriteQueries: true,

joins: {
Expand All @@ -199,14 +199,14 @@ describe('MSSqlUngrouped', () => {
visitor_checkins_count: {
type: 'count'
},

visitorCheckinsRolling: {
type: 'count',
rollingWindow: {
trailing: 'unbounded'
}
},

revenue_per_checkin: {
type: 'number',
sql: \`\${visitors.visitor_revenue} / \${visitor_checkins_count}\`
Expand Down Expand Up @@ -259,7 +259,7 @@ describe('MSSqlUngrouped', () => {
subQuery: true
},
},

preAggregations: {
checkinSource: {
type: 'rollup',
Expand Down Expand Up @@ -331,9 +331,9 @@ describe('MSSqlUngrouped', () => {
}
}
})



`);

async function runQueryTest(q, expectedResult) {
Expand Down
Loading
Loading