mirror of
https://github.com/nasa/openmct.git
synced 2024-12-19 05:07:52 +00:00
[Policy] Add example of usage
Add example showing usage of policy, WTD-973.
This commit is contained in:
parent
84634f03ed
commit
00551779fb
12
example/policy/bundle.json
Normal file
12
example/policy/bundle.json
Normal 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"
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
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;
|
||||
}
|
||||
);
|
Loading…
Reference in New Issue
Block a user