Skip to content

Commit

Permalink
feat: handle missing form property for Zeebe User Task
Browse files Browse the repository at this point in the history
  • Loading branch information
barmac committed Feb 27, 2024
1 parent 9e3ae13 commit 6ea1f8d
Show file tree
Hide file tree
Showing 5 changed files with 159 additions and 23 deletions.
41 changes: 23 additions & 18 deletions lib/compiled-config.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ const rules = {
"camunda-compat/no-task-schedule": "error",
"camunda-compat/no-template": "error",
"camunda-compat/no-zeebe-properties": "error",
"camunda-compat/no-zeebe-user-task": "error",
"camunda-compat/secrets": "warn",
"camunda-compat/sequence-flow-condition": "error",
"camunda-compat/signal-reference": "error",
Expand Down Expand Up @@ -178,38 +179,42 @@ import rule_24 from 'bpmnlint-plugin-camunda-compat/rules/camunda-cloud/no-zeebe

cache['bpmnlint-plugin-camunda-compat/no-zeebe-properties'] = rule_24;

import rule_25 from 'bpmnlint-plugin-camunda-compat/rules/camunda-cloud/secrets';
import rule_25 from 'bpmnlint-plugin-camunda-compat/rules/camunda-cloud/no-zeebe-user-task';

cache['bpmnlint-plugin-camunda-compat/secrets'] = rule_25;
cache['bpmnlint-plugin-camunda-compat/no-zeebe-user-task'] = rule_25;

import rule_26 from 'bpmnlint-plugin-camunda-compat/rules/camunda-cloud/sequence-flow-condition';
import rule_26 from 'bpmnlint-plugin-camunda-compat/rules/camunda-cloud/secrets';

cache['bpmnlint-plugin-camunda-compat/sequence-flow-condition'] = rule_26;
cache['bpmnlint-plugin-camunda-compat/secrets'] = rule_26;

import rule_27 from 'bpmnlint-plugin-camunda-compat/rules/camunda-cloud/signal-reference';
import rule_27 from 'bpmnlint-plugin-camunda-compat/rules/camunda-cloud/sequence-flow-condition';

cache['bpmnlint-plugin-camunda-compat/signal-reference'] = rule_27;
cache['bpmnlint-plugin-camunda-compat/sequence-flow-condition'] = rule_27;

import rule_28 from 'bpmnlint-plugin-camunda-compat/rules/camunda-cloud/start-event-form';
import rule_28 from 'bpmnlint-plugin-camunda-compat/rules/camunda-cloud/signal-reference';

cache['bpmnlint-plugin-camunda-compat/start-event-form'] = rule_28;
cache['bpmnlint-plugin-camunda-compat/signal-reference'] = rule_28;

import rule_29 from 'bpmnlint-plugin-camunda-compat/rules/camunda-cloud/subscription';
import rule_29 from 'bpmnlint-plugin-camunda-compat/rules/camunda-cloud/start-event-form';

cache['bpmnlint-plugin-camunda-compat/subscription'] = rule_29;
cache['bpmnlint-plugin-camunda-compat/start-event-form'] = rule_29;

import rule_30 from 'bpmnlint-plugin-camunda-compat/rules/camunda-cloud/task-schedule';
import rule_30 from 'bpmnlint-plugin-camunda-compat/rules/camunda-cloud/subscription';

cache['bpmnlint-plugin-camunda-compat/task-schedule'] = rule_30;
cache['bpmnlint-plugin-camunda-compat/subscription'] = rule_30;

import rule_31 from 'bpmnlint-plugin-camunda-compat/rules/camunda-cloud/timer';
import rule_31 from 'bpmnlint-plugin-camunda-compat/rules/camunda-cloud/task-schedule';

cache['bpmnlint-plugin-camunda-compat/timer'] = rule_31;
cache['bpmnlint-plugin-camunda-compat/task-schedule'] = rule_31;

import rule_32 from 'bpmnlint-plugin-camunda-compat/rules/camunda-cloud/user-task-definition';
import rule_32 from 'bpmnlint-plugin-camunda-compat/rules/camunda-cloud/timer';

cache['bpmnlint-plugin-camunda-compat/user-task-definition'] = rule_32;
cache['bpmnlint-plugin-camunda-compat/timer'] = rule_32;

import rule_33 from 'bpmnlint-plugin-camunda-compat/rules/camunda-cloud/user-task-form';
import rule_33 from 'bpmnlint-plugin-camunda-compat/rules/camunda-cloud/user-task-definition';

cache['bpmnlint-plugin-camunda-compat/user-task-form'] = rule_33;
cache['bpmnlint-plugin-camunda-compat/user-task-definition'] = rule_33;

import rule_34 from 'bpmnlint-plugin-camunda-compat/rules/camunda-cloud/user-task-form';

cache['bpmnlint-plugin-camunda-compat/user-task-form'] = rule_34;
17 changes: 16 additions & 1 deletion lib/utils/error-messages.js
Original file line number Diff line number Diff line change
Expand Up @@ -500,6 +500,15 @@ function getPropertyRequiredErrorMessage(report, executionPlatform, executionPla
return `${ getIndefiniteArticle(typeString) } <${ typeString }> with <Form type: Custom form key> must have a defined <Form key>`;
}

// Zeebe User Task
if (is(node, 'zeebe:FormDefinition') && isZeebeUserTask(parentNode)) {
if (isEmptyString(node.get('externalReference'))) {
return `${ getIndefiniteArticle(typeString) } <${ typeString }> with <Form type: External reference> must have a defined <External reference>`;
} else if (isEmptyString(node.get('formId'))) {
return `${ getIndefiniteArticle(typeString) } <${ typeString }> with <Form type: Camunda Form> must have a defined <Form ID>`;
}
}

if (is(node, 'zeebe:FormDefinition') && isArray(requiredProperty) && requiredProperty.includes('formId') && isEmptyString(node.get('formId'))) {
return `${ getIndefiniteArticle(typeString) } <${ typeString }> with <Form type: Camunda form (linked)> must have a defined <Form ID>`;
}
Expand Down Expand Up @@ -693,4 +702,10 @@ function getLoopNotAllowedErrorMessage(report) {

function isEmptyString(value) {
return isString(value) && value.trim() === '';
}
}

function isZeebeUserTask(node) {
return node.get('extensionElements').get('values').some(extensionElement => {
return is(extensionElement, 'zeebe:UserTask');
});
}
16 changes: 12 additions & 4 deletions lib/utils/properties-panel.js
Original file line number Diff line number Diff line change
Expand Up @@ -168,10 +168,14 @@ export function getEntryIds(report) {
requiredProperty
} = data;

if (isArray(requiredProperty) && requiredProperty.includes('formKey') && isEmptyString(node.get('formKey'))) {
return [ 'customFormKey' ];
} else if (isArray(requiredProperty) && requiredProperty.includes('formId') && isEmptyString(node.get('formId'))) {
return [ 'formId' ];
if (isArray(requiredProperty)) {
if (requiredProperty.includes('formKey') && isEmptyString(node.get('formKey'))) {
return [ 'customFormKey' ];
} else if (requiredProperty.includes('formId') && isEmptyString(node.get('formId'))) {
return [ 'formId' ];
} else if (requiredProperty.includes('externalReference') && isEmptyString(node.get('externalReference'))) {
return [ 'externalReference' ];
}
}
}

Expand Down Expand Up @@ -424,6 +428,10 @@ export function getErrorMessage(id, report) {
}
}

