From ea23930352037553d75dc25ca9de47a1ce12ad69 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Felix=20N=C3=BCsse?= Date: Fri, 23 Nov 2018 18:15:18 +0100 Subject: [PATCH] Added proper returnvalue to updatemethod of credentials and add the resulting value to the list if it does not exist or replace it if it exists Fixed Nullpointer on listadd MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Felix NĂ¼sse --- controller/credentialcontroller.php | 10 ++++++++++ js/app/controllers/credential.js | 1 - js/app/controllers/edit_credential.js | 20 ++++++++++++++++---- 3 files changed, 26 insertions(+), 5 deletions(-) diff --git a/controller/credentialcontroller.php b/controller/credentialcontroller.php index 5f7839dd..d18e7855 100644 --- a/controller/credentialcontroller.php +++ b/controller/credentialcontroller.php @@ -269,6 +269,16 @@ class CredentialController extends ApiController { $credential = $this->credentialService->updateCredential($credential); + + //fetch the proper credentialelement, the returned element from createCredential is not usable in the frontend. + $credentials = $this->credentialService->getCredentialsByVaultId($vault_id, $this->userId); + foreach ($credentials as &$value) { + if($value->getGuid() == $credential->getGuid()){ + return new JSONResponse($value); + } + } + + //return old value as fallback return new JSONResponse($credential); } diff --git a/js/app/controllers/credential.js b/js/app/controllers/credential.js index f6d445c1..cb82461d 100644 --- a/js/app/controllers/credential.js +++ b/js/app/controllers/credential.js @@ -319,7 +319,6 @@ }; $rootScope.$on('push_decrypted_credential_to_list', function () { - $scope.active_vault = $rootScope.vaultCache[$scope.active_vault.guid]; $rootScope.$broadcast('credentials_loaded'); }); diff --git a/js/app/controllers/edit_credential.js b/js/app/controllers/edit_credential.js index 14acc04c..0cfaff6a 100644 --- a/js/app/controllers/edit_credential.js +++ b/js/app/controllers/edit_credential.js @@ -317,8 +317,6 @@ $location.path('/vault/' + $routeParams.vault_id); NotificationService.showNotification($translate.instant('credential.created'), 5000); - console.log("new cred"); - console.log(new_cred); $scope.updateExistingListWithCredential(new_cred); }); @@ -349,11 +347,13 @@ if(_credential.description && _credential.description !== "") { _credential.description = _credential.description.replace(regex, ""); } - CredentialService.updateCredential(_credential, _useKey).then(function () { + CredentialService.updateCredential(_credential, _useKey).then(function (updated_cred) { $scope.saving = false; SettingsService.setSetting('edit_credential', null); $location.path('/vault/' + $routeParams.vault_id); NotificationService.showNotification($translate.instant('credential.updated'), 5000); + + $scope.updateExistingListWithCredential(updated_cred); }); } @@ -369,7 +369,19 @@ } credential.tags_raw = credential.tags; - $rootScope.vaultCache[$scope.active_vault.guid].credentials.push(credential); + + var found=false; + var credList=$rootScope.vaultCache[$scope.active_vault.guid].credentials; + for (var i = 0; i < credList.length; i++) { + if(credList[i].credential_id==credential.credential_id){ + $rootScope.vaultCache[$scope.active_vault.guid].credentials[i]=credential; + found=true; + } + } + + if(!found){ + $rootScope.vaultCache[$scope.active_vault.guid].credentials.push(credential); + } $rootScope.$broadcast('push_decrypted_credential_to_list', credential); } catch (e) {