From da8b31533af540592a4b7a0d1dac9e44f6ca179d Mon Sep 17 00:00:00 2001 From: Kyle Spearrin Date: Wed, 12 Apr 2017 16:41:31 -0400 Subject: [PATCH] export data fixes due to api cahnges --- src/app/services/cipherService.js | 6 ----- src/app/tools/toolsExportController.js | 31 +++++++++++++++++++++----- 2 files changed, 26 insertions(+), 11 deletions(-) diff --git a/src/app/services/cipherService.js b/src/app/services/cipherService.js index f61f1186d4..ed54988f2d 100644 --- a/src/app/services/cipherService.js +++ b/src/app/services/cipherService.js @@ -37,12 +37,6 @@ angular notes: encryptedLogin.Notes && encryptedLogin.Notes !== '' ? cryptoService.decrypt(encryptedLogin.Notes, key) : null }; - if (encryptedLogin.Folder) { - login.folder = { - name: cryptoService.decrypt(encryptedLogin.Folder.Name) - }; - } - return login; }; diff --git a/src/app/tools/toolsExportController.js b/src/app/tools/toolsExportController.js index 4a2e3cfad7..b91dd3dc52 100644 --- a/src/app/tools/toolsExportController.js +++ b/src/app/tools/toolsExportController.js @@ -5,19 +5,40 @@ $analytics.eventTrack('toolsExportController', { category: 'Modal' }); $scope.export = function (model) { $scope.startedExport = true; - apiService.logins.list({ expand: ['folder'] }, function (logins) { - try { - var decLogins = cipherService.decryptLogins(logins.Data); + var decLogins = [], + decFolders = []; + var folderPromise = apiService.folders.list({}, function (folders) { + decFolders = cipherService.decryptFolders(folders.Data); + }).$promise; + + var loginsPromise = apiService.logins.list({}, function (logins) { + decLogins = cipherService.decryptLogins(logins.Data); + }).$promise; + + $q.all([folderPromise, loginsPromise]).then(function () { + if (!decLogins.length) { + toastr.error('Nothing to export.', 'Error!'); + $scope.close(); + return; + } + + var foldersDict = {}; + for (var i = 0; i < decFolders.length; i++) { + foldersDict[decFolders[i].id] = decFolders[i]; + } + + try { var exportLogins = []; - for (var i = 0; i < decLogins.length; i++) { + for (i = 0; i < decLogins.length; i++) { var login = { name: decLogins[i].name, uri: decLogins[i].uri, username: decLogins[i].username, password: decLogins[i].password, notes: decLogins[i].notes, - folder: decLogins[i].folder ? decLogins[i].folder.name : null, + folder: decLogins[i].folderId && (decLogins[i].folderId in foldersDict) ? + foldersDict[decLogins[i].folderId].name : null, favorite: decLogins[i].favorite ? 1 : null };