mirror of
https://github.com/nasa/openmct.git
synced 2025-06-04 08:30:48 +00:00
[Policy] Implement action decorator
Implement policy-driven action decorator, sufficient to satisfy spec. WTD-973.
This commit is contained in:
parent
04005ce75f
commit
f9387a8e84
@ -0,0 +1,37 @@
|
|||||||
|
/*global define*/
|
||||||
|
|
||||||
|
define(
|
||||||
|
[],
|
||||||
|
function () {
|
||||||
|
"use strict";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Filters out actions based on policy.
|
||||||
|
* @param {PolicyService} policyService the service which provides
|
||||||
|
* policy decisions
|
||||||
|
* @param {ActionService} actionService the service to decorate
|
||||||
|
*/
|
||||||
|
function PolicyActionDecorator(policyService, actionService) {
|
||||||
|
return {
|
||||||
|
/**
|
||||||
|
* Get actions which are applicable in this context.
|
||||||
|
* These will be filters to remove any actions which
|
||||||
|
* are deemed inapplicable by policy.
|
||||||
|
* @param context the context in which the action will occur
|
||||||
|
* @returns {Action[]} applicable actions
|
||||||
|
*/
|
||||||
|
getActions: function (context) {
|
||||||
|
// Check if an action is allowed by policy.
|
||||||
|
function allow(action) {
|
||||||
|
return policyService.allow('action', action, context);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Look up actions, filter out the disallowed ones.
|
||||||
|
return actionService.getActions(context).filter(allow);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
return PolicyActionDecorator;
|
||||||
|
}
|
||||||
|
);
|
Loading…
x
Reference in New Issue
Block a user