[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:
@@ -35,6 +35,16 @@ define(
|
|||||||
*/
|
*/
|
||||||
function MessagesViewPolicy() {
|
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 {
|
return {
|
||||||
/**
|
/**
|
||||||
* Check whether or not a given action is allowed by this
|
* Check whether or not a given action is allowed by this
|
||||||
@@ -47,12 +57,10 @@ define(
|
|||||||
// This policy only applies for the Messages view
|
// This policy only applies for the Messages view
|
||||||
if (view.key === 'messages') {
|
if (view.key === 'messages') {
|
||||||
// The Messages view is allowed only if the domain
|
// The Messages view is allowed only if the domain
|
||||||
// object is a Event Message Generator
|
// object has string telemetry
|
||||||
if (domainObject.getModel().type !== 'eventGenerator') {
|
if (!hasStringTelemetry(domainObject)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: This may later apply to more types beyond just eventGenerator.
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Like all policies, allow by default.
|
// Like all policies, allow by default.
|
||||||
|
|||||||
@@ -32,6 +32,7 @@ define(
|
|||||||
describe("The messages view policy", function () {
|
describe("The messages view policy", function () {
|
||||||
var mockDomainObject,
|
var mockDomainObject,
|
||||||
testType,
|
testType,
|
||||||
|
telemetryType,
|
||||||
policy;
|
policy;
|
||||||
|
|
||||||
beforeEach(function () {
|
beforeEach(function () {
|
||||||
@@ -42,18 +43,18 @@ define(
|
|||||||
mockDomainObject.getModel.andCallFake(function (c) {
|
mockDomainObject.getModel.andCallFake(function (c) {
|
||||||
return {type: testType};
|
return {type: testType};
|
||||||
});
|
});
|
||||||
|
|
||||||
policy = new MessagesViewPolicy();
|
policy = new MessagesViewPolicy();
|
||||||
});
|
});
|
||||||
|
|
||||||
it("disallows the message view for non Event Generators", function () {
|
it("disallows the message view for objects without string telemetry", function () {
|
||||||
testType = 'notAnEventGenerator';
|
telemetryType = 'notString';
|
||||||
expect(policy.allow({ key: 'messages' }, mockDomainObject))
|
expect(policy.allow({ key: 'messages' }, mockDomainObject))
|
||||||
.toBeFalsy();
|
.toBeFalsy();
|
||||||
});
|
});
|
||||||
|
|
||||||
it("allows the message view for Event Generators", function () {
|
it("allows the message view for objects with string telemetry", function () {
|
||||||
testType = 'eventGenerator';
|
telemetryType = 'string';
|
||||||
expect(policy.allow({ key: 'messages' }, mockDomainObject))
|
expect(policy.allow({ key: 'messages' }, mockDomainObject))
|
||||||
.toBeTruthy();
|
.toBeTruthy();
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user