mirror of
https://github.com/dani-garcia/vaultwarden.git
synced 2025-06-10 21:13:53 +00:00
Only send one notification per vault import and purge, improve move ciphers functions
This commit is contained in:
parent
f935f5cf46
commit
bef1183c49
5 changed files with 83 additions and 83 deletions
|
@ -196,40 +196,28 @@ impl Cipher {
|
|||
}
|
||||
|
||||
pub fn move_to_folder(&self, folder_uuid: Option<String>, user_uuid: &str, conn: &DbConn) -> EmptyResult {
|
||||
match self.get_folder_uuid(&user_uuid, &conn) {
|
||||
None => {
|
||||
match folder_uuid {
|
||||
Some(new_folder) => {
|
||||
self.update_users_revision(conn);
|
||||
let folder_cipher = FolderCipher::new(&new_folder, &self.uuid);
|
||||
folder_cipher.save(&conn)
|
||||
}
|
||||
None => Ok(()), //nothing to do
|
||||
}
|
||||
}
|
||||
Some(current_folder) => {
|
||||
match folder_uuid {
|
||||
Some(new_folder) => {
|
||||
if current_folder == new_folder {
|
||||
Ok(()) //nothing to do
|
||||
} else {
|
||||
self.update_users_revision(conn);
|
||||
if let Some(current_folder) =
|
||||
FolderCipher::find_by_folder_and_cipher(¤t_folder, &self.uuid, &conn)
|
||||
{
|
||||
current_folder.delete(&conn)?;
|
||||
}
|
||||
FolderCipher::new(&new_folder, &self.uuid).save(&conn)
|
||||
}
|
||||
}
|
||||
None => {
|
||||
self.update_users_revision(conn);
|
||||
match FolderCipher::find_by_folder_and_cipher(¤t_folder, &self.uuid, &conn) {
|
||||
Some(current_folder) => current_folder.delete(&conn),
|
||||
None => err!("Couldn't move from previous folder"),
|
||||
}
|
||||
}
|
||||
User::update_uuid_revision(user_uuid, &conn);
|
||||
|
||||
match (self.get_folder_uuid(&user_uuid, &conn), folder_uuid) {
|
||||
// No changes
|
||||
(None, None) => Ok(()),
|
||||
(Some(ref old), Some(ref new)) if old == new => Ok(()),
|
||||
|
||||
// Add to folder
|
||||
(None, Some(new)) => FolderCipher::new(&new, &self.uuid).save(&conn),
|
||||
|
||||
// Remove from folder
|
||||
(Some(old), None) => match FolderCipher::find_by_folder_and_cipher(&old, &self.uuid, &conn) {
|
||||
Some(old) => old.delete(&conn),
|
||||
None => err!("Couldn't move from previous folder"),
|
||||
},
|
||||
|
||||
// Move to another folder
|
||||
(Some(old), Some(new)) => {
|
||||
if let Some(old) = FolderCipher::find_by_folder_and_cipher(&old, &self.uuid, &conn) {
|
||||
old.delete(&conn)?;
|
||||
}
|
||||
FolderCipher::new(&new, &self.uuid).save(&conn)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -241,7 +241,9 @@ impl CollectionUser {
|
|||
pub fn delete_all_by_collection(collection_uuid: &str, conn: &DbConn) -> EmptyResult {
|
||||
CollectionUser::find_by_collection(&collection_uuid, conn)
|
||||
.iter()
|
||||
.for_each(|collection| User::update_uuid_revision(&collection.user_uuid, conn));
|
||||
.for_each(|collection| {
|
||||
User::update_uuid_revision(&collection.user_uuid, conn);
|
||||
});
|
||||
|
||||
diesel::delete(users_collections::table.filter(users_collections::collection_uuid.eq(collection_uuid)))
|
||||
.execute(&**conn)
|
||||
|
|
|
@ -172,12 +172,14 @@ impl User {
|
|||
.map_res("Error deleting user")
|
||||
}
|
||||
|
||||
pub fn update_uuid_revision(uuid: &str, conn: &DbConn) {
|
||||
pub fn update_uuid_revision(uuid: &str, conn: &DbConn) -> Vec<String> {
|
||||
if let Some(mut user) = User::find_by_uuid(&uuid, conn) {
|
||||
if user.update_revision(conn).is_err() {
|
||||
warn!("Failed to update revision for {}", user.email);
|
||||
};
|
||||
};
|
||||
|
||||
vec![uuid.to_string()]
|
||||
}
|
||||
|
||||
pub fn update_revision(&mut self, conn: &DbConn) -> EmptyResult {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue