Skip to content
Open
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
6 changes: 5 additions & 1 deletion schemas/json/layout/expression.schema.v1.json
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,11 @@
"type": "array",
"items": [
{ "const": "authContext" },
{ "enum": ["read", "write", "instantiate", "confirm", "sign", "reject"] }
{ "anyOf": [
{ "enum": ["read", "write", "instantiate", "confirm", "sign", "reject"] },
{ "type": "string" }
]}

],
"additionalItems": false
},
Expand Down
26 changes: 12 additions & 14 deletions src/features/expressions/expression-functions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import type {
} from 'src/features/expressions/types';
import type { ValidationContext } from 'src/features/expressions/validation';
import type { IDataModelReference } from 'src/layout/common.generated';
import type { IAuthContext, IInstanceDataSources } from 'src/types/shared';
import type { IInstanceDataSources } from 'src/types/shared';
import type { ExpressionDataSources } from 'src/utils/layout/useExpressionDataSources';

type ArgsToActual<T extends readonly AnyExprArg[]> = {
Expand Down Expand Up @@ -407,22 +407,20 @@ export const ExprFunctionImplementations: { [K in ExprFunctionName]: Implementat
return (this.dataSources.applicationSettings && this.dataSources.applicationSettings[key]) || null;
},
authContext(key) {
const authContextKeys: { [key in keyof IAuthContext]: true } = {
read: true,
write: true,
instantiate: true,
confirm: true,
sign: true,
reject: true,
complete: true,
};

if (key === null || authContextKeys[key] !== true) {
throw new ExprRuntimeError(this.expr, this.path, `Unknown auth context property ${key}`);
if (key === null) {
throw new ExprRuntimeError(this.expr, this.path, `Auth context key cannot be null`);
}

const authContext = buildAuthContext(this.dataSources.process?.currentTask);
return Boolean(authContext?.[key]);
const hasAction = authContext?.[key];
if (hasAction === undefined) {
throw new ExprRuntimeError(
this.expr,
this.path,
`Unknown Auth context property ${key} for task ${this.dataSources.process?.currentTask?.elementId} (allowed keys are {${Object.keys(authContext).join(', ')}})`,
);
}
return Boolean(hasAction);
},
component(id) {
if (id === null) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"name": "error unknown action",
"expression": ["authContext", "unknown_action"],
"expectsFailure": "Unknown Auth context property unknown_action for task Task_1",
"permissions": {
"read": true,
"write": false,
"actions": {
"instantiate": true,
"confirm": true,
"sign": false,
"reject": false,
"asdf":false
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@
"actions": {
"instantiate": true,
"confirm": false,
"sign": true
"sign": true,
"reject": false
}
}
}
Loading