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