mirror of
https://github.com/nasa/openmct.git
synced 2025-06-16 22:28:13 +00:00
[Composition] Disallow composition for leaf types
Disallow composition for domain object types which will not have a composition property; WTD-1221.
This commit is contained in:
@ -45,8 +45,9 @@ define(
|
|||||||
properties = type.getProperties();
|
properties = type.getProperties();
|
||||||
|
|
||||||
function validateLocation(locatingObject) {
|
function validateLocation(locatingObject) {
|
||||||
var locatingType = locatingObject.getCapability('type');
|
var locatingType = locatingObject &&
|
||||||
return policyService.allow(
|
locatingObject.getCapability('type');
|
||||||
|
return locatingType && policyService.allow(
|
||||||
"composition",
|
"composition",
|
||||||
locatingType,
|
locatingType,
|
||||||
type
|
type
|
||||||
|
@ -12,6 +12,11 @@
|
|||||||
"implementation": "CompositionMutabilityPolicy.js",
|
"implementation": "CompositionMutabilityPolicy.js",
|
||||||
"message": "Objects of this type cannot be modified."
|
"message": "Objects of this type cannot be modified."
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"category": "composition",
|
||||||
|
"implementation": "CompositionModelPolicy.js",
|
||||||
|
"message": "Objects of this type cannot contain other objects."
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"category": "action",
|
"category": "action",
|
||||||
"implementation": "ComposeActionPolicy.js",
|
"implementation": "ComposeActionPolicy.js",
|
||||||
|
28
platform/containment/src/CompositionModelPolicy.js
Normal file
28
platform/containment/src/CompositionModelPolicy.js
Normal file
@ -0,0 +1,28 @@
|
|||||||
|
/*global define*/
|
||||||
|
|
||||||
|
define(
|
||||||
|
[],
|
||||||
|
function () {
|
||||||
|
"use strict";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Policy allowing composition only for domain object types which
|
||||||
|
* have a composition property.
|
||||||
|
*/
|
||||||
|
function CompositionModelPolicy() {
|
||||||
|
return {
|
||||||
|
/**
|
||||||
|
* Is the type identified by the candidate allowed to
|
||||||
|
* contain the type described by the context?
|
||||||
|
*/
|
||||||
|
allow: function (candidate, context) {
|
||||||
|
return Array.isArray(
|
||||||
|
(candidate.getInitialModel() || {}).composition
|
||||||
|
);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
return CompositionModelPolicy;
|
||||||
|
}
|
||||||
|
);
|
26
platform/containment/test/CompositionModelPolicySpec.js
Normal file
26
platform/containment/test/CompositionModelPolicySpec.js
Normal file
@ -0,0 +1,26 @@
|
|||||||
|
/*global define,Promise,describe,it,expect,beforeEach,waitsFor,jasmine*/
|
||||||
|
|
||||||
|
define(
|
||||||
|
["../src/CompositionModelPolicy"],
|
||||||
|
function (CompositionModelPolicy) {
|
||||||
|
"use strict";
|
||||||
|
|
||||||
|
describe("The composition model policy", function () {
|
||||||
|
var mockType,
|
||||||
|
policy;
|
||||||
|
|
||||||
|
beforeEach(function () {
|
||||||
|
mockType = jasmine.createSpyObj('type', ['getInitialModel']);
|
||||||
|
policy = new CompositionModelPolicy();
|
||||||
|
});
|
||||||
|
|
||||||
|
it("only allows composition for types which will have a composition property", function () {
|
||||||
|
mockType.getInitialModel.andReturn({});
|
||||||
|
expect(policy.allow(mockType)).toBeFalsy();
|
||||||
|
mockType.getInitialModel.andReturn({ composition: [] });
|
||||||
|
expect(policy.allow(mockType)).toBeTruthy();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
}
|
||||||
|
);
|
@ -35,7 +35,7 @@ define(
|
|||||||
policy = new CompositionMutabilityPolicy();
|
policy = new CompositionMutabilityPolicy();
|
||||||
});
|
});
|
||||||
|
|
||||||
it("only allows composition for types which will have a composition capability", function () {
|
it("only allows composition for types which can be created/modified", function () {
|
||||||
expect(policy.allow(mockType)).toBeFalsy();
|
expect(policy.allow(mockType)).toBeFalsy();
|
||||||
mockType.hasFeature.andReturn(true);
|
mockType.hasFeature.andReturn(true);
|
||||||
expect(policy.allow(mockType)).toBeTruthy();
|
expect(policy.allow(mockType)).toBeTruthy();
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
[
|
[
|
||||||
"CapabilityTable",
|
"CapabilityTable",
|
||||||
"ComposeActionPolicy",
|
"ComposeActionPolicy",
|
||||||
|
"CompositionModelPolicy",
|
||||||
"CompositionMutabilityPolicy",
|
"CompositionMutabilityPolicy",
|
||||||
"CompositionPolicy",
|
"CompositionPolicy",
|
||||||
"ContainmentTable"
|
"ContainmentTable"
|
||||||
|
Reference in New Issue
Block a user