From ae4dfa55893ca88476029e0ad492057c3fb5c06d Mon Sep 17 00:00:00 2001 From: Philipp Date: Wed, 1 Nov 2023 15:04:39 +0100 Subject: [PATCH] feat(user-task-form): validate `formId` with Camunda 8.3 and newer Closes #144 Related to https://github.com/camunda/camunda-modeler/issues/3656 --- rules/camunda-cloud/user-task-form.js | 51 +++++++++++-- test/camunda-cloud/user-task-form.spec.js | 90 +++++++++++++++++++++++ 2 files changed, 133 insertions(+), 8 deletions(-) diff --git a/rules/camunda-cloud/user-task-form.js b/rules/camunda-cloud/user-task-form.js index ab368356..30c588ca 100644 --- a/rules/camunda-cloud/user-task-form.js +++ b/rules/camunda-cloud/user-task-form.js @@ -4,14 +4,19 @@ const { findExtensionElement, findExtensionElements, findParent, - hasProperties + hasProperties, + hasProperty } = require('../utils/element'); const { reportErrors } = require('../utils/reporter'); const { skipInNonExecutableProcess } = require('../utils/rule'); -module.exports = skipInNonExecutableProcess(function() { +const { greaterOrEqual } = require('../utils/version'); + +const formIdAllowedVersion = '8.3'; + +module.exports = skipInNonExecutableProcess(function({ version }) { function check(node, reporter) { if (!is(node, 'bpmn:UserTask')) { return; @@ -23,13 +28,39 @@ module.exports = skipInNonExecutableProcess(function() { return; } - let errors = hasProperties(formDefinition, { - formKey: { - required: true + let errors = []; + + if (isFormIdAllowed(version)) { + + // Camunda 8.3 and newer + errors = hasProperty(formDefinition, [ + 'formKey', + 'formId' + ], node); + } else { + + // Camunda 8.2 and older + errors = hasProperties(formDefinition, { + formId: { + allowed: false, + allowedVersion: formIdAllowedVersion + } + }, node); + + if (errors.length) { + reportErrors(node, reporter, errors); + + return; } - }, node); - if (errors && errors.length) { + errors = hasProperties(formDefinition, { + formKey: { + required: true + } + }, node); + } + + if (errors.length) { reportErrors(node, reporter, errors); return; @@ -49,7 +80,7 @@ module.exports = skipInNonExecutableProcess(function() { } }, node); - if (errors && errors.length) { + if (errors.length) { reportErrors(node, reporter, errors); } } @@ -77,4 +108,8 @@ function findUserTaskForm(node, formKey) { return `camunda-forms:bpmn:${ id }` === formKey; }); } +} + +function isFormIdAllowed(version) { + return greaterOrEqual(version, formIdAllowedVersion); } \ No newline at end of file diff --git a/test/camunda-cloud/user-task-form.spec.js b/test/camunda-cloud/user-task-form.spec.js index f6600b23..5a81abfe 100644 --- a/test/camunda-cloud/user-task-form.spec.js +++ b/test/camunda-cloud/user-task-form.spec.js @@ -13,6 +13,7 @@ const { ERROR_TYPES } = require('../../rules/utils/element'); const valid = [ { name: 'user task (user task form)', + config: { version: '8.2' }, moddleElement: createModdle(createProcess(` {} @@ -26,6 +27,7 @@ const valid = [ }, { name: 'user task', + config: { version: '8.2' }, moddleElement: createModdle(createProcess(` `)) @@ -48,6 +50,7 @@ const valid = [ const invalid = [ { name: 'user task (no form key)', + config: { version: '8.2' }, moddleElement: createModdle(createProcess(` @@ -72,8 +75,95 @@ const invalid = [ } } }, + { + name: 'user task (no form key or form ID)', + config: { version: '8.3' }, + moddleElement: createModdle(createProcess(` + + + + + + `)), + report: { + id: 'UserTask_1', + message: 'Element of type must have property or ', + path: [ + 'extensionElements', + 'values', + 0 + ], + data: { + type: ERROR_TYPES.PROPERTY_REQUIRED, + node: 'zeebe:FormDefinition', + parentNode: 'UserTask_1', + requiredProperty: [ + 'formKey', + 'formId' + ] + } + } + }, + { + name: 'user task (form ID with Camunda 8.2)', + config: { version: '8.2' }, + moddleElement: createModdle(createProcess(` + + + + + + `)), + report: { + id: 'UserTask_1', + message: 'Property only allowed by Camunda 8.3 or newer', + path: [ + 'extensionElements', + 'values', + 0, + 'formId' + ], + data: { + type: ERROR_TYPES.PROPERTY_NOT_ALLOWED, + node: 'zeebe:FormDefinition', + parentNode: 'UserTask_1', + property: 'formId', + allowedVersion: '8.3' + } + } + }, + { + name: 'user task (form key and form ID)', + config: { version: '8.3' }, + moddleElement: createModdle(createProcess(` + + + + + + `)), + report: { + id: 'UserTask_1', + message: 'Element of type must have property or ', + path: [ + 'extensionElements', + 'values', + 0 + ], + data: { + type: ERROR_TYPES.PROPERTY_REQUIRED, + node: 'zeebe:FormDefinition', + parentNode: 'UserTask_1', + requiredProperty: [ + 'formKey', + 'formId' + ] + } + } + }, { name: 'user task (empty user task form)', + config: { version: '8.2' }, moddleElement: createModdle(createProcess(`