[Events] More general view policy

The Messages view policy now will allow any object
that has a telemetry type of string to have access
to the Messages view, not just Event List
Generators. (The test for this still does not work
though.) #18.
This commit is contained in:
Sarah Hale 2015-06-24 17:05:14 -07:00
parent fd81c5c859
commit 203de023d2
2 changed files with 18 additions and 9 deletions

View File

@ -35,6 +35,16 @@ define(
*/
function MessagesViewPolicy() {
function hasStringTelemetry(domainObject) {
var telemetry = domainObject &&
domainObject.getCapability('telemetry'),
metadata = telemetry ? telemetry.getMetadata() : {},
ranges = metadata.ranges || [];
return ranges.some(function (range) {
return range.format === 'string';
});
}
return {
/**
* Check whether or not a given action is allowed by this
@ -47,12 +57,10 @@ define(
// This policy only applies for the Messages view
if (view.key === 'messages') {
// The Messages view is allowed only if the domain
// object is a Event Message Generator
if (domainObject.getModel().type !== 'eventGenerator') {
// object has string telemetry
if (!hasStringTelemetry(domainObject)) {
return false;
}
// TODO: This may later apply to more types beyond just eventGenerator.
}
// Like all policies, allow by default.

View File

@ -32,6 +32,7 @@ define(
describe("The messages view policy", function () {
var mockDomainObject,
testType,
telemetryType,
policy;
beforeEach(function () {
@ -42,18 +43,18 @@ define(
mockDomainObject.getModel.andCallFake(function (c) {
return {type: testType};
});
policy = new MessagesViewPolicy();
});
it("disallows the message view for non Event Generators", function () {
testType = 'notAnEventGenerator';
it("disallows the message view for objects without string telemetry", function () {
telemetryType = 'notString';
expect(policy.allow({ key: 'messages' }, mockDomainObject))
.toBeFalsy();
});
it("allows the message view for Event Generators", function () {
testType = 'eventGenerator';
it("allows the message view for objects with string telemetry", function () {
telemetryType = 'string';
expect(policy.allow({ key: 'messages' }, mockDomainObject))
.toBeTruthy();
});