Skip to content

Commit

Permalink
feat(user-task-form): validate formId with Camunda 8.3 and newer
Browse files Browse the repository at this point in the history
  • Loading branch information
philippfromme committed Nov 1, 2023
1 parent b13a564 commit ae4dfa5
Show file tree
Hide file tree
Showing 2 changed files with 133 additions and 8 deletions.
51 changes: 43 additions & 8 deletions rules/camunda-cloud/user-task-form.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -49,7 +80,7 @@ module.exports = skipInNonExecutableProcess(function() {
}
}, node);

if (errors && errors.length) {
if (errors.length) {
reportErrors(node, reporter, errors);
}
}
Expand Down Expand Up @@ -77,4 +108,8 @@ function findUserTaskForm(node, formKey) {
return `camunda-forms:bpmn:${ id }` === formKey;
});
}
}

function isFormIdAllowed(version) {
return greaterOrEqual(version, formIdAllowedVersion);
}
90 changes: 90 additions & 0 deletions test/camunda-cloud/user-task-form.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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(`
<bpmn:extensionElements>
<zeebe:userTaskForm id="userTaskForm_1">{}</zeebe:userTaskForm>
Expand All @@ -26,6 +27,7 @@ const valid = [
},
{
name: 'user task',
config: { version: '8.2' },
moddleElement: createModdle(createProcess(`
<bpmn:userTask id="UserTask_1" />
`))
Expand All @@ -48,6 +50,7 @@ const valid = [
const invalid = [
{
name: 'user task (no form key)',
config: { version: '8.2' },
moddleElement: createModdle(createProcess(`
<bpmn:userTask id="UserTask_1">
<bpmn:extensionElements>
Expand All @@ -72,8 +75,95 @@ const invalid = [
}
}
},
{
name: 'user task (no form key or form ID)',
config: { version: '8.3' },
moddleElement: createModdle(createProcess(`
<bpmn:userTask id="UserTask_1">
<bpmn:extensionElements>
<zeebe:formDefinition />
</bpmn:extensionElements>
</bpmn:userTask>
`)),
report: {
id: 'UserTask_1',
message: 'Element of type <zeebe:FormDefinition> must have property <formKey> or <formId>',
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(`
<bpmn:userTask id="UserTask_1">
<bpmn:extensionElements>
<zeebe:formDefinition formId="foo" />
</bpmn:extensionElements>
</bpmn:userTask>
`)),
report: {
id: 'UserTask_1',
message: 'Property <formId> 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(`
<bpmn:userTask id="UserTask_1">
<bpmn:extensionElements>
<zeebe:formDefinition formKey="foo" formId="bar" />
</bpmn:extensionElements>
</bpmn:userTask>
`)),
report: {
id: 'UserTask_1',
message: 'Element of type <zeebe:FormDefinition> must have property <formKey> or <formId>',
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(`
<bpmn:extensionElements>
<zeebe:userTaskForm id="userTaskForm_1"></zeebe:userTaskForm>
Expand Down

0 comments on commit ae4dfa5

Please sign in to comment.