Don't import files that didn't decrypt properly
This commit is contained in:
@@ -5,7 +5,7 @@ module.exports = function(grunt) {
|
|||||||
watch: {
|
watch: {
|
||||||
haml: {
|
haml: {
|
||||||
files: ['app/assets/templates/**/*.haml'],
|
files: ['app/assets/templates/**/*.haml'],
|
||||||
tasks: ['newer:haml', 'ngtemplates', 'concat'],
|
tasks: ['newer:haml', 'ngtemplates', 'concat:app', 'babel', 'browserify', 'concat:dist'],
|
||||||
options: {
|
options: {
|
||||||
spawn: false,
|
spawn: false,
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -185,15 +185,24 @@ class AccountMenu {
|
|||||||
$scope.importData.loading = true;
|
$scope.importData.loading = true;
|
||||||
// allow loading indicator to come up with timeout
|
// allow loading indicator to come up with timeout
|
||||||
$timeout(function(){
|
$timeout(function(){
|
||||||
$scope.importJSONData(data, password, function(response){
|
$scope.importJSONData(data, password, function(response, errorCount){
|
||||||
$timeout(function(){
|
$timeout(function(){
|
||||||
$scope.importData.loading = false;
|
$scope.importData.loading = false;
|
||||||
$scope.importData = null;
|
$scope.importData = null;
|
||||||
if(!response) {
|
|
||||||
alert("There was an error importing your data. Please try again.");
|
// Update UI before showing alert
|
||||||
} else {
|
setTimeout(function () {
|
||||||
alert("Your data was successfully imported.")
|
if(!response) {
|
||||||
}
|
alert("There was an error importing your data. Please try again.");
|
||||||
|
} else {
|
||||||
|
if(errorCount > 0) {
|
||||||
|
var message = `Import complete. ${errorCount} items were not imported because there was an error decrypting them. Make sure the password is correct and try again.`;
|
||||||
|
alert(message);
|
||||||
|
} else {
|
||||||
|
alert("Your data was successfully imported.")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}, 10);
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
@@ -225,7 +234,7 @@ class AccountMenu {
|
|||||||
}
|
}
|
||||||
|
|
||||||
$scope.importJSONData = function(data, password, callback) {
|
$scope.importJSONData = function(data, password, callback) {
|
||||||
var onDataReady = function() {
|
var onDataReady = function(errorCount) {
|
||||||
var items = modelManager.mapResponseItemsToLocalModels(data.items);
|
var items = modelManager.mapResponseItemsToLocalModels(data.items);
|
||||||
items.forEach(function(item){
|
items.forEach(function(item){
|
||||||
item.setDirty(true);
|
item.setDirty(true);
|
||||||
@@ -233,7 +242,9 @@ class AccountMenu {
|
|||||||
item.markAllReferencesDirty();
|
item.markAllReferencesDirty();
|
||||||
})
|
})
|
||||||
|
|
||||||
syncManager.sync(callback, {additionalFields: ["created_at", "updated_at"]});
|
syncManager.sync((response) => {
|
||||||
|
callback(response, errorCount);
|
||||||
|
}, {additionalFields: ["created_at", "updated_at"]});
|
||||||
}.bind(this)
|
}.bind(this)
|
||||||
|
|
||||||
if(data.auth_params) {
|
if(data.auth_params) {
|
||||||
@@ -244,8 +255,19 @@ class AccountMenu {
|
|||||||
data.items.forEach(function(item){
|
data.items.forEach(function(item){
|
||||||
item.enc_item_key = null;
|
item.enc_item_key = null;
|
||||||
item.auth_hash = null;
|
item.auth_hash = null;
|
||||||
|
});
|
||||||
|
|
||||||
|
var errorCount = 0;
|
||||||
|
// Don't import items that didn't decrypt properly
|
||||||
|
data.items = data.items.filter(function(item){
|
||||||
|
if(item.errorDecrypting) {
|
||||||
|
errorCount++;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
})
|
})
|
||||||
onDataReady();
|
|
||||||
|
onDataReady(errorCount);
|
||||||
}
|
}
|
||||||
catch (e) {
|
catch (e) {
|
||||||
console.log("Error decrypting", e);
|
console.log("Error decrypting", e);
|
||||||
|
|||||||
@@ -35,7 +35,6 @@ angular.module('app.frontend')
|
|||||||
}
|
}
|
||||||
|
|
||||||
items = items || [];
|
items = items || [];
|
||||||
console.log("Sorting", items.length, "items");
|
|
||||||
return items.sort(function(a, b){
|
return items.sort(function(a, b){
|
||||||
return sortValueFn(a, b);
|
return sortValueFn(a, b);
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -149,7 +149,7 @@
|
|||||||
%input{"type" => "radio", "ng-model" => "archiveFormData.encrypted", "ng-value" => "false", "ng-change" => "archiveFormData.encrypted = false"}
|
%input{"type" => "radio", "ng-model" => "archiveFormData.encrypted", "ng-value" => "false", "ng-change" => "archiveFormData.encrypted = false"}
|
||||||
Decrypted
|
Decrypted
|
||||||
|
|
||||||
%a.block.mt-5{"ng-click" => "downloadDataArchive()", "ng-class" => "{'mt-5' : !user}"} Download Data Archive
|
%a.block.mt-5{"ng-click" => "downloadDataArchive()", "ng-class" => "{'mt-5' : !user}"} Export Data Archive
|
||||||
|
|
||||||
%label.block.mt-5
|
%label.block.mt-5
|
||||||
%input{"type" => "file", "style" => "display: none;", "file-change" => "->", "handler" => "importFileSelected(files)"}
|
%input{"type" => "file", "style" => "display: none;", "file-change" => "->", "handler" => "importFileSelected(files)"}
|
||||||
|
|||||||
Reference in New Issue
Block a user