mirror of
https://github.com/nasa/openmct.git
synced 2025-05-29 05:34:18 +00:00
[Policy] Implement view decorator
Implement policy-driven view decorator, sufficient to satisfy specs. WTD-1062.
This commit is contained in:
parent
7915074b10
commit
892e2c9dd4
@ -10,6 +10,12 @@
|
||||
"implementation": "PolicyActionDecorator.js",
|
||||
"depends": [ "policyService" ]
|
||||
},
|
||||
{
|
||||
"type": "decorator",
|
||||
"provides": "viewService",
|
||||
"implementation": "PolicyViewDecorator.js",
|
||||
"depends": [ "policyService" ]
|
||||
},
|
||||
{
|
||||
"type": "provider",
|
||||
"provides": "policyService",
|
||||
|
@ -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;
|
||||
}
|
||||
);
|
@ -54,7 +54,7 @@ define(
|
||||
it("provides views from its decorated view service", function () {
|
||||
// Mock policy service allows everything by default,
|
||||
// so everything should be returned
|
||||
expect(decorator.getActions(mockDomainObject))
|
||||
expect(decorator.getViews(mockDomainObject))
|
||||
.toEqual(testViews);
|
||||
});
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user