Modified composition policies to consider object instances instead of types. Fixes #669

This commit is contained in:
Henry 2017-03-24 16:59:30 -07:00
parent 399b745084
commit 1cb5dd021f
11 changed files with 25 additions and 22 deletions

View File

@ -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
);
}

View File

@ -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"
}
]
}

View File

@ -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
);
};

View File

@ -14,8 +14,9 @@ define(
}
CompositionModelPolicy.prototype.allow = function (candidate) {
var candidateType = candidate.getCapability('type');
return Array.isArray(
(candidate.getInitialModel() || {}).composition
(candidateType.getInitialModel() || {}).composition
);
};

View File

@ -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;

View File

@ -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.<Type, Type>}
* @implements {Policy.<DomainObjectImpl, DomainObjectImpl>}
*/
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) {

View File

@ -47,7 +47,7 @@ define(
}
return this.policyService.allow(
"composition",
parentCandidate.getCapability('type'),
parentCandidate,
object
);
};

View File

@ -51,7 +51,7 @@ define(
}
return this.policyService.allow(
"composition",
parentCandidate.getCapability('type'),
parentCandidate,
object
);
};

View File

@ -55,7 +55,7 @@ define(
}
return this.policyService.allow(
"composition",
parentCandidate.getCapability('type'),
parentCandidate,
object
);
};

View File

@ -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')) {

View File

@ -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
);
};