mirror of
https://github.com/nasa/openmct.git
synced 2025-04-15 06:56:43 +00:00
Modified composition policies to consider object instances instead of types. Fixes #669
This commit is contained in:
parent
399b745084
commit
1cb5dd021f
@ -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
|
||||
);
|
||||
}
|
||||
|
@ -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"
|
||||
}
|
||||
]
|
||||
}
|
||||
|
@ -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
|
||||
);
|
||||
};
|
||||
|
@ -14,8 +14,9 @@ define(
|
||||
}
|
||||
|
||||
CompositionModelPolicy.prototype.allow = function (candidate) {
|
||||
var candidateType = candidate.getCapability('type');
|
||||
return Array.isArray(
|
||||
(candidate.getInitialModel() || {}).composition
|
||||
(candidateType.getInitialModel() || {}).composition
|
||||
);
|
||||
};
|
||||
|
||||
|
@ -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;
|
||||
|
@ -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) {
|
||||
|
@ -47,7 +47,7 @@ define(
|
||||
}
|
||||
return this.policyService.allow(
|
||||
"composition",
|
||||
parentCandidate.getCapability('type'),
|
||||
parentCandidate,
|
||||
object
|
||||
);
|
||||
};
|
||||
|
@ -51,7 +51,7 @@ define(
|
||||
}
|
||||
return this.policyService.allow(
|
||||
"composition",
|
||||
parentCandidate.getCapability('type'),
|
||||
parentCandidate,
|
||||
object
|
||||
);
|
||||
};
|
||||
|
@ -55,7 +55,7 @@ define(
|
||||
}
|
||||
return this.policyService.allow(
|
||||
"composition",
|
||||
parentCandidate.getCapability('type'),
|
||||
parentCandidate,
|
||||
object
|
||||
);
|
||||
};
|
||||
|
@ -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')) {
|
||||
|
||||
|
@ -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
|
||||
);
|
||||
};
|
||||
|
Loading…
x
Reference in New Issue
Block a user