vw_small

Hardened fork of Vaultwarden (https://github.com/dani-garcia/vaultwarden) with fewer features.
git clone https://git.philomathiclife.com/repos/vw_small
Log | Files | Refs | README

commit 1049646e27f481392a3582041df6e482128be594
parent 1f35ef2865a8f8ca5316568e34a1e91f0f32d30c
Author: Daniel GarcĂ­a <dani-garcia@users.noreply.github.com>
Date:   Sat,  6 Oct 2018 16:08:04 +0200

Merge pull request #210 from janost/cipher-save-refactor

Cipher::save() should return QueryResult instead of bool
Diffstat:
Msrc/api/core/ciphers.rs | 10++++++++--
Msrc/db/models/cipher.rs | 10++++------
2 files changed, 12 insertions(+), 8 deletions(-)

diff --git a/src/api/core/ciphers.rs b/src/api/core/ciphers.rs @@ -191,7 +191,10 @@ pub fn update_cipher_from_data(cipher: &mut Cipher, data: CipherData, headers: & cipher.data = type_data.to_string(); cipher.password_history = data.PasswordHistory.map(|f| f.to_string()); - cipher.save(&conn); + match cipher.save(&conn) { + Ok(()) => (), + Err(_) => println!("Error: Failed to save cipher") + }; ws.send_cipher_update(ut, &cipher, &cipher.update_users_revision(&conn)); if cipher.move_to_folder(data.FolderId, &headers.user.uuid, &conn).is_err() { @@ -626,7 +629,10 @@ fn move_cipher_selected(data: JsonUpcase<Value>, headers: Headers, conn: DbConn, if cipher.move_to_folder(folder_id.clone(), &headers.user.uuid, &conn).is_err() { err!("Error saving the folder information") } - cipher.save(&conn); + match cipher.save(&conn) { + Ok(()) => (), + Err(_) => println!("Error: Failed to save cipher") + }; ws.send_cipher_update(UpdateType::SyncCipherUpdate, &cipher, &cipher.update_users_revision(&conn)); } diff --git a/src/db/models/cipher.rs b/src/db/models/cipher.rs @@ -151,16 +151,14 @@ impl Cipher { user_uuids } - pub fn save(&mut self, conn: &DbConn) -> bool { + pub fn save(&mut self, conn: &DbConn) -> QueryResult<()> { self.update_users_revision(conn); self.updated_at = Utc::now().naive_utc(); - match diesel::replace_into(ciphers::table) + diesel::replace_into(ciphers::table) .values(&*self) - .execute(&**conn) { - Ok(1) => true, // One row inserted - _ => false, - } + .execute(&**conn) + .and(Ok(())) } pub fn delete(&self, conn: &DbConn) -> QueryResult<()> {