feat(copy-paste): disallow pasting of participants on some scenarios

Participants are not allowed to be pasted onto a Process,
if the Process already has other elements.

Closes #526
This commit is contained in:
Ricardo Matias 2016-05-02 08:57:12 +02:00 committed by Nico Rehwaldt
parent 3f04e18398
commit 612b93db2e
3 changed files with 286 additions and 232 deletions

View File

@ -2,18 +2,19 @@
var is = require('../../../util/ModelUtil').is; var is = require('../../../util/ModelUtil').is;
var COLLAB_ERR_MSG = 'flow elements must be children of pools/participants'; var COLLAB_ERR_MSG = 'flow elements must be children of pools/participants',
PROCESS_ERR_MSG = 'participants cannot be pasted onto a non-empty process diagram';
function ModelingFeedback(eventBus, tooltips, translate) { function ModelingFeedback(eventBus, tooltips, translate) {
function showError(position, message) { function showError(position, message, timeout) {
tooltips.add({ tooltips.add({
position: { position: {
x: position.x + 5, x: position.x + 5,
y: position.y + 5 y: position.y + 5
}, },
type: 'error', type: 'error',
timeout: 2000, timeout: timeout || 2000,
html: '<div>' + message + '</div>' html: '<div>' + message + '</div>'
}); });
} }
@ -36,6 +37,10 @@ function ModelingFeedback(eventBus, tooltips, translate) {
if (is(target, 'bpmn:Collaboration')) { if (is(target, 'bpmn:Collaboration')) {
showError(position, translate(COLLAB_ERR_MSG)); showError(position, translate(COLLAB_ERR_MSG));
} }
if (is(target, 'bpmn:Process')) {
showError(position, translate(PROCESS_ERR_MSG), 3000);
}
}); });
} }

View File

@ -427,7 +427,8 @@ function canDrop(element, target, position) {
} }
function canPaste(tree, target) { function canPaste(tree, target) {
var topLevel = tree[0]; var topLevel = tree[0],
participants;
if (is(target, 'bpmn:Collaboration')) { if (is(target, 'bpmn:Collaboration')) {
return every(topLevel, function(e) { return every(topLevel, function(e) {
@ -435,6 +436,14 @@ function canPaste(tree, target) {
}); });
} }
if (is(target, 'bpmn:Process')) {
participants = any(topLevel, function(e) {
return e.type === 'bpmn:Participant';
});
return !(participants && target.children.length > 0);
}
// disallow to create elements on collapsed pools // disallow to create elements on collapsed pools
if (is(target, 'bpmn:Participant') && !isExpanded(target)) { if (is(target, 'bpmn:Participant') && !isExpanded(target)) {
return false; return false;

View File

@ -48,7 +48,7 @@ describe('features/copy-paste', function() {
collaborationMultipleXML = require('../../../fixtures/bpmn/features/copy-paste/collaboration-multiple.bpmn'); collaborationMultipleXML = require('../../../fixtures/bpmn/features/copy-paste/collaboration-multiple.bpmn');
var integrationTest = function(ids) { function integrationTest(ids) {
return function(canvas, elementRegistry, modeling, copyPaste, commandStack) { return function(canvas, elementRegistry, modeling, copyPaste, commandStack) {
// given // given
var shapes = elementRegistry.getAll(), var shapes = elementRegistry.getAll(),
@ -127,6 +127,7 @@ describe('features/copy-paste', function() {
}; };
}; };
describe('basic diagram', function() { describe('basic diagram', function() {
beforeEach(bootstrapModeler(basicXML, { modules: testModules })); beforeEach(bootstrapModeler(basicXML, { modules: testModules }));
@ -166,6 +167,7 @@ describe('features/copy-paste', function() {
}); });
describe('integration', function() { describe('integration', function() {
it('should retain label\'s relative position', it('should retain label\'s relative position',
@ -279,6 +281,7 @@ describe('features/copy-paste', function() {
}); });
describe('rules', function() { describe('rules', function() {
it('disallow individual boundary events copying', inject(function(copyPaste, elementRegistry, canvas) { it('disallow individual boundary events copying', inject(function(copyPaste, elementRegistry, canvas) {
@ -298,6 +301,7 @@ describe('features/copy-paste', function() {
}); });
describe('basic collaboration', function() { describe('basic collaboration', function() {
beforeEach(bootstrapModeler(collaborationXML, { modules: testModules })); beforeEach(bootstrapModeler(collaborationXML, { modules: testModules }));
@ -310,6 +314,7 @@ describe('features/copy-paste', function() {
}); });
describe('rules', function () { describe('rules', function () {
it('disallow individual lanes copying', inject(function(copyPaste, elementRegistry, canvas) { it('disallow individual lanes copying', inject(function(copyPaste, elementRegistry, canvas) {
@ -358,10 +363,44 @@ describe('features/copy-paste', function() {
expect(pasteRejected).to.have.been.called; expect(pasteRejected).to.have.been.called;
})); }));
it('pasting participants on a process is disallowed when it\'s not a collaboration',
inject(function(copyPaste, elementRegistry, canvas, tooltips, eventBus, modeling, elementFactory) {
var participant = elementRegistry.get('Participant_145muai'),
otherParticipant = elementRegistry.get('Participant_0uu1rvj'),
startEvent = elementFactory.create('shape', { type: 'bpmn:StartEvent' }),
rootElement;
var pasteRejected = sinon.spy(function() {});
// when
copyPaste.copy([ participant ]);
modeling.removeElements([ participant, otherParticipant ]);
rootElement = canvas.getRootElement();
modeling.createShape(startEvent, { x: 50, y: 50 }, rootElement);
eventBus.on('elements.paste.rejected', pasteRejected);
copyPaste.paste({
element: rootElement,
point: {
x: 500,
y: 200
}
});
expect(pasteRejected).to.have.been.called;
}));
}); });
}); });
describe('complex collaboration', function() { describe('complex collaboration', function() {
beforeEach(bootstrapModeler(collaborationMultipleXML, { modules: testModules })); beforeEach(bootstrapModeler(collaborationMultipleXML, { modules: testModules }));
@ -395,6 +434,7 @@ describe('features/copy-paste', function() {
}); });
describe('integration', function() { describe('integration', function() {
it('multiple participants', inject(integrationTest([ 'Participant_0pgdgt4', 'Participant_1id96b4' ]))); it('multiple participants', inject(integrationTest([ 'Participant_0pgdgt4', 'Participant_1id96b4' ])));