diff --git a/src/app/global/mainController.js b/src/app/global/mainController.js index 67dd8bf6d4..fdf4928f9b 100644 --- a/src/app/global/mainController.js +++ b/src/app/global/mainController.js @@ -44,6 +44,10 @@ angular $state.go('backend.user.vault'); }; + $scope.searchOrganizationVault = function () { + $state.go('backend.org.vault', { orgId: $state.params.orgId }); + }; + $scope.addLogin = function () { $scope.$broadcast('vaultAddLogin'); }; @@ -52,6 +56,10 @@ angular $scope.$broadcast('vaultAddFolder'); }; + $scope.addOrganizationLogin = function () { + $scope.$broadcast('organizationVaultAddLogin'); + }; + // Append dropdown menu somewhere else var bodyScrollbarWidth, appendedDropdownMenu, diff --git a/src/app/organization/organizationVaultAddLoginController.js b/src/app/organization/organizationVaultAddLoginController.js new file mode 100644 index 0000000000..d529c80ce6 --- /dev/null +++ b/src/app/organization/organizationVaultAddLoginController.js @@ -0,0 +1,50 @@ +angular + .module('bit.vault') + + .controller('organizationVaultAddLoginController', function ($scope, apiService, $uibModalInstance, cryptoService, + cipherService, passwordService, $analytics, orgId) { + $analytics.eventTrack('organizationVaultAddLoginController', { category: 'Modal' }); + $scope.login = {}; + $scope.hideFolders = $scope.hideFavorite = true; + + $scope.savePromise = null; + $scope.save = function (model) { + model.organizationId = orgId; + var login = cipherService.encryptLogin(model); + $scope.savePromise = apiService.logins.postAdmin(login, function (loginResponse) { + $analytics.eventTrack('Created Organization Login'); + var decLogin = cipherService.decryptLogin(loginResponse); + $uibModalInstance.close(decLogin); + }).$promise; + }; + + $scope.generatePassword = function () { + if (!$scope.login.password || confirm('Are you sure you want to overwrite the current password?')) { + $analytics.eventTrack('Generated Password From Add'); + $scope.login.password = passwordService.generatePassword({ length: 12, special: true }); + } + }; + + $scope.clipboardSuccess = function (e) { + e.clearSelection(); + selectPassword(e); + }; + + $scope.clipboardError = function (e, password) { + if (password) { + selectPassword(e); + } + alert('Your web browser does not support easy clipboard copying. Copy it manually instead.'); + }; + + function selectPassword(e) { + var target = $(e.trigger).parent().prev(); + if (target.attr('type') === 'text') { + target.select(); + } + } + + $scope.close = function () { + $uibModalInstance.dismiss('close'); + }; + }); diff --git a/src/app/organization/organizationVaultController.js b/src/app/organization/organizationVaultController.js index f72a4c9b8f..4d3517f2f5 100644 --- a/src/app/organization/organizationVaultController.js +++ b/src/app/organization/organizationVaultController.js @@ -77,6 +77,49 @@ } }; + $scope.editLogin = function (login) { + var editModel = $uibModal.open({ + animation: true, + templateUrl: 'app/vault/views/vaultEditLogin.html', + controller: 'organizationVaultEditLoginController', + resolve: { + loginId: function () { return login.id; } + } + }); + + editModel.result.then(function (returnVal) { + if (returnVal.action === 'edit') { + login.name = returnVal.data.name; + login.username = returnVal.data.username; + } + else if (returnVal.action === 'delete') { + var index = $scope.logins.indexOf(login); + if (index > -1) { + $scope.logins.splice(index, 1); + } + } + }); + }; + + $scope.$on('organizationVaultAddLogin', function (event, args) { + $scope.addLogin(); + }); + + $scope.addLogin = function () { + var addModel = $uibModal.open({ + animation: true, + templateUrl: 'app/vault/views/vaultAddLogin.html', + controller: 'organizationVaultAddLoginController', + resolve: { + orgId: function () { return $state.params.orgId; } + } + }); + + addModel.result.then(function (addedLogin) { + $scope.logins.push(addedLogin); + }); + }; + $scope.editCollections = function (cipher) { var modal = $uibModal.open({ animation: true, diff --git a/src/app/organization/organizationVaultEditLoginController.js b/src/app/organization/organizationVaultEditLoginController.js new file mode 100644 index 0000000000..84aea7f71e --- /dev/null +++ b/src/app/organization/organizationVaultEditLoginController.js @@ -0,0 +1,69 @@ +angular + .module('bit.vault') + + .controller('organizationVaultEditLoginController', function ($scope, apiService, $uibModalInstance, cryptoService, + cipherService, passwordService, loginId, $analytics) { + $analytics.eventTrack('organizationVaultEditLoginController', { category: 'Modal' }); + $scope.login = {}; + $scope.hideFolders = $scope.hideFavorite = true; + + apiService.logins.getAdmin({ id: loginId }, function (login) { + $scope.login = cipherService.decryptLogin(login); + }); + + $scope.save = function (model) { + var login = cipherService.encryptLogin(model); + $scope.savePromise = apiService.logins.putAdmin({ id: loginId }, login, function (loginResponse) { + $analytics.eventTrack('Edited Organization Login'); + var decLogin = cipherService.decryptLogin(loginResponse); + $uibModalInstance.close({ + action: 'edit', + data: decLogin + }); + }).$promise; + }; + + $scope.generatePassword = function () { + if (!$scope.login.password || confirm('Are you sure you want to overwrite the current password?')) { + $analytics.eventTrack('Generated Password From Edit'); + $scope.login.password = passwordService.generatePassword({ length: 12, special: true }); + } + }; + + $scope.clipboardSuccess = function (e) { + e.clearSelection(); + selectPassword(e); + }; + + $scope.clipboardError = function (e, password) { + if (password) { + selectPassword(e); + } + alert('Your web browser does not support easy clipboard copying. Copy it manually instead.'); + }; + + function selectPassword(e) { + var target = $(e.trigger).parent().prev(); + if (target.attr('type') === 'text') { + target.select(); + } + } + + $scope.delete = function () { + if (!confirm('Are you sure you want to delete this login (' + $scope.login.name + ')?')) { + return; + } + + apiService.ciphers.delAdmin({ id: $scope.login.id }, function () { + $analytics.eventTrack('Deleted Organization Login From Edit'); + $uibModalInstance.close({ + action: 'delete', + data: $scope.login.id + }); + }); + }; + + $scope.close = function () { + $uibModalInstance.dismiss('cancel'); + }; + }); diff --git a/src/app/organization/views/organizationVault.html b/src/app/organization/views/organizationVault.html index 0f2df3d238..537dcbb568 100644 --- a/src/app/organization/views/organizationVault.html +++ b/src/app/organization/views/organizationVault.html @@ -13,7 +13,7 @@
Loading...
|
- {{login.name}}
+ {{login.name}}
{{login.username}}
|