mirror of
https://github.com/dani-garcia/vaultwarden.wiki.git
synced 2026-10-31 03:06:48 +02:00
Bump user revision once for bulk cipher move (#7840)
This commit is contained in:
1 parent
0dbc92f2b7
commit
f1c7eccd4a
2 files changed
+21
-2
No files matched your search
+12
-2
@@ -23,7 +23,7 @@ use crate::{
|
|||||||
models::{
|
models::{
|
||||||
Archive, Attachment, AttachmentId, Cipher, CipherId, Collection, CollectionCipher, CollectionGroup,
|
Archive, Attachment, AttachmentId, Cipher, CipherId, Collection, CollectionCipher, CollectionGroup,
|
||||||
CollectionId, CollectionUser, EventType, Favorite, Folder, FolderCipher, FolderId, Group, KeyId,
|
CollectionId, CollectionUser, EventType, Favorite, Folder, FolderCipher, FolderId, Group, KeyId,
|
||||||
Membership, MembershipType, OrgPolicy, OrgPolicyType, OrganizationId, RepromptType, Send, UserId,
|
Membership, MembershipType, OrgPolicy, OrgPolicyType, OrganizationId, RepromptType, Send, User, UserId,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
util::{NumberOrString, deser_opt_nonempty_str, save_temp_file},
|
util::{NumberOrString, deser_opt_nonempty_str, save_temp_file},
|
||||||
@@ -1738,12 +1738,22 @@ async fn move_cipher_selected(
|
|||||||
// Find all ciphers a user has access to, all others will be ignored
|
// Find all ciphers a user has access to, all others will be ignored
|
||||||
let accessible_ciphers = Cipher::find_by_user_and_ciphers(user_id, &data.ids, &conn).await;
|
let accessible_ciphers = Cipher::find_by_user_and_ciphers(user_id, &data.ids, &conn).await;
|
||||||
let accessible_ciphers_count = accessible_ciphers.len();
|
let accessible_ciphers_count = accessible_ciphers.len();
|
||||||
|
let mut move_result = Ok(());
|
||||||
for cipher in accessible_ciphers {
|
for cipher in accessible_ciphers {
|
||||||
cipher.move_to_folder(data.folder_id.clone(), user_id, &conn).await?;
|
move_result = cipher.move_to_folder_without_revision_update(data.folder_id.clone(), user_id, &conn).await;
|
||||||
|
if move_result.is_err() {
|
||||||
|
break;
|
||||||
|
}
|
||||||
if cipher_count == 1 {
|
if cipher_count == 1 {
|
||||||
single_cipher = Some(cipher);
|
single_cipher = Some(cipher);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
// Update the revision once for the whole batch. Also when a move failed halfway,
|
||||||
|
// since the ciphers moved before it are already changed.
|
||||||
|
if accessible_ciphers_count > 0 {
|
||||||
|
User::update_uuid_revision(user_id, &conn).await;
|
||||||
|
}
|
||||||
|
move_result?;
|
||||||
|
|
||||||
if let Some(cipher) = single_cipher {
|
if let Some(cipher) = single_cipher {
|
||||||
nt.send_cipher_update(
|
nt.send_cipher_update(
|
||||||
|
|||||||
@@ -520,7 +520,16 @@ impl Cipher {
|
|||||||
conn: &DbConn,
|
conn: &DbConn,
|
||||||
) -> EmptyResult {
|
) -> EmptyResult {
|
||||||
User::update_uuid_revision(user_uuid, conn).await;
|
User::update_uuid_revision(user_uuid, conn).await;
|
||||||
|
self.move_to_folder_without_revision_update(folder_uuid, user_uuid, conn).await
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Same as `move_to_folder`, but the caller is responsible for updating the user's revision.
|
||||||
|
pub async fn move_to_folder_without_revision_update(
|
||||||
|
&self,
|
||||||
|
folder_uuid: Option<FolderId>,
|
||||||
|
user_uuid: &UserId,
|
||||||
|
conn: &DbConn,
|
||||||
|
) -> EmptyResult {
|
||||||
match (self.get_folder_uuid(user_uuid, conn).await, folder_uuid) {
|
match (self.get_folder_uuid(user_uuid, conn).await, folder_uuid) {
|
||||||
// No changes
|
// No changes
|
||||||
(None, None) => Ok(()),
|
(None, None) => Ok(()),
|
||||||
|
|||||||
Reference in new issue
Block a user