[Policy] Add example of usage

Add example showing usage of policy, WTD-973.
This commit is contained in:
Victor Woeltjen 2015-04-01 15:18:20 -07:00
parent 84634f03ed
commit 00551779fb
2 changed files with 38 additions and 0 deletions

View File

@ -0,0 +1,12 @@
{
"name": "Example Policy",
"description": "Provides an example of using policies to prohibit actions.",
"extensions": {
"policies": [
{
"implementation": "ExamplePolicy.js",
"category": "action"
}
]
}
}

View File

@ -0,0 +1,26 @@
/*global define*/
define(
[],
function () {
"use strict";
function ExamplePolicy() {
return {
/**
* Disallow the Remove action on objects whose name contains
* "foo."
*/
allow: function (action, context) {
var domainObject = (context || {}).domainObject,
model = (domainObject && domainObject.getModel()) || {},
name = model.name || "",
metadata = action.getMetadata() || {};
return metadata.key !== 'remove' || name.indexOf('foo') < 0;
}
};
}
return ExamplePolicy;
}
);