From b85a45d8f97fecd6f961e6340a863e37ca73b8dc Mon Sep 17 00:00:00 2001 From: Kyle Spearrin Date: Tue, 21 Mar 2017 00:05:20 -0400 Subject: [PATCH] Move and list ciphers from org subvaults --- src/app/services/apiService.js | 1 + src/app/services/cipherService.js | 20 ++++++--- src/app/vault/vaultController.js | 18 +++++++- src/app/vault/vaultShareController.js | 61 +++++++++++++++++++++++++++ src/app/vault/views/vault.html | 6 ++- src/app/vault/views/vaultShare.html | 33 +++++++++++++++ src/index.html | 1 + 7 files changed, 131 insertions(+), 9 deletions(-) create mode 100644 src/app/vault/vaultShareController.js create mode 100644 src/app/vault/views/vaultShare.html diff --git a/src/app/services/apiService.js b/src/app/services/apiService.js index 51d14291d6..05907bf888 100644 --- a/src/app/services/apiService.js +++ b/src/app/services/apiService.js @@ -26,6 +26,7 @@ list: { method: 'GET', params: {} }, 'import': { url: _apiUri + '/ciphers/import', method: 'POST', params: {} }, favorite: { url: _apiUri + '/ciphers/:id/favorite', method: 'POST', params: { id: '@id' } }, + move: { url: _apiUri + '/ciphers/:id/move', method: 'POST', params: { id: '@id' } }, del: { url: _apiUri + '/ciphers/:id/delete', method: 'POST', params: { id: '@id' } } }); diff --git a/src/app/services/cipherService.js b/src/app/services/cipherService.js index 2e89486e4b..84ebdc4a6b 100644 --- a/src/app/services/cipherService.js +++ b/src/app/services/cipherService.js @@ -19,12 +19,13 @@ angular if (!encryptedLogin) throw "encryptedLogin is undefined or null"; var key = null; - if (encryptedLogin.Key) { - key = cryptoService.rsaDecrypt(encryptedLogin.Key); + if (encryptedLogin.OrganizationId) { + key = cryptoService.getOrgKey(encryptedLogin.OrganizationId); } var login = { id: encryptedLogin.Id, + organizationId: encryptedLogin.OrganizationId, 'type': 1, folderId: encryptedLogin.FolderId, favorite: encryptedLogin.Favorite, @@ -32,8 +33,7 @@ angular uri: encryptedLogin.Uri && encryptedLogin.Uri !== '' ? cryptoService.decrypt(encryptedLogin.Uri, key) : null, username: encryptedLogin.Username && encryptedLogin.Username !== '' ? cryptoService.decrypt(encryptedLogin.Username, key) : null, password: encryptedLogin.Password && encryptedLogin.Password !== '' ? cryptoService.decrypt(encryptedLogin.Password, key) : null, - notes: encryptedLogin.Notes && encryptedLogin.Notes !== '' ? cryptoService.decrypt(encryptedLogin.Notes, key) : null, - key: encryptedLogin.Key + notes: encryptedLogin.Notes && encryptedLogin.Notes !== '' ? cryptoService.decrypt(encryptedLogin.Notes, key) : null }; if (encryptedLogin.Folder) { @@ -49,12 +49,13 @@ angular if (!encryptedCipher) throw "encryptedCipher is undefined or null"; var key = null; - if (encryptedCipher.Key) { - key = cryptoService.rsaDecrypt(encryptedCipher.Key); + if (encryptedCipher.OrganizationId) { + key = cryptoService.getOrgKey(encryptedCipher.OrganizationId); } var login = { id: encryptedCipher.Id, + organizationId: encryptedCipher.OrganizationId, folderId: encryptedCipher.FolderId, favorite: encryptedCipher.Favorite, name: _service.decryptProperty(encryptedCipher.Data.Name, key, false), @@ -119,7 +120,7 @@ angular }; }; - _service.decryptProperty = function(property, key, checkEmpty) { + _service.decryptProperty = function (property, key, checkEmpty) { if (checkEmpty && (!property || property === '')) { return null; } @@ -148,9 +149,14 @@ angular _service.encryptLogin = function (unencryptedLogin, key) { if (!unencryptedLogin) throw "unencryptedLogin is undefined or null"; + if (unencryptedLogin.organizationId) { + key = key || cryptoService.getOrgKey(unencryptedLogin.organizationId); + } + return { id: unencryptedLogin.id, 'type': 1, + organizationId: unencryptedLogin.organizationId || null, folderId: unencryptedLogin.folderId === '' ? null : unencryptedLogin.folderId, favorite: unencryptedLogin.favorite !== null ? unencryptedLogin.favorite : false, uri: !unencryptedLogin.uri || unencryptedLogin.uri === '' ? null : cryptoService.encrypt(unencryptedLogin.uri, key), diff --git a/src/app/vault/vaultController.js b/src/app/vault/vaultController.js index a225aaf47e..72889b8406 100644 --- a/src/app/vault/vaultController.js +++ b/src/app/vault/vaultController.js @@ -11,7 +11,7 @@ var folderPromise = apiService.folders.list({}, function (folders) { var decFolders = [{ id: null, - name: '(none)' + name: 'No Folder' }]; for (var i = 0; i < folders.Data.length; i++) { @@ -172,4 +172,20 @@ var logins = $filter('filter')($scope.logins, { folderId: folder.id }); return logins.length === 0; }; + + $scope.share = function (login) { + var modal = $uibModal.open({ + animation: true, + templateUrl: 'app/vault/views/vaultShare.html', + controller: 'vaultShareController', + size: 'sm', + resolve: { + loginId: function () { return login.id; } + } + }); + + modal.result.then(function () { + + }); + }; }); diff --git a/src/app/vault/vaultShareController.js b/src/app/vault/vaultShareController.js new file mode 100644 index 0000000000..7190cb2dab --- /dev/null +++ b/src/app/vault/vaultShareController.js @@ -0,0 +1,61 @@ +angular + .module('bit.vault') + + .controller('vaultShareController', function ($scope, apiService, $uibModalInstance, authService, cipherService, loginId, $analytics) { + $analytics.eventTrack('vaultShareController', { category: 'Modal' }); + $scope.model = {}; + $scope.login = {}; + $scope.subvaults = []; + $scope.organizations = []; + + apiService.logins.get({ id: loginId }, function (login) { + $scope.login = cipherService.decryptLogin(login); + }); + + var profile = authService.getUserProfile(); + if (profile && profile.organizations) { + var orgs = []; + for (var i = 0; i < profile.organizations.length; i++) { + orgs.push({ + id: profile.organizations[i].id, + name: profile.organizations[i].name + }); + + if (i === 0) { + $scope.model.organizationId = profile.organizations[i].id; + } + } + + $scope.organizations = orgs; + + apiService.subvaults.listMe(function (response) { + var subvaults = []; + for (var i = 0; i < response.Data.length; i++) { + var decSubvault = cipherService.decryptSubvault(response.Data[i]); + decSubvault.organizationId = response.Data[i].OrganizationId; + subvaults.push(decSubvault); + } + + $scope.subvaults = subvaults; + }); + } + + $scope.submitPromise = null; + $scope.submit = function (model) { + $scope.login.organizationId = model.organizationId; + + var request = { + subvaultIds: model.subvaultIds, + cipher: cipherService.encryptLogin($scope.login) + }; + + $scope.savePromise = apiService.ciphers.move({ id: loginId }, request, function (response) { + $analytics.eventTrack('Shared Login'); + $uibModalInstance.close(); + }).$promise; + }; + + $scope.close = function () { + $uibModalInstance.dismiss('cancel'); + }; + }); diff --git a/src/app/vault/views/vault.html b/src/app/vault/views/vault.html index 9baed2420c..b122274b74 100644 --- a/src/app/vault/views/vault.html +++ b/src/app/vault/views/vault.html @@ -47,7 +47,7 @@ - + @@ -64,6 +64,10 @@ uib-tooltip="View/Edit"> +
Name Username
diff --git a/src/app/vault/views/vaultShare.html b/src/app/vault/views/vaultShare.html new file mode 100644 index 0000000000..4d4680e8ea --- /dev/null +++ b/src/app/vault/views/vaultShare.html @@ -0,0 +1,33 @@ + +
+ + +
\ No newline at end of file diff --git a/src/index.html b/src/index.html index 872cfa59a9..098ff4a6c0 100644 --- a/src/index.html +++ b/src/index.html @@ -115,6 +115,7 @@ +