mirror of
https://github.com/nasa/openmct.git
synced 2024-12-27 08:32:28 +00:00
Merge branch 'open1098' into open-master
This commit is contained in:
commit
a2bdeda1a0
@ -7,6 +7,11 @@
|
||||
"depends": [ "$injector" ],
|
||||
"message": "Objects of this type cannot contain objects of that type."
|
||||
},
|
||||
{
|
||||
"category": "composition",
|
||||
"implementation": "CompositionMutabilityPolicy.js",
|
||||
"message": "Objects of this type cannot be modified."
|
||||
},
|
||||
{
|
||||
"category": "action",
|
||||
"implementation": "ComposeActionPolicy.js",
|
||||
|
30
platform/containment/src/CompositionMutabilityPolicy.js
Normal file
30
platform/containment/src/CompositionMutabilityPolicy.js
Normal file
@ -0,0 +1,30 @@
|
||||
/*global define*/
|
||||
|
||||
define(
|
||||
[],
|
||||
function () {
|
||||
"use strict";
|
||||
|
||||
/**
|
||||
* Disallow composition changes to objects which are not mutable.
|
||||
* @constructor
|
||||
*/
|
||||
function CompositionMutabilityPolicy() {
|
||||
return {
|
||||
/**
|
||||
* Is the type identified by the candidate allowed to
|
||||
* contain the type described by the context?
|
||||
* @param {Type} candidate the type of domain object
|
||||
*/
|
||||
allow: function (candidate) {
|
||||
// Equate creatability with mutability; that is, users
|
||||
// can only modify objects of types they can create, and
|
||||
// vice versa.
|
||||
return candidate.hasFeature('creation');
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
return CompositionMutabilityPolicy;
|
||||
}
|
||||
);
|
26
platform/containment/test/CompositionMutabilityPolicySpec.js
Normal file
26
platform/containment/test/CompositionMutabilityPolicySpec.js
Normal file
@ -0,0 +1,26 @@
|
||||
/*global define,Promise,describe,it,expect,beforeEach,waitsFor,jasmine*/
|
||||
|
||||
define(
|
||||
["../src/CompositionMutabilityPolicy"],
|
||||
function (CompositionMutabilityPolicy) {
|
||||
"use strict";
|
||||
|
||||
describe("The composition mutability policy", function () {
|
||||
var mockType,
|
||||
policy;
|
||||
|
||||
beforeEach(function () {
|
||||
mockType = jasmine.createSpyObj('type', ['hasFeature']);
|
||||
policy = new CompositionMutabilityPolicy();
|
||||
});
|
||||
|
||||
it("only allows composition for types which will have a composition capability", function () {
|
||||
expect(policy.allow(mockType)).toBeFalsy();
|
||||
mockType.hasFeature.andReturn(true);
|
||||
expect(policy.allow(mockType)).toBeTruthy();
|
||||
expect(mockType.hasFeature).toHaveBeenCalledWith('creation');
|
||||
});
|
||||
});
|
||||
|
||||
}
|
||||
);
|
@ -1,6 +1,7 @@
|
||||
[
|
||||
"CapabilityTable",
|
||||
"ComposeActionPolicy",
|
||||
"CompositionMutabilityPolicy",
|
||||
"CompositionPolicy",
|
||||
"ContainmentTable"
|
||||
]
|
Loading…
Reference in New Issue
Block a user