if (id === 'externalReference') {
return 'External reference must be defined.';
}

if (id === 'formConfiguration') {
return 'Form JSON configuration must be defined.';
}
Expand Down
52 changes: 52 additions & 0 deletions test/spec/utils/error-messages.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -1243,6 +1243,32 @@ describe('utils/error-messages', function() {
});


it('should adjust (Zeebe User Task) (form ID) (Camunda 8.5 and newer)', async function() {

// given
const node = createElement('bpmn:UserTask', {
extensionElements: createElement('bpmn:ExtensionElements', {
values: [
createElement('zeebe:UserTask', {}),
createElement('zeebe:FormDefinition', {
formId: ''
})
]
})
});

const { default: rule } = await import('bpmnlint-plugin-camunda-compat/rules/camunda-cloud/user-task-form');

const report = await getLintError(node, rule, { version: '8.5' });

// when
const errorMessage = getErrorMessage(report);

// then
expect(errorMessage).to.equal('A <User Task> with <Form type: Camunda Form> must have a defined <Form ID>');
});


it('should adjust (body)', async function() {

// given
Expand Down Expand Up @@ -1281,6 +1307,32 @@ describe('utils/error-messages', function() {
});


it('should adjust (Zeebe User Task) (external reference) (Camunda 8.5 and newer)', async function() {

// given
const node = createElement('bpmn:UserTask', {
extensionElements: createElement('bpmn:ExtensionElements', {
values: [
createElement('zeebe:UserTask', {}),
createElement('zeebe:FormDefinition', {
externalReference: ''
})
]
})
});

const { default: rule } = await import('bpmnlint-plugin-camunda-compat/rules/camunda-cloud/user-task-form');

const report = await getLintError(node, rule, { version: '8.5' });

// when
const errorMessage = getErrorMessage(report);

// then
expect(errorMessage).to.equal('A <User Task> with <Form type: External reference> must have a defined <External reference>');
});


it('should adjust (condition expression)', async function() {

// given
Expand Down
56 changes: 56 additions & 0 deletions test/spec/utils/properties-panel.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -900,6 +900,62 @@ describe('utils/properties-panel', function() {
});


it('user-task-form (Zeebe User Task) - Form ID (Camunda 8.5 and newer)', async function() {

// given
const node = createElement('bpmn:UserTask', {
extensionElements: createElement('bpmn:ExtensionElements', {
values: [
createElement('zeebe:UserTask'),
createElement('zeebe:FormDefinition', {
formId: ''
})
]
})
});

const { default: rule } = await import('bpmnlint-plugin-camunda-compat/rules/camunda-cloud/user-task-form');

const report = await getLintError(node, rule, { version: '8.5' });

// when
const entryIds = getEntryIds(report);

// then
expect(entryIds).to.eql([ 'formId' ]);

expectErrorMessage(entryIds[ 0 ], 'Form ID must be defined.', report);
});


it('user-task-form (Zeebe User Task) - External reference (Camunda 8.5 and newer)', async function() {

// given
const node = createElement('bpmn:UserTask', {
extensionElements: createElement('bpmn:ExtensionElements', {
values: [
createElement('zeebe:UserTask'),
createElement('zeebe:FormDefinition', {
externalReference: ''
})
]
})
});

const { default: rule } = await import('bpmnlint-plugin-camunda-compat/rules/camunda-cloud/user-task-form');

const report = await getLintError(node, rule, { version: '8.5' });

// when
const entryIds = getEntryIds(report);

// then
expect(entryIds).to.eql([ 'externalReference' ]);

expectErrorMessage(entryIds[ 0 ], 'External reference must be defined.', report);
});


it('user-task-form - Form JSON configuration', async function() {

// given
Expand Down

0 comments on commit 6ea1f8d

Please sign in to comment.