mirror of
https://github.com/nasa/openmct.git
synced 2025-06-15 21:58:13 +00:00
[Policy] Add example of usage
Add example showing usage of policy, WTD-973.
This commit is contained in:
26
example/policy/src/ExamplePolicy.js
Normal file
26
example/policy/src/ExamplePolicy.js
Normal 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;
|
||||
}
|
||||
);
|
Reference in New Issue
Block a user