mirror of
https://github.com/nasa/openmct.git
synced 2025-06-17 06:38:17 +00:00
[Code Style] Use prototypes in policy bundle
WTD-1482.
This commit is contained in:
@ -33,28 +33,24 @@ define(
|
|||||||
* @param {ActionService} actionService the service to decorate
|
* @param {ActionService} actionService the service to decorate
|
||||||
* @constructor
|
* @constructor
|
||||||
* @memberof platform/policy
|
* @memberof platform/policy
|
||||||
|
* @implements {ActionService}
|
||||||
*/
|
*/
|
||||||
function PolicyActionDecorator(policyService, actionService) {
|
function PolicyActionDecorator(policyService, actionService) {
|
||||||
return {
|
this.policyService = policyService;
|
||||||
/**
|
this.actionService = actionService;
|
||||||
* Get actions which are applicable in this context.
|
}
|
||||||
* These will be filtered to remove any actions which
|
|
||||||
* are deemed inapplicable by policy.
|
PolicyActionDecorator.prototype.getActions = function (context) {
|
||||||
* @param context the context in which the action will occur
|
var policyService = this.policyService;
|
||||||
* @returns {Action[]} applicable actions
|
|
||||||
* @memberof platform/policy.PolicyActionDecorator#
|
|
||||||
*/
|
|
||||||
getActions: function (context) {
|
|
||||||
// Check if an action is allowed by policy.
|
// Check if an action is allowed by policy.
|
||||||
function allow(action) {
|
function allow(action) {
|
||||||
return policyService.allow('action', action, context);
|
return policyService.allow('action', action, context);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Look up actions, filter out the disallowed ones.
|
// Look up actions, filter out the disallowed ones.
|
||||||
return actionService.getActions(context).filter(allow);
|
return this.actionService.getActions(context).filter(allow);
|
||||||
}
|
|
||||||
};
|
};
|
||||||
}
|
|
||||||
|
|
||||||
return PolicyActionDecorator;
|
return PolicyActionDecorator;
|
||||||
}
|
}
|
||||||
|
@ -53,12 +53,37 @@ define(
|
|||||||
* @returns {boolean} false if disallowed; otherwise, true
|
* @returns {boolean} false if disallowed; otherwise, true
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The `policyService` handles decisions about what things
|
||||||
|
* are and are not allowed in certain contexts.
|
||||||
|
* @interface PolicyService
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Check whether or not a certain decision is allowed by
|
||||||
|
* policy.
|
||||||
|
* @param {string} category a machine-readable identifier
|
||||||
|
* for the kind of decision being made
|
||||||
|
* @param candidate the object about which the decision is
|
||||||
|
* being made
|
||||||
|
* @param context the context in which the decision occurs
|
||||||
|
* @param {Function} [callback] callback to invoke with a
|
||||||
|
* string message describing the reason a decision
|
||||||
|
* was disallowed (if its disallowed)
|
||||||
|
* @returns {boolean} true if the decision is allowed,
|
||||||
|
* otherwise false.
|
||||||
|
* @method PolicyService#allow
|
||||||
|
*/
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Provides an implementation of `policyService` which consults
|
* Provides an implementation of `policyService` which consults
|
||||||
* various policy extensions to determine whether or not a specific
|
* various policy extensions to determine whether or not a specific
|
||||||
* decision should be allowed.
|
* decision should be allowed.
|
||||||
* @memberof platform/policy
|
* @memberof platform/policy
|
||||||
* @constructor
|
* @constructor
|
||||||
|
* @implements {PolicyService}
|
||||||
|
* @param {Policy[]} policies the policies to enforce
|
||||||
*/
|
*/
|
||||||
function PolicyProvider(policies) {
|
function PolicyProvider(policies) {
|
||||||
var policyMap = {};
|
var policyMap = {};
|
||||||
@ -87,25 +112,11 @@ define(
|
|||||||
|
|
||||||
// Populate the map for subsequent lookup
|
// Populate the map for subsequent lookup
|
||||||
policies.forEach(addToMap);
|
policies.forEach(addToMap);
|
||||||
|
this.policyMap = policyMap;
|
||||||
|
}
|
||||||
|
|
||||||
return {
|
PolicyProvider.prototype.allow = function (category, candidate, context, callback) {
|
||||||
/**
|
var policyList = this.policyMap[category] || [],
|
||||||
* Check whether or not a certain decision is allowed by
|
|
||||||
* policy.
|
|
||||||
* @param {string} category a machine-readable identifier
|
|
||||||
* for the kind of decision being made
|
|
||||||
* @param candidate the object about which the decision is
|
|
||||||
* being made
|
|
||||||
* @param context the context in which the decision occurs
|
|
||||||
* @param {Function} [callback] callback to invoke with a
|
|
||||||
* string message describing the reason a decision
|
|
||||||
* was disallowed (if its disallowed)
|
|
||||||
* @returns {boolean} true if the decision is allowed,
|
|
||||||
* otherwise false.
|
|
||||||
* @memberof platform/policy.PolicyProvider#
|
|
||||||
*/
|
|
||||||
allow: function (category, candidate, context, callback) {
|
|
||||||
var policyList = policyMap[category] || [],
|
|
||||||
i;
|
i;
|
||||||
|
|
||||||
// Iterate through policies. We do this instead of map or
|
// Iterate through policies. We do this instead of map or
|
||||||
@ -126,9 +137,7 @@ define(
|
|||||||
|
|
||||||
// No policy disallowed this decision.
|
// No policy disallowed this decision.
|
||||||
return true;
|
return true;
|
||||||
}
|
|
||||||
};
|
};
|
||||||
}
|
|
||||||
|
|
||||||
return PolicyProvider;
|
return PolicyProvider;
|
||||||
}
|
}
|
||||||
|
@ -33,29 +33,25 @@ define(
|
|||||||
* @param {ViewService} viewService the service to decorate
|
* @param {ViewService} viewService the service to decorate
|
||||||
* @constructor
|
* @constructor
|
||||||
* @memberof platform/policy
|
* @memberof platform/policy
|
||||||
|
* @implements {ViewService}
|
||||||
*/
|
*/
|
||||||
function PolicyActionDecorator(policyService, viewService) {
|
function PolicyViewDecorator(policyService, viewService) {
|
||||||
return {
|
this.policyService = policyService;
|
||||||
/**
|
this.viewService = viewService;
|
||||||
* Get views which are applicable to this domain object.
|
}
|
||||||
* These will be filtered to remove any views which
|
|
||||||
* are deemed inapplicable by policy.
|
PolicyViewDecorator.prototype.getViews = function (domainObject) {
|
||||||
* @param {DomainObject} the domain object to view
|
var policyService = this.policyService;
|
||||||
* @returns {View[]} applicable views
|
|
||||||
* @memberof platform/policy.PolicyViewDecorator#
|
|
||||||
*/
|
|
||||||
getViews: function (domainObject) {
|
|
||||||
// Check if an action is allowed by policy.
|
// Check if an action is allowed by policy.
|
||||||
function allow(view) {
|
function allow(view) {
|
||||||
return policyService.allow('view', view, domainObject);
|
return policyService.allow('view', view, domainObject);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Look up actions, filter out the disallowed ones.
|
// Look up actions, filter out the disallowed ones.
|
||||||
return viewService.getViews(domainObject).filter(allow);
|
return this.viewService.getViews(domainObject).filter(allow);
|
||||||
}
|
|
||||||
};
|
};
|
||||||
}
|
|
||||||
|
|
||||||
return PolicyActionDecorator;
|
return PolicyViewDecorator;
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
Reference in New Issue
Block a user