[Policy] Implement action decorator

Implement policy-driven action decorator, sufficient to satisfy
spec. WTD-973.
This commit is contained in:
Victor Woeltjen 2015-04-01 14:39:47 -07:00
parent 04005ce75f
commit f9387a8e84

View File

@ -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;
}
);