Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Do Not Copy Message Flows Without Participant #1904

Draft
wants to merge 2 commits into
base: develop
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 16 additions & 18 deletions lib/features/rules/BpmnRules.js
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ BpmnRules.prototype.init = function() {

return every(elements, function(element) {
if (isConnection(element)) {
return canConnect(element.source, element.target, element);
return (canConnect(element.source, element.target, element) || {}).type === element.type;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's elaborate what this does.

My guess is it ensures that connections can only be created if they would not change their type?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, the check was useless before because we want to create a number of shapes and connections that are predefined and must not change their type during creation.

}

if (element.host) {
Expand Down Expand Up @@ -1068,11 +1068,11 @@ function canConnectMessageFlow(source, target) {
return false;
}

return (
isMessageFlowSource(source) &&
isMessageFlowTarget(target) &&
!isSameOrganization(source, target)
);
return isMessageFlowSource(source)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm hesitant to merge this, as this is completely unclear what these additions ensure.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll have to check whether this check is strictly necessary. The point is to make sure source and target are in different participants.

&& (is(source, 'bpmn:Participant') || !!getParent(source, 'bpmn:Participant'))
&& isMessageFlowTarget(target)
&& (is(target, 'bpmn:Participant') || !!getParent(target, 'bpmn:Participant'))
&& !isSameOrganization(source, target);
}

/**
Expand Down 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)) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We're getting rid of null-safety here. Is this intentional?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let me have a look.

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('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
32 changes: 30 additions & 2 deletions test/spec/features/rules/BpmnRulesSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,8 @@ describe('features/modeling/rules - BpmnRules', function() {
sequenceFlow = elementFactory.createConnection({
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As we're fixing something I'd expect a test case that verifies the new behavior.

type: 'bpmn:SequenceFlow',
source: task1,
target: task2
target: task2,
waypoints: []
});

// then
Expand All @@ -74,7 +75,8 @@ describe('features/modeling/rules - BpmnRules', function() {
sequenceFlow = elementFactory.createConnection({
type: 'bpmn:MessageFlow',
source: task1,
target: task2
target: task2,
waypoints: []
});

// then
Expand Down Expand Up @@ -218,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