From 74eeb1a3c1ae8c4562952e8c1fd6641a5d53b577 Mon Sep 17 00:00:00 2001 From: Kyle Spearrin Date: Wed, 18 Oct 2017 14:56:59 -0400 Subject: [PATCH] fixes from refactors --- src/background.js | 152 ++++++++++-------- .../app/vault/vaultAttachmentsController.js | 20 +-- .../app/vault/views/vaultAttachments.html | 14 +- .../app/vault/views/vaultViewCipher.html | 2 +- src/services/cipherService.js | 4 +- src/services/folderService.js | 2 +- 6 files changed, 103 insertions(+), 91 deletions(-) diff --git a/src/background.js b/src/background.js index 8045e7f3..87fc0456 100644 --- a/src/background.js +++ b/src/background.js @@ -205,29 +205,29 @@ var bg_isBackground = true, return; } - bg_cipherService.getAllDecrypted().then(function (logins) { - for (var i = 0; i < logins.length; i++) { - if (logins[i].id === id) { + bg_cipherService.getAllDecrypted().then(function (ciphers) { + for (var i = 0; i < ciphers.length; i++) { + if (ciphers[i].id === id) { if (info.parentMenuItemId === 'autofill') { ga('send', { hitType: 'event', eventAction: 'Autofilled From Context Menu' }); - startAutofillPage(logins[i]); + startAutofillPage(ciphers[i]); } else if (info.parentMenuItemId === 'copy-username') { ga('send', { hitType: 'event', eventAction: 'Copied Username From Context Menu' }); - bg_utilsService.copyToClipboard(logins[i].username); + bg_utilsService.copyToClipboard(ciphers[i].login.username); } else if (info.parentMenuItemId === 'copy-password') { ga('send', { hitType: 'event', eventAction: 'Copied Password From Context Menu' }); - bg_utilsService.copyToClipboard(logins[i].password); + bg_utilsService.copyToClipboard(ciphers[i].login.password); } return; } @@ -260,16 +260,16 @@ var bg_isBackground = true, if (bg_utilsService.isFirefox()) { return new Promise(function (resolve, reject) { - bg_cipherService.getAllDecryptedForDomain(domain).then(function (logins) { - if (!logins || logins.length !== 1) { + bg_cipherService.getAllDecryptedForDomain(domain).then(function (ciphers) { + if (!ciphers || ciphers.length !== 1) { reject(); return; } resolve({ authCredentials: { - username: logins[0].username, - password: logins[0].password + username: ciphers[0].login.username, + password: ciphers[0].login.password } }); }, function () { @@ -278,16 +278,16 @@ var bg_isBackground = true, }); } else { - bg_cipherService.getAllDecryptedForDomain(domain).then(function (logins) { - if (!logins || logins.length !== 1) { + bg_cipherService.getAllDecryptedForDomain(domain).then(function (ciphers) { + if (!ciphers || ciphers.length !== 1) { callback(); return; } callback({ authCredentials: { - username: logins[0].username, - password: logins[0].password + username: ciphers[0].login.username, + password: ciphers[0].login.password } }); }, function () { @@ -580,16 +580,16 @@ var bg_isBackground = true, }); } - function addLogin(login, tab) { - var loginDomain = bg_utilsService.getDomain(login.url); + function addLogin(loginInfo, tab) { + var loginDomain = bg_utilsService.getDomain(loginInfo.url); if (!loginDomain) { return; } - bg_cipherService.getAllDecryptedForDomain(loginDomain).then(function (logins) { + bg_cipherService.getAllDecryptedForDomain(loginDomain).then(function (ciphers) { var match = false; - for (var i = 0; i < logins.length; i++) { - if (logins[i].username === login.username) { + for (var i = 0; i < ciphers.length; i++) { + if (ciphers[i].login.username === loginInfo.username) { match = true; break; } @@ -600,11 +600,11 @@ var bg_isBackground = true, removeAddLogin(tab); bg_loginsToAdd.push({ - username: login.username, - password: login.password, + username: loginInfo.username, + password: loginInfo.password, name: loginDomain, domain: loginDomain, - uri: login.url, + uri: loginInfo.url, tabId: tab.id, expires: new Date((new Date()).getTime() + 30 * 60000) // 30 minutes }); @@ -633,53 +633,62 @@ var bg_isBackground = true, function saveAddLogin(tab) { for (var i = bg_loginsToAdd.length - 1; i >= 0; i--) { - if (bg_loginsToAdd[i].tabId === tab.id) { - var loginToAdd = bg_loginsToAdd[i]; - - var tabDomain = bg_utilsService.getDomain(tab.url); - if (tabDomain && tabDomain === loginToAdd.domain) { - bg_loginsToAdd.splice(i, 1); - - /* jshint ignore:start */ - bg_cipherService.encrypt({ - id: null, - folderId: null, - favorite: false, - name: loginToAdd.name, - uri: loginToAdd.uri, - username: loginToAdd.username, - password: loginToAdd.password, - notes: null - }).then(function (loginModel) { - var login = new Login(loginModel, true); - bg_cipherService.saveWithServer(login).then(function (login) { - ga('send', { - hitType: 'event', - eventAction: 'Added Login from Notification Bar' - }); - }); - }); - /* jshint ignore:end */ - - messageTab(tab.id, 'closeNotificationBar'); - } + if (bg_loginsToAdd[i].tabId !== tab.id) { + continue; } + + var loginInfo = bg_loginsToAdd[i]; + var tabDomain = bg_utilsService.getDomain(tab.url); + if (tabDomain && tabDomain !== loginInfo.domain) { + continue; + } + + bg_loginsToAdd.splice(i, 1); + + /* jshint ignore:start */ + bg_cipherService.encrypt({ + id: null, + folderId: null, + favorite: false, + name: loginInfo.name, + notes: null, + type: bg_constantsService.cipherType.login, + login: { + uri: loginInfo.uri, + username: loginInfo.username, + password: loginInfo + } + }).then(function (model) { + var cipher = new Cipher(model, true); + return bg_cipherService.saveWithServer(cipher); + }).then(function (login) { + ga('send', { + hitType: 'event', + eventAction: 'Added Login from Notification Bar' + }); + }); + /* jshint ignore:end */ + + messageTab(tab.id, 'closeNotificationBar'); } } function saveNever(tab) { for (var i = bg_loginsToAdd.length - 1; i >= 0; i--) { - if (bg_loginsToAdd[i].tabId === tab.id) { - var loginToAdd = bg_loginsToAdd[i]; - - var tabDomain = bg_utilsService.getDomain(tab.url); - if (tabDomain && tabDomain === loginToAdd.domain) { - bg_loginsToAdd.splice(i, 1); - var hostname = bg_utilsService.getHostname(tab.url); - bg_cipherService.saveNeverDomain(hostname); - messageTab(tab.id, 'closeNotificationBar'); - } + if (bg_loginsToAdd[i].tabId !== tab.id) { + continue; } + + var loginInfo = bg_loginsToAdd[i]; + var tabDomain = bg_utilsService.getDomain(tab.url); + if (tabDomain && tabDomain !== loginInfo.domain) { + continue; + } + + bg_loginsToAdd.splice(i, 1); + var hostname = bg_utilsService.getHostname(tab.url); + bg_cipherService.saveNeverDomain(hostname); + messageTab(tab.id, 'closeNotificationBar'); } } @@ -711,18 +720,20 @@ var bg_isBackground = true, } for (var i = 0; i < bg_loginsToAdd.length; i++) { - if (bg_loginsToAdd[i].tabId === tab.id && bg_loginsToAdd[i].domain === tabDomain) { - messageTab(tab.id, 'openNotificationBar', { - type: 'add' - }, function () { }); - break; + if (bg_loginsToAdd[i].tabId !== tab.id || bg_loginsToAdd[i].domain !== tabDomain) { + continue; } + + messageTab(tab.id, 'openNotificationBar', { + type: 'add' + }, function () { }); + break; } } } - function startAutofillPage(login) { - loginToAutoFill = login; + function startAutofillPage(cipher) { + loginToAutoFill = cipher; chrome.tabs.query({ active: true, currentWindow: true }, function (tabs) { var tab = null; if (tabs.length > 0) { @@ -740,8 +751,7 @@ var bg_isBackground = true, command: 'collectPageDetails', tab: tab, sender: 'contextMenu' - }, function () { - }); + }, function () { }); }); } diff --git a/src/popup/app/vault/vaultAttachmentsController.js b/src/popup/app/vault/vaultAttachmentsController.js index 40384803..c9c9cad0 100644 --- a/src/popup/app/vault/vaultAttachmentsController.js +++ b/src/popup/app/vault/vaultAttachmentsController.js @@ -10,11 +10,11 @@ angular $scope.canAccessAttachments = $scope.isPremium; $scope.hasUpdatedKey = false; - cipherService.get($stateParams.id).then(function (login) { - return login.decrypt(); + cipherService.get($stateParams.id).then(function (cipher) { + return cipher.decrypt(); }).then(function (model) { - $scope.login = model; - $scope.canAccessAttachments = $scope.isPremium || !!$scope.login.organizationId; + $scope.cipher = model; + $scope.canAccessAttachments = $scope.isPremium || !!$scope.cipher.organizationId; if (!$scope.canAccessAttachments) { SweetAlert.swal({ @@ -69,9 +69,9 @@ angular return deferred.promise; } - $scope.submitPromise = cipherService.saveAttachmentWithServer($scope.login, files[0]).then(function (login) { - login.decrypt().then(function (model) { - $scope.login = model; + $scope.submitPromise = cipherService.saveAttachmentWithServer($scope.cipher, files[0]).then(function (cipher) { + cipher.decrypt().then(function (model) { + $scope.cipher = model; }); $analytics.eventTrack('Added Attachment'); toastr.success(i18nService.attachmentSaved); @@ -101,9 +101,9 @@ angular }, function (confirmed) { if (confirmed) { cipherService.deleteAttachmentWithServer($stateParams.id, attachment.id).then(function () { - var index = $scope.login.attachments.indexOf(attachment); + var index = $scope.cipher.attachments.indexOf(attachment); if (index > -1) { - $scope.login.attachments.splice(index, 1); + $scope.cipher.attachments.splice(index, 1); } $analytics.eventTrack('Deleted Attachment'); toastr.success(i18nService.deletedAttachment); @@ -114,7 +114,7 @@ angular $scope.close = function () { $state.go('editCipher', { - loginId: $stateParams.id, + cipherId: $stateParams.id, animation: 'out-slide-down', from: $stateParams.from, fromView: $stateParams.fromView diff --git a/src/popup/app/vault/views/vaultAttachments.html b/src/popup/app/vault/views/vaultAttachments.html index bf03313a..a4c0d137 100644 --- a/src/popup/app/vault/views/vaultAttachments.html +++ b/src/popup/app/vault/views/vaultAttachments.html @@ -13,14 +13,16 @@
-
+
{{i18n.noAttachments}}
-
- - - +
+
+ + + +
{{attachment.sizeName}} {{attachment.fileName}}
diff --git a/src/popup/app/vault/views/vaultViewCipher.html b/src/popup/app/vault/views/vaultViewCipher.html index 6ad47ff9..c91bb9e2 100644 --- a/src/popup/app/vault/views/vaultViewCipher.html +++ b/src/popup/app/vault/views/vaultViewCipher.html @@ -48,7 +48,7 @@ {{i18n.username}} {{cipher.login.username}}
-