mirror of
https://github.com/nasa/openmct.git
synced 2025-06-21 00:23:01 +00:00
[Containment] Restrict the compose action
Restrict the compose action by policy, to avoid drag-drop of inappropriate domain object types. WTD-962.
This commit is contained in:
57
platform/containment/src/ComposeActionPolicy.js
Normal file
57
platform/containment/src/ComposeActionPolicy.js
Normal file
@ -0,0 +1,57 @@
|
||||
/*global define*/
|
||||
|
||||
define(
|
||||
[],
|
||||
function () {
|
||||
"use strict";
|
||||
|
||||
/**
|
||||
* Restrict `compose` actions to cases where composition
|
||||
* is explicitly allowed.
|
||||
*
|
||||
* Note that this is a policy that needs the `policyService`,
|
||||
* since it's delegated to a different policy category.
|
||||
* To avoid a circular dependency, the service is obtained via
|
||||
* Angular's `$injector`.
|
||||
*/
|
||||
function ComposeActionPolicy($injector) {
|
||||
var policyService;
|
||||
|
||||
function allowComposition(containerObject, selectedObject) {
|
||||
// Get the object types involved in the compose action
|
||||
var containerType = containerObject &&
|
||||
containerObject.getCapability('type'),
|
||||
selectedType = selectedObject &&
|
||||
selectedObject.getCapability('type');
|
||||
|
||||
// Get a reference to the policy service if needed...
|
||||
policyService = policyService || $injector.get('policyService');
|
||||
|
||||
// ...and delegate to the composition policy
|
||||
return policyService.allow(
|
||||
'composition',
|
||||
containerType,
|
||||
selectedType
|
||||
);
|
||||
}
|
||||
|
||||
return {
|
||||
/**
|
||||
* Check whether or not a compose action should be allowed
|
||||
* in this context.
|
||||
* @returns {boolean} true if it may be allowed
|
||||
*/
|
||||
allow: function (candidate, context) {
|
||||
if (candidate.getMetadata().key === 'compose') {
|
||||
return allowComposition(
|
||||
(context || {}).domainObject,
|
||||
(context || {}).selectedObject
|
||||
);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
}
|
||||
);
|
Reference in New Issue
Block a user