diff --git a/schemas/json/layout/expression.schema.v1.json b/schemas/json/layout/expression.schema.v1.json index 1fe72c015a..2dd61724fc 100644 --- a/schemas/json/layout/expression.schema.v1.json +++ b/schemas/json/layout/expression.schema.v1.json @@ -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 }, diff --git a/src/features/expressions/expression-functions.ts b/src/features/expressions/expression-functions.ts index c5bd4b424a..39174725d5 100644 --- a/src/features/expressions/expression-functions.ts +++ b/src/features/expressions/expression-functions.ts @@ -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 = { @@ -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) { diff --git a/src/features/expressions/shared-tests/functions/authContext/error-unknown-action.json b/src/features/expressions/shared-tests/functions/authContext/error-unknown-action.json new file mode 100644 index 0000000000..1e935209a0 --- /dev/null +++ b/src/features/expressions/shared-tests/functions/authContext/error-unknown-action.json @@ -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 + } + } +} diff --git a/src/features/expressions/shared-tests/functions/authContext/read-sign.json b/src/features/expressions/shared-tests/functions/authContext/read-sign.json index a674b8a053..31dbba3b66 100644 --- a/src/features/expressions/shared-tests/functions/authContext/read-sign.json +++ b/src/features/expressions/shared-tests/functions/authContext/read-sign.json @@ -14,7 +14,8 @@ "actions": { "instantiate": true, "confirm": false, - "sign": true + "sign": true, + "reject": false } } }