[Policy] Implement view decorator
Implement policy-driven view decorator, sufficient to satisfy specs. WTD-1062.
This commit is contained in:
@@ -15,7 +15,7 @@ define(
|
||||
return {
|
||||
/**
|
||||
* Get actions which are applicable in this context.
|
||||
* These will be filters to remove any actions which
|
||||
* 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
|
||||
|
||||
37
platform/policy/src/PolicyViewDecorator.js
Normal file
37
platform/policy/src/PolicyViewDecorator.js
Normal file
@@ -0,0 +1,37 @@
|
||||
/*global define*/
|
||||
|
||||
define(
|
||||
[],
|
||||
function () {
|
||||
"use strict";
|
||||
|
||||
/**
|
||||
* Filters out views based on policy.
|
||||
* @param {PolicyService} policyService the service which provides
|
||||
* policy decisions
|
||||
* @param {ViewService} viewService the service to decorate
|
||||
*/
|
||||
function PolicyActionDecorator(policyService, viewService) {
|
||||
return {
|
||||
/**
|
||||
* Get views which are applicable to this domain object.
|
||||
* These will be filtered to remove any views which
|
||||
* are deemed inapplicable by policy.
|
||||
* @param {DomainObject} the domain object to view
|
||||
* @returns {View[]} applicable views
|
||||
*/
|
||||
getViews: function (domainObject) {
|
||||
// Check if an action is allowed by policy.
|
||||
function allow(view) {
|
||||
return policyService.allow('view', view, domainObject);
|
||||
}
|
||||
|
||||
// Look up actions, filter out the disallowed ones.
|
||||
return viewService.getViews(domainObject).filter(allow);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
return PolicyActionDecorator;
|
||||
}
|
||||
);
|
||||
Reference in New Issue
Block a user