From 9bcdd3b95851d4f9e4dbb18076af4e19b6f40a74 Mon Sep 17 00:00:00 2001 From: Nico Rehwaldt Date: Wed, 23 Mar 2016 15:32:10 +0100 Subject: [PATCH] fix(rules): do not allow deletion of labels Closes #499 --- lib/features/rules/BpmnRules.js | 8 ++++++ .../context-pad/ContextPadProviderSpec.js | 10 ++++---- test/spec/features/rules/BpmnRulesSpec.js | 25 +++++++++++++++++++ 3 files changed, 38 insertions(+), 5 deletions(-) diff --git a/lib/features/rules/BpmnRules.js b/lib/features/rules/BpmnRules.js index 022dfc1d..05937193 100644 --- a/lib/features/rules/BpmnRules.js +++ b/lib/features/rules/BpmnRules.js @@ -2,6 +2,7 @@ var find = require('lodash/collection/find'), any = require('lodash/collection/any'), + filter = require('lodash/collection/filter'), forEach = require('lodash/collection/forEach'), inherits = require('inherits'); @@ -91,6 +92,13 @@ BpmnRules.prototype.init = function() { return canAttach([ shape ], target, source, position) || canCreate(shape, target, source, position); }); + this.addRule([ 'elements.delete' ], function(context) { + + // do not allow deletion of labels + return filter(context.elements, function(e) { + return !isLabel(e); + }); + }); }; BpmnRules.prototype.canConnectMessageFlow = canConnectMessageFlow; diff --git a/test/spec/features/context-pad/ContextPadProviderSpec.js b/test/spec/features/context-pad/ContextPadProviderSpec.js index 729ecb71..cb94561e 100644 --- a/test/spec/features/context-pad/ContextPadProviderSpec.js +++ b/test/spec/features/context-pad/ContextPadProviderSpec.js @@ -64,7 +64,7 @@ describe('features - context-pad', function() { inject(function (elementRegistry, contextPad, customRules) { // given - customRules.addRule('elements.delete', function() { + customRules.addRule('elements.delete', 1500, function() { return true; }); @@ -82,7 +82,7 @@ describe('features - context-pad', function() { inject(function(elementRegistry, contextPad, customRules) { // given - customRules.addRule('elements.delete', function() { + customRules.addRule('elements.delete', 1500, function() { return false; }); @@ -101,7 +101,7 @@ describe('features - context-pad', function() { // given var element = elementRegistry.get('StartEvent_1'); - customRules.addRule('elements.delete', function(context) { + customRules.addRule('elements.delete', 1500, function(context) { // element array is actually passed expect(context.elements).to.eql([ element ]); @@ -120,7 +120,7 @@ describe('features - context-pad', function() { inject(function(elementRegistry, contextPad, customRules) { // given - customRules.addRule('elements.delete', function(context) { + customRules.addRule('elements.delete', 1500, function(context) { return context.elements; }); @@ -138,7 +138,7 @@ describe('features - context-pad', function() { inject(function(elementRegistry, contextPad, customRules) { // given - customRules.addRule('elements.delete', function() { + customRules.addRule('elements.delete', 1500, function() { return []; }); diff --git a/test/spec/features/rules/BpmnRulesSpec.js b/test/spec/features/rules/BpmnRulesSpec.js index ba22121a..04bd4294 100644 --- a/test/spec/features/rules/BpmnRulesSpec.js +++ b/test/spec/features/rules/BpmnRulesSpec.js @@ -1317,4 +1317,29 @@ describe('features/modeling/rules - BpmnRules', function() { }); + + describe('labels', function() { + + var testXML = require('./BpmnRules.process.bpmn'); + + beforeEach(bootstrapModeler(testXML, { modules: testModules })); + + + it('should filter labels', inject(function(elementRegistry, rules) { + + // given + var startEventShape = elementRegistry.get('StartEvent_None'), + startEventLabel = startEventShape.label; + + // when + var allowed = rules.allowed('elements.delete', { + elements: [ startEventShape, startEventLabel ] + }); + + // then + expect(allowed).to.eql([ startEventShape ]); + })); + + }); + });