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

Signed-off-by: Felix Nüsse <Felix.nuesse@t-online.de>
This commit is contained in:
Felix Nüsse 2018-11-23 18:15:18 +01:00 committed by fnuesse
parent abaedc1e38
commit ea23930352
No known key found for this signature in database
GPG key ID: 2089A3431243E819
3 changed files with 26 additions and 5 deletions

View file

@ -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);
}

View file

@ -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');
});

View file

@ -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) {