Skip to content

Commit

Permalink
fix(copy-paste): do not copy message flows without participant
Browse files Browse the repository at this point in the history
Closes #1902
  • Loading branch information
philippfromme committed May 4, 2023
1 parent 22d59fd commit ecf232c
Show file tree
Hide file tree
Showing 4 changed files with 63 additions and 12 deletions.
2 changes: 2 additions & 0 deletions lib/features/copy-paste/BpmnCopyPaste.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ import {

import { isLabel } from '../../util/LabelUtil';

import { getParent } from '../modeling/util/ModelingUtil';

/**
* @typedef {import('../modeling/BpmnFactory').default} BpmnFactory
* @typedef {import('diagram-js/lib/core/EventBus').default} EventBus
Expand Down
22 changes: 10 additions & 12 deletions lib/features/rules/BpmnRules.js
Original file line number Diff line number Diff line change
Expand Up @@ -1143,16 +1143,6 @@ function canInsert(shape, connection, position) {
canDrop(shape, connection.parent, position));
}

/**
* @param {Element[]} elements
* @param {Element} element
*
* @return {boolean}
*/
function includes(elements, element) {
return (elements && element) && elements.indexOf(element) !== -1;
}

/**
* @param {Element[]} elements
* @param {Element} element
Expand All @@ -1164,10 +1154,18 @@ function canCopy(elements, element) {
return true;
}

if (is(element, 'bpmn:Lane') && !includes(elements, element.parent)) {
if (is(element, 'bpmn:Lane') && !elements.includes(element.parent)) {
return false;
}

if (is(element, 'bpmn:MessageFlow')) {
const source = element.source,
target = element.target;

return elements.includes(is(source, 'bpmn:Participant') ? source : getParent(source, 'bpmn:Participant'))
&& elements.includes(is(target, 'bpmn:Participant') ? target : getParent(target, 'bpmn:Participant'));
}

return true;
}

Expand All @@ -1178,4 +1176,4 @@ function canCopy(elements, element) {
*/
function getRootElement(element) {
return getParent(element, 'bpmn:Process') || getParent(element, 'bpmn:Collaboration');
}
}
25 changes: 25 additions & 0 deletions test/spec/features/copy-paste/BpmnCopyPasteSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -964,6 +964,31 @@ describe('features/copy-paste', function() {

});


describe('rules', function() {

beforeEach(bootstrapModeler(collaborationMultipleXML, {
modules: testModules,
moddleExtensions: {
camunda: camundaPackage
}
}));


it.only('should allow copying message flow with parent participants of source and target', inject(function(elementRegistry) {

// when
var tree = copy([ 'IntermediateThrowEvent_1', 'Task_2', 'MessageFlow_1' ]);

console.log(tree, keys(tree));

// then
expect(keys(tree)).to.have.length(1);
expect(getAllElementsInTree(tree, 0)).to.have.length(2);
}));

});

});


Expand Down
26 changes: 26 additions & 0 deletions test/spec/features/rules/BpmnRulesSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,32 @@ describe('features/modeling/rules - BpmnRules', function() {
expectCanCopy(boundaryEvent, [ boundaryEvent ], true);
}));


it('copy message flow with parent participants of source and target', inject(function(elementFactory) {

// given
var sourceParticipant = elementFactory.createShape({ type: 'bpmn:Participant' }),
targetParticipant = elementFactory.createShape({ type: 'bpmn:Participant' }),
source = elementFactory.createShape({ type: 'bpmn:Task', parent: sourceParticipant }),
target = elementFactory.createShape({ type: 'bpmn:Task', parent: targetParticipant }),
messageFlow = elementFactory.createConnection({ type: 'bpmn:MessageFlow', source: source, target: target, waypoints: [] });

// then
expectCanCopy(messageFlow, [ sourceParticipant, targetParticipant, source, target, messageFlow ], true);
}));


it('copy message flow without parent participants of source and target', inject(function(elementFactory) {

// given
var source = elementFactory.createShape({ type: 'bpmn:Task' }),
target = elementFactory.createShape({ type: 'bpmn:Task' }),
messageFlow = elementFactory.createConnection({ type: 'bpmn:MessageFlow', source: source, target: target, waypoints: [] });

// then
expectCanCopy(messageFlow, [ source, target, messageFlow ], false);
}));

});


Expand Down

0 comments on commit ecf232c

Please sign in to comment.