Files
openmct/platform/policy/src/PolicyActionDecorator.js
Victor Woeltjen 892e2c9dd4 [Policy] Implement view decorator
Implement policy-driven view decorator, sufficient to satisfy
specs. WTD-1062.
2015-04-01 15:58:19 -07:00

37 lines
1.3 KiB
JavaScript

/*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 filtered 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;
}
);