Extension save decrypted status, fix remote load issue
This commit is contained in:
@@ -52,15 +52,15 @@ class Extension extends Item {
|
||||
constructor(json) {
|
||||
super(json);
|
||||
_.merge(this, json);
|
||||
|
||||
this.encrypted = true;
|
||||
this.content_type = "Extension";
|
||||
|
||||
if(json.actions) {
|
||||
this.actions = json.actions.map(function(action){
|
||||
return new Action(action);
|
||||
})
|
||||
}
|
||||
|
||||
if(!this.actions) {
|
||||
this.actions = [];
|
||||
}
|
||||
}
|
||||
|
||||
actionsInGlobalContext() {
|
||||
@@ -80,34 +80,37 @@ class Extension extends Item {
|
||||
this.name = contentObject.name;
|
||||
this.description = contentObject.description;
|
||||
this.url = contentObject.url;
|
||||
|
||||
if(contentObject.encrypted !== null && contentObject.encrypted !== undefined) {
|
||||
this.encrypted = contentObject.encrypted;
|
||||
} else {
|
||||
this.encrypted = true;
|
||||
}
|
||||
|
||||
this.supported_types = contentObject.supported_types;
|
||||
if(contentObject.actions) {
|
||||
this.actions = contentObject.actions.map(function(action){
|
||||
return new Action(action);
|
||||
})
|
||||
} else {
|
||||
this.actions = [];
|
||||
}
|
||||
}
|
||||
|
||||
updateFromExternalResponseItem(externalResponseItem) {
|
||||
_.merge(this, externalResponseItem);
|
||||
this.actions = externalResponseItem.actions.map(function(action){
|
||||
return new Action(action);
|
||||
})
|
||||
}
|
||||
|
||||
referenceParams() {
|
||||
return null;
|
||||
}
|
||||
|
||||
get content_type() {
|
||||
return "Extension";
|
||||
}
|
||||
|
||||
structureParams() {
|
||||
var params = {
|
||||
name: this.name,
|
||||
url: this.url,
|
||||
description: this.description,
|
||||
actions: this.actions,
|
||||
supported_types: this.supported_types
|
||||
supported_types: this.supported_types,
|
||||
encrypted: this.encrypted
|
||||
};
|
||||
|
||||
_.merge(params, super.structureParams());
|
||||
|
||||
@@ -66,7 +66,7 @@ class ContextualExtensionsMenu {
|
||||
|
||||
$scope.isActionEnabled = function(action, extension) {
|
||||
if(action.access_type) {
|
||||
var extEncryptedAccess = extensionManager.extensionUsesEncryptedData(extension);
|
||||
var extEncryptedAccess = extension.encrypted;
|
||||
if(action.access_type == "decrypted" && extEncryptedAccess) {
|
||||
return false;
|
||||
} else if(action.access_type == "encrypted" && !extEncryptedAccess) {
|
||||
@@ -77,7 +77,7 @@ class ContextualExtensionsMenu {
|
||||
}
|
||||
|
||||
$scope.accessTypeForExtension = function(extension) {
|
||||
return extensionManager.extensionUsesEncryptedData(extension) ? "encrypted" : "decrypted";
|
||||
return extension.encrypted ? "encrypted" : "decrypted";
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -32,7 +32,9 @@ class GlobalExtensionsMenu {
|
||||
}
|
||||
|
||||
$scope.changeExtensionEncryptionFormat = function(encrypted, extension) {
|
||||
extensionManager.changeExtensionEncryptionFormat(encrypted, extension);
|
||||
extension.encrypted = encrypted;
|
||||
extension.setDirty(true);
|
||||
syncManager.sync();
|
||||
}
|
||||
|
||||
$scope.deleteActionExtension = function(extension) {
|
||||
|
||||
@@ -5,15 +5,11 @@ class ExtensionManager {
|
||||
this.modelManager = modelManager;
|
||||
this.authManager = authManager;
|
||||
this.enabledRepeatActionUrls = JSON.parse(storageManager.getItem("enabledRepeatActionUrls")) || [];
|
||||
this.decryptedExtensions = JSON.parse(storageManager.getItem("decryptedExtensions")) || [];
|
||||
this.syncManager = syncManager;
|
||||
this.storageManager = storageManager;
|
||||
|
||||
modelManager.addItemSyncObserver("extensionManager", "Extension", function(items){
|
||||
for (var ext of items) {
|
||||
|
||||
ext.encrypted = this.extensionUsesEncryptedData(ext);
|
||||
|
||||
for (var action of ext.actions) {
|
||||
if(_.includes(this.enabledRepeatActionUrls, action.url)) {
|
||||
this.enableRepeatAction(action, ext);
|
||||
@@ -39,29 +35,12 @@ class ExtensionManager {
|
||||
}
|
||||
}
|
||||
|
||||
extensionUsesEncryptedData(extension) {
|
||||
return !_.includes(this.decryptedExtensions, extension.url);
|
||||
}
|
||||
|
||||
changeExtensionEncryptionFormat(encrypted, extension) {
|
||||
if(encrypted) {
|
||||
_.pull(this.decryptedExtensions, extension.url);
|
||||
} else {
|
||||
this.decryptedExtensions.push(extension.url);
|
||||
}
|
||||
|
||||
this.storageManager.setItem("decryptedExtensions", JSON.stringify(this.decryptedExtensions))
|
||||
|
||||
extension.encrypted = this.extensionUsesEncryptedData(extension);
|
||||
}
|
||||
|
||||
addExtension(url, callback) {
|
||||
this.retrieveExtensionFromServer(url, callback);
|
||||
}
|
||||
|
||||
deleteExtension(extension) {
|
||||
for(var action of extension.actions) {
|
||||
_.pull(this.decryptedExtensions, extension);
|
||||
if(action.repeat_mode) {
|
||||
if(this.isRepeatActionEnabled(action)) {
|
||||
this.disableRepeatAction(action);
|
||||
@@ -80,18 +59,10 @@ class ExtensionManager {
|
||||
loadExtensionInContextOfItem(extension, item, callback) {
|
||||
|
||||
this.httpManager.getAbsolute(extension.url, {content_type: item.content_type, item_uuid: item.uuid}, function(response){
|
||||
var scopedExtension = new Extension(response);
|
||||
if(scopedExtension) {
|
||||
_.merge(extension, scopedExtension);
|
||||
extension.actions = scopedExtension.actions;
|
||||
extension.encrypted = this.extensionUsesEncryptedData(extension);
|
||||
}
|
||||
if(callback) {
|
||||
callback(scopedExtension);
|
||||
}
|
||||
this.updateExtensionFromRemoteResponse(extension, response);
|
||||
callback && callback(extension);
|
||||
}.bind(this), function(response){
|
||||
console.log("Error loading extension", response);
|
||||
extension.encrypted = this.extensionUsesEncryptedData(extension);
|
||||
if(callback) {
|
||||
callback(null);
|
||||
}
|
||||
@@ -120,7 +91,7 @@ class ExtensionManager {
|
||||
handleExtensionLoadExternalResponseItem(url, externalResponseItem) {
|
||||
var extension = _.find(this.extensions, {url: url});
|
||||
if(extension) {
|
||||
extension.updateFromExternalResponseItem(externalResponseItem);
|
||||
this.updateExtensionFromRemoteResponse(extension, externalResponseItem);
|
||||
} else {
|
||||
extension = new Extension(externalResponseItem);
|
||||
extension.url = url;
|
||||
@@ -132,6 +103,26 @@ class ExtensionManager {
|
||||
return extension;
|
||||
}
|
||||
|
||||
updateExtensionFromRemoteResponse(extension, response) {
|
||||
// Don't allow remote response to set these flags
|
||||
delete response.encrypted;
|
||||
delete response.uuid;
|
||||
|
||||
if(response.name) {
|
||||
extension.name = response.name;
|
||||
}
|
||||
if(response.description) {
|
||||
extension.description = response.description;
|
||||
}
|
||||
if(response.supported_types) {
|
||||
extension.supported_types = response.supported_types;
|
||||
}
|
||||
|
||||
extension.actions = response.actions.map(function(action){
|
||||
return new Action(action);
|
||||
})
|
||||
}
|
||||
|
||||
refreshExtensionsFromServer() {
|
||||
for (var url of this.enabledRepeatActionUrls) {
|
||||
var action = this.actionWithURL(url);
|
||||
@@ -149,7 +140,7 @@ class ExtensionManager {
|
||||
|
||||
executeAction(action, extension, item, callback) {
|
||||
|
||||
if(this.extensionUsesEncryptedData(extension) && this.authManager.offline()) {
|
||||
if(extension.encrypted && this.userManager.offline()) {
|
||||
alert("To send data encrypted, you must have an encryption key, and must therefore be signed in.");
|
||||
callback(null);
|
||||
return;
|
||||
@@ -274,11 +265,9 @@ class ExtensionManager {
|
||||
return;
|
||||
}
|
||||
|
||||
// console.log("Successfully queued", action, this.actionQueue.length);
|
||||
this.actionQueue.push(action);
|
||||
|
||||
setTimeout(function () {
|
||||
// console.log("Performing queued action", action);
|
||||
this.triggerWatchAction(action, extension, changedItems);
|
||||
_.pull(this.actionQueue, action);
|
||||
}.bind(this), delay * 1000);
|
||||
@@ -297,8 +286,6 @@ class ExtensionManager {
|
||||
|
||||
action.lastExecuted = new Date();
|
||||
|
||||
console.log("Performing action.");
|
||||
|
||||
if(action.verb == "post") {
|
||||
var params = {};
|
||||
params.items = changedItems.map(function(item){
|
||||
@@ -316,8 +303,8 @@ class ExtensionManager {
|
||||
}
|
||||
|
||||
outgoingParamsForItem(item, extension) {
|
||||
var keys = this.authManager.keys();
|
||||
if(!this.extensionUsesEncryptedData(extension)) {
|
||||
var keys = this.userManager.keys();
|
||||
if(!extension.encrypted) {
|
||||
keys = null;
|
||||
}
|
||||
var itemParams = new ItemParams(item, keys, this.authManager.protocolVersion());
|
||||
@@ -326,8 +313,8 @@ class ExtensionManager {
|
||||
|
||||
performPost(action, extension, params, callback) {
|
||||
|
||||
if(this.extensionUsesEncryptedData(extension)) {
|
||||
params.auth_params = this.authManager.getAuthParams();
|
||||
if(extension.encrypted) {
|
||||
params.auth_params = this.userManager.getAuthParams();
|
||||
}
|
||||
|
||||
this.httpManager.postAbsolute(action.url, params, function(response){
|
||||
|
||||
@@ -31,6 +31,7 @@ class ModelManager {
|
||||
}
|
||||
|
||||
alternateUUIDForItem(item, callback) {
|
||||
console.log("Alternating uuid for item", item);
|
||||
// we need to clone this item and give it a new uuid, then delete item with old uuid from db (you can't mofidy uuid's in our indexeddb setup)
|
||||
var newItem = this.createItem(item);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user