From f9387a8e84fa72bd169abf2b3f09673a3bbe431a Mon Sep 17 00:00:00 2001 From: Victor Woeltjen Date: Wed, 1 Apr 2015 14:39:47 -0700 Subject: [PATCH] [Policy] Implement action decorator Implement policy-driven action decorator, sufficient to satisfy spec. WTD-973. --- platform/policy/src/PolicyActionDecorator.js | 37 ++++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/platform/policy/src/PolicyActionDecorator.js b/platform/policy/src/PolicyActionDecorator.js index e69de29bb2..1057dca905 100644 --- a/platform/policy/src/PolicyActionDecorator.js +++ b/platform/policy/src/PolicyActionDecorator.js @@ -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; + } +); \ No newline at end of file