Compare commits

...

3 Commits

Author SHA1 Message Date
f62f460f52 Merge branch 'master' of https://github.com/nasa/openmct into issue#1542 2018-05-03 10:30:09 -07:00
4bc5e574f2 fix style 2018-04-25 13:49:27 -07:00
40db47bcdc partially fixes #1542
Add Action Policy to disallow remove action on non editable objects
2018-04-25 13:44:34 -07:00
2 changed files with 68 additions and 0 deletions

View File

@ -38,6 +38,7 @@ define([
"./src/policies/EditableLinkPolicy",
"./src/policies/EditableMovePolicy",
"./src/policies/EditContextualActionPolicy",
"./src/policies/RemoveActionPolicy",
"./src/representers/EditRepresenter",
"./src/representers/EditToolbarRepresenter",
"./src/capabilities/EditorCapability",
@ -77,6 +78,7 @@ define([
EditableLinkPolicy,
EditableMovePolicy,
EditContextualActionPolicy,
RemoveActionPolicy,
EditRepresenter,
EditToolbarRepresenter,
EditorCapability,
@ -268,6 +270,10 @@ define([
"category": "action",
"implementation": EditableLinkPolicy
},
{
"category": "action",
"implementation": RemoveActionPolicy
},
{
"implementation": CreationPolicy,
"category": "creation"

View File

@ -0,0 +1,62 @@
/*****************************************************************************
* Open MCT, Copyright (c) 2014-2017, United States Government
* as represented by the Administrator of the National Aeronautics and Space
* Administration. All rights reserved.
*
* Open MCT is licensed under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* http://www.apache.org/licenses/LICENSE-2.0.
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations
* under the License.
*
* Open MCT includes source code licensed under additional open source
* licenses. See the Open Source Licenses file (LICENSES.md) included with
* this source code distribution or the Licensing information page available
* at runtime from the About dialog for additional information.
*****************************************************************************/
/*global define*/
define(
[],
function () {
function RemoveActionPolicy() {
function isAnyViewEditable(views) {
var isEditable = false;
views.forEach(function (view) {
if (view.editable) {
isEditable = true;
return;
}
});
return isEditable;
}
return {
/**
* Disallow the Remove action on objects that are not editable
*/
allow: function (action, context) {
var domainObject = (context || {}).domainObject,
views = domainObject.useCapability('view'),
metadata = action.getMetadata() || {};
if (metadata.key === 'remove') {
return isAnyViewEditable(views);
}
return true;
}
};
}
return RemoveActionPolicy;
}
);