Spiegel von
https://github.com/dani-garcia/vaultwarden.git
synchronisiert 2024-12-01 06:31:11 +01:00
Merge pull request #20 from mprasil/folder_delete
Improve Folder::delete() to handle FolderCipher
Dieser Commit ist enthalten in:
Commit
e2a065cb09
4 geänderte Dateien mit 30 neuen und 15 gelöschten Zeilen
|
@ -176,7 +176,12 @@ fn delete_account(data: Json<PasswordData>, headers: Headers, conn: DbConn) -> E
|
||||||
}
|
}
|
||||||
|
|
||||||
// Delete folders
|
// Delete folders
|
||||||
for f in Folder::find_by_user(&user.uuid, &conn) { f.delete(&conn); }
|
for f in Folder::find_by_user(&user.uuid, &conn) {
|
||||||
|
match f.delete(&conn) {
|
||||||
|
Ok(()) => (),
|
||||||
|
Err(_) => err!("Failed deleting folder")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Delete devices
|
// Delete devices
|
||||||
for d in Device::find_by_user(&user.uuid, &conn) { d.delete(&conn); }
|
for d in Device::find_by_user(&user.uuid, &conn) { d.delete(&conn); }
|
||||||
|
|
|
@ -557,7 +557,12 @@ fn delete_all(data: Json<PasswordData>, headers: Headers, conn: DbConn) -> Empty
|
||||||
}
|
}
|
||||||
|
|
||||||
// Delete folders
|
// Delete folders
|
||||||
for f in Folder::find_by_user(&user.uuid, &conn) { f.delete(&conn); }
|
for f in Folder::find_by_user(&user.uuid, &conn) {
|
||||||
|
match f.delete(&conn) {
|
||||||
|
Ok(()) => (),
|
||||||
|
Err(_) => err!("Failed deleting folder")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
|
@ -89,11 +89,9 @@ fn delete_folder(uuid: String, headers: Headers, conn: DbConn) -> EmptyResult {
|
||||||
err!("Folder belongs to another user")
|
err!("Folder belongs to another user")
|
||||||
}
|
}
|
||||||
|
|
||||||
// Delete FolderCipher mappings
|
|
||||||
for fc in FolderCipher::find_by_folder(&uuid, &conn) { fc.delete(&conn).expect("Error deleting mapping"); }
|
|
||||||
|
|
||||||
// Delete the actual folder entry
|
// Delete the actual folder entry
|
||||||
folder.delete(&conn);
|
match folder.delete(&conn) {
|
||||||
|
Ok(()) => Ok(()),
|
||||||
Ok(())
|
Err(_) => err!("Failed deleting folder")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -81,13 +81,14 @@ impl Folder {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn delete(self, conn: &DbConn) -> bool {
|
pub fn delete(self, conn: &DbConn) -> QueryResult<()> {
|
||||||
match diesel::delete(folders::table.filter(
|
FolderCipher::delete_all_by_folder(&self.uuid, &conn)?;
|
||||||
folders::uuid.eq(self.uuid)))
|
|
||||||
.execute(&**conn) {
|
diesel::delete(
|
||||||
Ok(1) => true, // One row deleted
|
folders::table.filter(
|
||||||
_ => false,
|
folders::uuid.eq(self.uuid)
|
||||||
}
|
)
|
||||||
|
).execute(&**conn).and(Ok(()))
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn find_by_uuid(uuid: &str, conn: &DbConn) -> Option<Self> {
|
pub fn find_by_uuid(uuid: &str, conn: &DbConn) -> Option<Self> {
|
||||||
|
@ -123,6 +124,12 @@ impl FolderCipher {
|
||||||
).execute(&**conn).and(Ok(()))
|
).execute(&**conn).and(Ok(()))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn delete_all_by_folder(folder_uuid: &str, conn: &DbConn) -> QueryResult<()> {
|
||||||
|
diesel::delete(folders_ciphers::table
|
||||||
|
.filter(folders_ciphers::folder_uuid.eq(folder_uuid))
|
||||||
|
).execute(&**conn).and(Ok(()))
|
||||||
|
}
|
||||||
|
|
||||||
pub fn find_by_folder_and_cipher(folder_uuid: &str, cipher_uuid: &str, conn: &DbConn) -> Option<Self> {
|
pub fn find_by_folder_and_cipher(folder_uuid: &str, cipher_uuid: &str, conn: &DbConn) -> Option<Self> {
|
||||||
folders_ciphers::table
|
folders_ciphers::table
|
||||||
.filter(folders_ciphers::folder_uuid.eq(folder_uuid))
|
.filter(folders_ciphers::folder_uuid.eq(folder_uuid))
|
||||||
|
|
Laden …
In neuem Issue referenzieren