mirror of
https://github.com/nasa/openmct.git
synced 2025-06-17 06:38:17 +00:00
Modified composition policies to consider object instances instead of types. Fixes #669
This commit is contained in:
@ -60,11 +60,9 @@ define(
|
|||||||
policyService = this.policyService;
|
policyService = this.policyService;
|
||||||
|
|
||||||
function validateLocation(parent) {
|
function validateLocation(parent) {
|
||||||
var parentType = parent &&
|
return parent && policyService.allow(
|
||||||
parent.getCapability('type');
|
|
||||||
return parentType && policyService.allow(
|
|
||||||
"composition",
|
"composition",
|
||||||
parentType,
|
parent,
|
||||||
domainObject
|
domainObject
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -25,12 +25,14 @@ define([
|
|||||||
"./src/CompositionMutabilityPolicy",
|
"./src/CompositionMutabilityPolicy",
|
||||||
"./src/CompositionModelPolicy",
|
"./src/CompositionModelPolicy",
|
||||||
"./src/ComposeActionPolicy",
|
"./src/ComposeActionPolicy",
|
||||||
|
"./src/PersistableCompositionPolicy",
|
||||||
'legacyRegistry'
|
'legacyRegistry'
|
||||||
], function (
|
], function (
|
||||||
CompositionPolicy,
|
CompositionPolicy,
|
||||||
CompositionMutabilityPolicy,
|
CompositionMutabilityPolicy,
|
||||||
CompositionModelPolicy,
|
CompositionModelPolicy,
|
||||||
ComposeActionPolicy,
|
ComposeActionPolicy,
|
||||||
|
PersistableCompositionPolicy,
|
||||||
legacyRegistry
|
legacyRegistry
|
||||||
) {
|
) {
|
||||||
|
|
||||||
@ -59,6 +61,12 @@ define([
|
|||||||
"$injector"
|
"$injector"
|
||||||
],
|
],
|
||||||
"message": "Objects of this type cannot contain objects of that type."
|
"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) {
|
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...
|
// Get a reference to the policy service if needed...
|
||||||
this.policyService = this.policyService || this.getPolicyService();
|
this.policyService = this.policyService || this.getPolicyService();
|
||||||
@ -54,7 +51,7 @@ define(
|
|||||||
return containerObject.getId() !== selectedObject.getId() &&
|
return containerObject.getId() !== selectedObject.getId() &&
|
||||||
this.policyService.allow(
|
this.policyService.allow(
|
||||||
'composition',
|
'composition',
|
||||||
containerType,
|
containerObject,
|
||||||
selectedObject
|
selectedObject
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
@ -14,8 +14,9 @@ define(
|
|||||||
}
|
}
|
||||||
|
|
||||||
CompositionModelPolicy.prototype.allow = function (candidate) {
|
CompositionModelPolicy.prototype.allow = function (candidate) {
|
||||||
|
var candidateType = candidate.getCapability('type');
|
||||||
return Array.isArray(
|
return Array.isArray(
|
||||||
(candidate.getInitialModel() || {}).composition
|
(candidateType.getInitialModel() || {}).composition
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -37,7 +37,7 @@ define(
|
|||||||
// Equate creatability with mutability; that is, users
|
// Equate creatability with mutability; that is, users
|
||||||
// can only modify objects of types they can create, and
|
// can only modify objects of types they can create, and
|
||||||
// vice versa.
|
// vice versa.
|
||||||
return candidate.hasFeature('creation');
|
return candidate.getCapability('type').hasFeature('creation');
|
||||||
};
|
};
|
||||||
|
|
||||||
return CompositionMutabilityPolicy;
|
return CompositionMutabilityPolicy;
|
||||||
|
@ -30,16 +30,16 @@ define(
|
|||||||
function () {
|
function () {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Defines composition policy as driven by type metadata.
|
* Determines whether a given object can contain a candidate child object.
|
||||||
* @constructor
|
* @constructor
|
||||||
* @memberof platform/containment
|
* @memberof platform/containment
|
||||||
* @implements {Policy.<Type, Type>}
|
* @implements {Policy.<DomainObjectImpl, DomainObjectImpl>}
|
||||||
*/
|
*/
|
||||||
function CompositionPolicy() {
|
function CompositionPolicy() {
|
||||||
}
|
}
|
||||||
|
|
||||||
CompositionPolicy.prototype.allow = function (parentType, child) {
|
CompositionPolicy.prototype.allow = function (parent, child) {
|
||||||
var parentDef = parentType.getDefinition();
|
var parentDef = parent.getCapability('type').getDefinition();
|
||||||
|
|
||||||
// A parent without containment rules can contain anything.
|
// A parent without containment rules can contain anything.
|
||||||
if (!parentDef.contains) {
|
if (!parentDef.contains) {
|
||||||
|
@ -47,7 +47,7 @@ define(
|
|||||||
}
|
}
|
||||||
return this.policyService.allow(
|
return this.policyService.allow(
|
||||||
"composition",
|
"composition",
|
||||||
parentCandidate.getCapability('type'),
|
parentCandidate,
|
||||||
object
|
object
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
@ -51,7 +51,7 @@ define(
|
|||||||
}
|
}
|
||||||
return this.policyService.allow(
|
return this.policyService.allow(
|
||||||
"composition",
|
"composition",
|
||||||
parentCandidate.getCapability('type'),
|
parentCandidate,
|
||||||
object
|
object
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
@ -55,7 +55,7 @@ define(
|
|||||||
}
|
}
|
||||||
return this.policyService.allow(
|
return this.policyService.allow(
|
||||||
"composition",
|
"composition",
|
||||||
parentCandidate.getCapability('type'),
|
parentCandidate,
|
||||||
object
|
object
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
@ -34,7 +34,8 @@ define(
|
|||||||
function LayoutCompositionPolicy() {
|
function LayoutCompositionPolicy() {
|
||||||
}
|
}
|
||||||
|
|
||||||
LayoutCompositionPolicy.prototype.allow = function (parentType, child) {
|
LayoutCompositionPolicy.prototype.allow = function (parent, child) {
|
||||||
|
var parentType = parent.getCapability('type');
|
||||||
if (parentType.instanceOf('layout') &&
|
if (parentType.instanceOf('layout') &&
|
||||||
child.getCapability('type').instanceOf('folder')) {
|
child.getCapability('type').instanceOf('folder')) {
|
||||||
|
|
||||||
|
@ -26,13 +26,11 @@ define([], function () {
|
|||||||
}
|
}
|
||||||
|
|
||||||
AdapterCompositionPolicy.prototype.allow = function (
|
AdapterCompositionPolicy.prototype.allow = function (
|
||||||
parentType,
|
parent,
|
||||||
child
|
child
|
||||||
) {
|
) {
|
||||||
var container = parentType.getInitialModel();
|
|
||||||
|
|
||||||
return this.openmct.composition.checkPolicy(
|
return this.openmct.composition.checkPolicy(
|
||||||
container,
|
parent,
|
||||||
child
|
child
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
Reference in New Issue
Block a user