From 84a7c7da5dc838a4e5b35695fa3fade4c6b84c37 Mon Sep 17 00:00:00 2001 From: Kristof Mattei <864376+kristof-mattei@users.noreply.github.com> Date: Sat, 27 Apr 2024 12:53:10 -0700 Subject: [PATCH] Pass in collection ids to notifier when sharing cipher. (#4517) --- src/api/core/accounts.rs | 2 +- src/api/core/ciphers.rs | 27 +++++++++++++++++---------- src/api/core/organizations.rs | 2 +- 3 files changed, 19 insertions(+), 12 deletions(-) diff --git a/src/api/core/accounts.rs b/src/api/core/accounts.rs index ff74c84f..b2afe905 100644 --- a/src/api/core/accounts.rs +++ b/src/api/core/accounts.rs @@ -568,7 +568,7 @@ async fn post_rotatekey(data: JsonUpcase, headers: Headers, mut conn: D // Prevent triggering cipher updates via WebSockets by settings UpdateType::None // The user sessions are invalidated because all the ciphers were re-encrypted and thus triggering an update could cause issues. // We force the users to logout after the user has been saved to try and prevent these issues. - update_cipher_from_data(&mut saved_cipher, cipher_data, &headers, false, &mut conn, &nt, UpdateType::None) + update_cipher_from_data(&mut saved_cipher, cipher_data, &headers, None, &mut conn, &nt, UpdateType::None) .await? } } diff --git a/src/api/core/ciphers.rs b/src/api/core/ciphers.rs index 51a9589d..5a955d17 100644 --- a/src/api/core/ciphers.rs +++ b/src/api/core/ciphers.rs @@ -321,7 +321,7 @@ async fn post_ciphers(data: JsonUpcase, headers: Headers, mut conn: data.LastKnownRevisionDate = None; let mut cipher = Cipher::new(data.Type, data.Name.clone()); - update_cipher_from_data(&mut cipher, data, &headers, false, &mut conn, &nt, UpdateType::SyncCipherCreate).await?; + update_cipher_from_data(&mut cipher, data, &headers, None, &mut conn, &nt, UpdateType::SyncCipherCreate).await?; Ok(Json(cipher.to_json(&headers.host, &headers.user.uuid, None, CipherSyncType::User, &mut conn).await)) } @@ -352,7 +352,7 @@ pub async fn update_cipher_from_data( cipher: &mut Cipher, data: CipherData, headers: &Headers, - shared_to_collection: bool, + shared_to_collections: Option>, conn: &mut DbConn, nt: &Notify<'_>, ut: UpdateType, @@ -391,7 +391,7 @@ pub async fn update_cipher_from_data( match UserOrganization::find_by_user_and_org(&headers.user.uuid, &org_id, conn).await { None => err!("You don't have permission to add item to organization"), Some(org_user) => { - if shared_to_collection + if shared_to_collections.is_some() || org_user.has_full_access() || cipher.is_write_accessible_to_user(&headers.user.uuid, conn).await { @@ -518,8 +518,15 @@ pub async fn update_cipher_from_data( ) .await; } - nt.send_cipher_update(ut, cipher, &cipher.update_users_revision(conn).await, &headers.device.uuid, None, conn) - .await; + nt.send_cipher_update( + ut, + cipher, + &cipher.update_users_revision(conn).await, + &headers.device.uuid, + shared_to_collections, + conn, + ) + .await; } Ok(()) } @@ -580,7 +587,7 @@ async fn post_ciphers_import( cipher_data.FolderId = folder_uuid; let mut cipher = Cipher::new(cipher_data.Type, cipher_data.Name.clone()); - update_cipher_from_data(&mut cipher, cipher_data, &headers, false, &mut conn, &nt, UpdateType::None).await?; + update_cipher_from_data(&mut cipher, cipher_data, &headers, None, &mut conn, &nt, UpdateType::None).await?; } let mut user = headers.user; @@ -648,7 +655,7 @@ async fn put_cipher( err!("Cipher is not write accessible") } - update_cipher_from_data(&mut cipher, data, &headers, false, &mut conn, &nt, UpdateType::SyncCipherUpdate).await?; + update_cipher_from_data(&mut cipher, data, &headers, None, &mut conn, &nt, UpdateType::SyncCipherUpdate).await?; Ok(Json(cipher.to_json(&headers.host, &headers.user.uuid, None, CipherSyncType::User, &mut conn).await)) } @@ -898,7 +905,7 @@ async fn share_cipher_by_uuid( None => err!("Cipher doesn't exist"), }; - let mut shared_to_collection = false; + let mut shared_to_collections = vec![]; if let Some(organization_uuid) = &data.Cipher.OrganizationId { for uuid in &data.CollectionIds { @@ -907,7 +914,7 @@ async fn share_cipher_by_uuid( Some(collection) => { if collection.is_writable_by_user(&headers.user.uuid, conn).await { CollectionCipher::save(&cipher.uuid, &collection.uuid, conn).await?; - shared_to_collection = true; + shared_to_collections.push(collection.uuid); } else { err!("No rights to modify the collection") } @@ -923,7 +930,7 @@ async fn share_cipher_by_uuid( UpdateType::SyncCipherCreate }; - update_cipher_from_data(&mut cipher, data.Cipher, headers, shared_to_collection, conn, nt, ut).await?; + update_cipher_from_data(&mut cipher, data.Cipher, headers, Some(shared_to_collections), conn, nt, ut).await?; Ok(Json(cipher.to_json(&headers.host, &headers.user.uuid, None, CipherSyncType::User, conn).await)) } diff --git a/src/api/core/organizations.rs b/src/api/core/organizations.rs index 840ae6ea..38657ef6 100644 --- a/src/api/core/organizations.rs +++ b/src/api/core/organizations.rs @@ -1618,7 +1618,7 @@ async fn post_org_import( let mut ciphers = Vec::new(); for cipher_data in data.Ciphers { let mut cipher = Cipher::new(cipher_data.Type, cipher_data.Name.clone()); - update_cipher_from_data(&mut cipher, cipher_data, &headers, false, &mut conn, &nt, UpdateType::None).await.ok(); + update_cipher_from_data(&mut cipher, cipher_data, &headers, None, &mut conn, &nt, UpdateType::None).await.ok(); ciphers.push(cipher); }