[Containment] Add general policy for containment rules

Add general policy for supporting containment rules, WTD-962.
This commit is contained in:
Victor Woeltjen
2015-04-07 19:58:39 -07:00
parent 3c3dd0ad17
commit 3c00eb86ea
4 changed files with 182 additions and 0 deletions

View File

@ -0,0 +1,53 @@
/*global define*/
define(
[],
function () {
"use strict";
/**
* Build a table indicating which types are expected to expose
* which capabilities.
*/
function CapabilityTable(typeService, capabilityService) {
var table = {};
// Build an initial model for a type
function buildModel(type) {
var model = Object.create(type.getInitialModel() || {});
model.type = type.getKey();
return model;
}
// Get capabilities expected for this type
function getCapabilities(type) {
return capabilityService.getCapabilities(buildModel(type));
}
// Populate the lookup table for this type's capabilities
function addToTable(type) {
var typeKey = type.getKey();
Object.keys(getCapabilities(type)).forEach(function (key) {
table[key] = table[key] || {};
table[key][typeKey] = true;
});
}
// Build the table
(typeService.listTypes() || []).forEach(addToTable);
return {
/**
* Check if a type is expected to expose a specific
* capability.
*/
hasCapability: function (typeKey, capabilityKey) {
return (table[capabilityKey] || {})[typeKey];
}
};
}
return CapabilityTable;
}
);