extension action handle access type

This commit is contained in:
Mo Bitar
2017-05-04 00:19:57 -05:00
parent bd54cf12b4
commit 4a4c493fd1
2 changed files with 25 additions and 3 deletions

View File

@@ -14,7 +14,9 @@ class ContextualExtensionsMenu {
$scope.renderData = {};
$scope.extensions = _.map(extensionManager.extensionsInContextOfItem($scope.item), function(ext){
return _.cloneDeep(ext);
// why are we cloning deep?
// return _.cloneDeep(ext);
return ext;
});
for(let ext of $scope.extensions) {
@@ -25,6 +27,10 @@ class ContextualExtensionsMenu {
}
$scope.executeAction = function(action, extension) {
if(!$scope.isActionEnabled(action, extension)) {
alert("This action requires " + action.access_type + " access to this note. You can change this setting in the Extensions menu on the bottom of the app.");
return;
}
if(action.verb == "nested") {
action.showNestedActions = !action.showNestedActions;
return;
@@ -52,6 +58,18 @@ class ContextualExtensionsMenu {
}
}
$scope.isActionEnabled = function(action, extension) {
if(action.access_type) {
var extEncryptedAccess = extensionManager.extensionUsesEncryptedData(extension);
if(action.access_type == "decrypted" && extEncryptedAccess) {
return false;
} else if(action.access_type == "encrypted" && !extEncryptedAccess) {
return false;
}
}
return true;
}
$scope.accessTypeForExtension = function(extension) {
return extensionManager.extensionUsesEncryptedData(extension) ? "encrypted" : "decrypted";
}