From 4c42d4de287c44189803e2e86c64278860318cfe Mon Sep 17 00:00:00 2001 From: Victor Woeltjen Date: Tue, 27 Jan 2015 13:00:40 -0800 Subject: [PATCH] [Actions] Restrict mutating actions Restrict actions which cause mutation of domain objects to types of domain objects which can be created. (This does not include Packet or Telemetry Point, WTD-723.) --- platform/commonUI/edit/src/actions/EditAction.js | 6 +++++- .../commonUI/edit/src/actions/PropertiesAction.js | 11 ++++++++--- platform/commonUI/edit/src/actions/RemoveAction.js | 9 +++++++-- 3 files changed, 20 insertions(+), 6 deletions(-) diff --git a/platform/commonUI/edit/src/actions/EditAction.js b/platform/commonUI/edit/src/actions/EditAction.js index 0798c603a4..1c5a6878a5 100644 --- a/platform/commonUI/edit/src/actions/EditAction.js +++ b/platform/commonUI/edit/src/actions/EditAction.js @@ -57,7 +57,11 @@ define( * will be performed; should contain a `domainObject` property */ EditAction.appliesTo = function (context) { - return (context || {}).domainObject !== undefined; + var domainObject = (context || {}).domainObject, + type = domainObject && domainObject.getCapability('type'); + + // Only allow creatable types to be edited + return type && type.hasFeature('creation'); }; return EditAction; diff --git a/platform/commonUI/edit/src/actions/PropertiesAction.js b/platform/commonUI/edit/src/actions/PropertiesAction.js index 18d2f57586..dd82774d69 100644 --- a/platform/commonUI/edit/src/actions/PropertiesAction.js +++ b/platform/commonUI/edit/src/actions/PropertiesAction.js @@ -70,9 +70,14 @@ define( * context. */ PropertiesAction.appliesTo = function (context) { - return (context || {}).domainObject && - (context || {}).domainObject.hasCapability("type") && - (context || {}).domainObject.hasCapability("persistence"); + var domainObject = (context || {}).domainObject, + type = domainObject && domainObject.getCapability('type'), + creatable = type && type.hasFeature('creation'); + + // Only allow creatable types to be edited + return domainObject && + domainObject.hasCapability("persistence") && + creatable; }; return PropertiesAction; diff --git a/platform/commonUI/edit/src/actions/RemoveAction.js b/platform/commonUI/edit/src/actions/RemoveAction.js index 9ff67c7a48..1a7d5f8ea1 100644 --- a/platform/commonUI/edit/src/actions/RemoveAction.js +++ b/platform/commonUI/edit/src/actions/RemoveAction.js @@ -80,9 +80,14 @@ define( RemoveAction.appliesTo = function (context) { var object = (context || {}).domainObject, contextCapability = object && object.getCapability("context"), - parent = contextCapability && contextCapability.getParent(); + parent = contextCapability && contextCapability.getParent(), + parentType = parent.getCapability('type'), + parentCreatable = parentType && parentType.hasFeature('creation'); + + // Only creatable types should be modifiable return parent !== undefined && - Array.isArray(parent.getModel().composition); + Array.isArray(parent.getModel().composition) && + parentCreatable; }; return RemoveAction;