diff --git a/example/policy/bundle.json b/example/policy/bundle.json new file mode 100644 index 0000000000..cec350ffd0 --- /dev/null +++ b/example/policy/bundle.json @@ -0,0 +1,12 @@ +{ + "name": "Example Policy", + "description": "Provides an example of using policies to prohibit actions.", + "extensions": { + "policies": [ + { + "implementation": "ExamplePolicy.js", + "category": "action" + } + ] + } +} \ No newline at end of file diff --git a/example/policy/src/ExamplePolicy.js b/example/policy/src/ExamplePolicy.js new file mode 100644 index 0000000000..ba9fd68812 --- /dev/null +++ b/example/policy/src/ExamplePolicy.js @@ -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; + } +); \ No newline at end of file