[LinkService] Reorder/refactor validation

Reoder validation to consider the composition capability
first; refactor to express as a single expression to clarify
validation logic (explicitly say 'and' instead of implying
it with control flow.)

Based on feedback from nasa/openmctweb#98
This commit is contained in:
Victor Woeltjen 2015-09-22 13:37:56 -07:00
parent 3310016264
commit c17269ba8b

View File

@ -39,20 +39,17 @@ define(
}
LinkService.prototype.validate = function (object, parentCandidate) {
if (!parentCandidate || !parentCandidate.getId) {
return false;
}
if (parentCandidate.getId() === object.getId()) {
return false;
}
if ((parentCandidate.getModel().composition || []).indexOf(object.getId()) !== -1) {
return false;
}
return this.policyService.allow(
"composition",
parentCandidate.getCapability('type'),
object.getCapability('type')
) && parentCandidate.hasCapability('composition');
var objectId = object.getId();
return !!parentCandidate &&
!!parentCandidate.getId &&
parentCandidate.getId() !== objectId &&
parentCandidate.hasCapability("composition") &&
parentCandidate.getModel().composition.indexOf(objectId) === -1 &&
this.policyService.allow(
"composition",
parentCandidate.getCapability('type'),
object.getCapability('type')
);
};
LinkService.prototype.perform = function (object, parentObject) {