mirror of
https://github.com/ViViDboarder/bitwarden_rs.git
synced 2024-11-22 13:16:39 +00:00
Remove dependent items when removing cipher
This commit is contained in:
parent
1e812c0a23
commit
21c1ab7fda
@ -169,9 +169,10 @@ fn delete_account(data: Json<PasswordData>, headers: Headers, conn: DbConn) -> E
|
|||||||
|
|
||||||
// Delete ciphers and their attachments
|
// Delete ciphers and their attachments
|
||||||
for cipher in Cipher::find_owned_by_user(&user.uuid, &conn) {
|
for cipher in Cipher::find_owned_by_user(&user.uuid, &conn) {
|
||||||
for a in Attachment::find_by_cipher(&cipher.uuid, &conn) { a.delete(&conn); }
|
match cipher.delete(&conn) {
|
||||||
|
Ok(()) => (),
|
||||||
cipher.delete(&conn);
|
Err(_) => err!("Failed deleting cipher")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Delete folders
|
// Delete folders
|
||||||
|
@ -450,9 +450,10 @@ fn delete_attachment(uuid: String, attachment_id: String, headers: Headers, conn
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Delete attachment
|
// Delete attachment
|
||||||
attachment.delete(&conn);
|
match attachment.delete(&conn) {
|
||||||
|
Ok(()) => Ok(()),
|
||||||
Ok(())
|
Err(_) => err!("Deleting attachement failed")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[post("/ciphers/<uuid>/delete")]
|
#[post("/ciphers/<uuid>/delete")]
|
||||||
@ -549,7 +550,10 @@ fn delete_all(data: Json<PasswordData>, headers: Headers, conn: DbConn) -> Empty
|
|||||||
|
|
||||||
// Delete ciphers and their attachments
|
// Delete ciphers and their attachments
|
||||||
for cipher in Cipher::find_owned_by_user(&user.uuid, &conn) {
|
for cipher in Cipher::find_owned_by_user(&user.uuid, &conn) {
|
||||||
_delete_cipher(cipher, &conn);
|
match cipher.delete(&conn) {
|
||||||
|
Ok(()) => (),
|
||||||
|
Err(_) => err!("Failed deleting cipher")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Delete folders
|
// Delete folders
|
||||||
@ -568,15 +572,8 @@ fn _delete_cipher_by_uuid(uuid: &str, headers: &Headers, conn: &DbConn) -> Empty
|
|||||||
err!("Cipher can't be deleted by user")
|
err!("Cipher can't be deleted by user")
|
||||||
}
|
}
|
||||||
|
|
||||||
_delete_cipher(cipher, conn);
|
match cipher.delete(conn) {
|
||||||
|
Ok(()) => Ok(()),
|
||||||
Ok(())
|
Err(_) => err!("Failed deleting cipher")
|
||||||
}
|
}
|
||||||
|
|
||||||
fn _delete_cipher(cipher: Cipher, conn: &DbConn) {
|
|
||||||
// Delete the attachments
|
|
||||||
for a in Attachment::find_by_cipher(&cipher.uuid, &conn) { a.delete(&conn); }
|
|
||||||
|
|
||||||
// Delete the cipher
|
|
||||||
cipher.delete(conn);
|
|
||||||
}
|
}
|
||||||
|
@ -62,17 +62,23 @@ impl Attachment {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn delete(self, conn: &DbConn) -> bool {
|
pub fn delete(self, conn: &DbConn) -> QueryResult<()> {
|
||||||
use util;
|
use util;
|
||||||
|
|
||||||
util::delete_file(&self.get_file_path());
|
util::delete_file(&self.get_file_path());
|
||||||
|
|
||||||
match diesel::delete(attachments::table.filter(
|
diesel::delete(
|
||||||
attachments::id.eq(self.id)))
|
attachments::table.filter(
|
||||||
.execute(&**conn) {
|
attachments::id.eq(self.id)
|
||||||
Ok(1) => true, // One row deleted
|
)
|
||||||
_ => false,
|
).execute(&**conn).and(Ok(()))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn delete_all_by_cipher(cipher_uuid: &str, conn: &DbConn) -> QueryResult<()> {
|
||||||
|
for attachement in Attachment::find_by_cipher(&cipher_uuid, &conn) {
|
||||||
|
attachement.delete(&conn)?;
|
||||||
|
}
|
||||||
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn find_by_id(id: &str, conn: &DbConn) -> Option<Self> {
|
pub fn find_by_id(id: &str, conn: &DbConn) -> Option<Self> {
|
||||||
|
@ -3,7 +3,7 @@ use serde_json::Value as JsonValue;
|
|||||||
|
|
||||||
use uuid::Uuid;
|
use uuid::Uuid;
|
||||||
|
|
||||||
use super::{User, Organization, UserOrganization, FolderCipher, UserOrgType};
|
use super::{User, Organization, UserOrganization, Attachment, FolderCipher, CollectionCipher, UserOrgType};
|
||||||
|
|
||||||
#[derive(Debug, Identifiable, Queryable, Insertable, Associations)]
|
#[derive(Debug, Identifiable, Queryable, Insertable, Associations)]
|
||||||
#[table_name = "ciphers"]
|
#[table_name = "ciphers"]
|
||||||
@ -133,13 +133,16 @@ impl Cipher {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn delete(self, conn: &DbConn) -> bool {
|
pub fn delete(self, conn: &DbConn) -> QueryResult<()> {
|
||||||
match diesel::delete(ciphers::table.filter(
|
FolderCipher::delete_all_by_cipher(&self.uuid, &conn)?;
|
||||||
ciphers::uuid.eq(self.uuid)))
|
CollectionCipher::delete_all_by_cipher(&self.uuid, &conn)?;
|
||||||
.execute(&**conn) {
|
Attachment::delete_all_by_cipher(&self.uuid, &conn)?;
|
||||||
Ok(1) => true, // One row deleted
|
|
||||||
_ => false,
|
diesel::delete(
|
||||||
}
|
ciphers::table.filter(
|
||||||
|
ciphers::uuid.eq(self.uuid)
|
||||||
|
)
|
||||||
|
).execute(&**conn).and(Ok(()))
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn move_to_folder(&self, folder_uuid: Option<String>, user_uuid: &str, conn: &DbConn) -> Result<(), &str> {
|
pub fn move_to_folder(&self, folder_uuid: Option<String>, user_uuid: &str, conn: &DbConn) -> Result<(), &str> {
|
||||||
|
@ -204,4 +204,10 @@ impl CollectionCipher {
|
|||||||
_ => false,
|
_ => false,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn delete_all_by_cipher(cipher_uuid: &str, conn: &DbConn) -> QueryResult<()> {
|
||||||
|
diesel::delete(ciphers_collections::table
|
||||||
|
.filter(ciphers_collections::cipher_uuid.eq(cipher_uuid))
|
||||||
|
).execute(&**conn).and(Ok(()))
|
||||||
|
}
|
||||||
}
|
}
|
@ -117,6 +117,12 @@ impl FolderCipher {
|
|||||||
).execute(&**conn).and(Ok(()))
|
).execute(&**conn).and(Ok(()))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn delete_all_by_cipher(cipher_uuid: &str, conn: &DbConn) -> QueryResult<()> {
|
||||||
|
diesel::delete(folders_ciphers::table
|
||||||
|
.filter(folders_ciphers::cipher_uuid.eq(cipher_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))
|
||||||
|
Loading…
Reference in New Issue
Block a user