diff --git a/platform/commonUI/edit/src/creation/CreateWizard.js b/platform/commonUI/edit/src/creation/CreateWizard.js index 79416ac4b4..2448a10d72 100644 --- a/platform/commonUI/edit/src/creation/CreateWizard.js +++ b/platform/commonUI/edit/src/creation/CreateWizard.js @@ -60,11 +60,9 @@ define( policyService = this.policyService; function validateLocation(parent) { - var parentType = parent && - parent.getCapability('type'); - return parentType && policyService.allow( + return parent && policyService.allow( "composition", - parentType, + parent, domainObject ); } diff --git a/platform/containment/bundle.js b/platform/containment/bundle.js index a64710b974..7bbfff0f3f 100644 --- a/platform/containment/bundle.js +++ b/platform/containment/bundle.js @@ -25,12 +25,14 @@ define([ "./src/CompositionMutabilityPolicy", "./src/CompositionModelPolicy", "./src/ComposeActionPolicy", + "./src/PersistableCompositionPolicy", 'legacyRegistry' ], function ( CompositionPolicy, CompositionMutabilityPolicy, CompositionModelPolicy, ComposeActionPolicy, + PersistableCompositionPolicy, legacyRegistry ) { @@ -59,6 +61,12 @@ define([ "$injector" ], "message": "Objects of this type cannot contain objects of that type." + }, + { + "category": "composition", + "implementation": PersistableCompositionPolicy, + "depends": ["openmct"], + "message": "Change cannot be made to composition of non-persistable object" } ] } diff --git a/platform/containment/src/ComposeActionPolicy.js b/platform/containment/src/ComposeActionPolicy.js index 0a107756af..1a9092772f 100644 --- a/platform/containment/src/ComposeActionPolicy.js +++ b/platform/containment/src/ComposeActionPolicy.js @@ -43,9 +43,6 @@ define( } ComposeActionPolicy.prototype.allowComposition = function (containerObject, selectedObject) { - // Get the object types involved in the compose action - var containerType = containerObject && - containerObject.getCapability('type'); // Get a reference to the policy service if needed... this.policyService = this.policyService || this.getPolicyService(); @@ -54,7 +51,7 @@ define( return containerObject.getId() !== selectedObject.getId() && this.policyService.allow( 'composition', - containerType, + containerObject, selectedObject ); }; diff --git a/platform/containment/src/CompositionModelPolicy.js b/platform/containment/src/CompositionModelPolicy.js index be51e0c040..71d938fa46 100644 --- a/platform/containment/src/CompositionModelPolicy.js +++ b/platform/containment/src/CompositionModelPolicy.js @@ -14,8 +14,9 @@ define( } CompositionModelPolicy.prototype.allow = function (candidate) { + var candidateType = candidate.getCapability('type'); return Array.isArray( - (candidate.getInitialModel() || {}).composition + (candidateType.getInitialModel() || {}).composition ); }; diff --git a/platform/containment/src/CompositionMutabilityPolicy.js b/platform/containment/src/CompositionMutabilityPolicy.js index 71e49d1962..bf554dd3a3 100644 --- a/platform/containment/src/CompositionMutabilityPolicy.js +++ b/platform/containment/src/CompositionMutabilityPolicy.js @@ -37,7 +37,7 @@ define( // Equate creatability with mutability; that is, users // can only modify objects of types they can create, and // vice versa. - return candidate.hasFeature('creation'); + return candidate.getCapability('type').hasFeature('creation'); }; return CompositionMutabilityPolicy; diff --git a/platform/containment/src/CompositionPolicy.js b/platform/containment/src/CompositionPolicy.js index 60d0008fb0..8ece24c5a4 100644 --- a/platform/containment/src/CompositionPolicy.js +++ b/platform/containment/src/CompositionPolicy.js @@ -30,16 +30,16 @@ define( function () { /** - * Defines composition policy as driven by type metadata. + * Determines whether a given object can contain a candidate child object. * @constructor * @memberof platform/containment - * @implements {Policy.} + * @implements {Policy.} */ function CompositionPolicy() { } - CompositionPolicy.prototype.allow = function (parentType, child) { - var parentDef = parentType.getDefinition(); + CompositionPolicy.prototype.allow = function (parent, child) { + var parentDef = parent.getCapability('type').getDefinition(); // A parent without containment rules can contain anything. if (!parentDef.contains) { diff --git a/platform/entanglement/src/services/CopyService.js b/platform/entanglement/src/services/CopyService.js index 2ac29268cd..510e64fb7b 100644 --- a/platform/entanglement/src/services/CopyService.js +++ b/platform/entanglement/src/services/CopyService.js @@ -47,7 +47,7 @@ define( } return this.policyService.allow( "composition", - parentCandidate.getCapability('type'), + parentCandidate, object ); }; diff --git a/platform/entanglement/src/services/LinkService.js b/platform/entanglement/src/services/LinkService.js index 4942f93d35..cd31a9755f 100644 --- a/platform/entanglement/src/services/LinkService.js +++ b/platform/entanglement/src/services/LinkService.js @@ -51,7 +51,7 @@ define( } return this.policyService.allow( "composition", - parentCandidate.getCapability('type'), + parentCandidate, object ); }; diff --git a/platform/entanglement/src/services/MoveService.js b/platform/entanglement/src/services/MoveService.js index 82c3a70371..ac8202eba9 100644 --- a/platform/entanglement/src/services/MoveService.js +++ b/platform/entanglement/src/services/MoveService.js @@ -55,7 +55,7 @@ define( } return this.policyService.allow( "composition", - parentCandidate.getCapability('type'), + parentCandidate, object ); }; diff --git a/platform/features/layout/src/LayoutCompositionPolicy.js b/platform/features/layout/src/LayoutCompositionPolicy.js index a281d2d2ea..7ee7e6e40c 100644 --- a/platform/features/layout/src/LayoutCompositionPolicy.js +++ b/platform/features/layout/src/LayoutCompositionPolicy.js @@ -34,7 +34,8 @@ define( function LayoutCompositionPolicy() { } - LayoutCompositionPolicy.prototype.allow = function (parentType, child) { + LayoutCompositionPolicy.prototype.allow = function (parent, child) { + var parentType = parent.getCapability('type'); if (parentType.instanceOf('layout') && child.getCapability('type').instanceOf('folder')) { diff --git a/src/adapter/policies/AdapterCompositionPolicy.js b/src/adapter/policies/AdapterCompositionPolicy.js index b9d196e6f0..7d0d47e326 100644 --- a/src/adapter/policies/AdapterCompositionPolicy.js +++ b/src/adapter/policies/AdapterCompositionPolicy.js @@ -26,13 +26,11 @@ define([], function () { } AdapterCompositionPolicy.prototype.allow = function ( - parentType, + parent, child ) { - var container = parentType.getInitialModel(); - return this.openmct.composition.checkPolicy( - container, + parent, child ); };