[Edit] Add policy to restrict views in Edit mode

Add policy to disallow views in Edit mode which have been
explicitly flagged as non-editable, WTD-1062.
This commit is contained in:
Victor Woeltjen 2015-04-01 15:50:15 -07:00
parent ccf2ccc4c6
commit facf350648

View File

@ -0,0 +1,36 @@
/*global define*/
define(
[],
function () {
"use strict";
/**
* Policy controlling which views should be visible in Edit mode.
* @constructor
*/
function EditableViewPolicy() {
return {
/**
* Check whether or not a given action is allowed by this
* policy.
* @param {Action} action the action
* @param domainObject the domain object which will be viewed
* @returns {boolean} true if not disallowed
*/
allow: function (view, domainObject) {
// If a view is flagged as non-editable, only allow it
// while we're not in Edit mode.
if ((view || {}).editable === false) {
return !domainObject.hasCapability('editor');
}
// Like all policies, allow by default.
return true;
}
};
}
return EditableViewPolicy;
}
);