diff --git a/crates/bitwarden-uniffi/src/vault/ciphers.rs b/crates/bitwarden-uniffi/src/vault/ciphers.rs index 6508558eb..b2f8dcf3e 100644 --- a/crates/bitwarden-uniffi/src/vault/ciphers.rs +++ b/crates/bitwarden-uniffi/src/vault/ciphers.rs @@ -1,3 +1,4 @@ +use bitwarden_collections::collection::CollectionId; use bitwarden_core::OrganizationId; use bitwarden_vault::{ Cipher, CipherListView, CipherView, DecryptCipherListResult, EncryptionContext, @@ -53,4 +54,17 @@ impl CiphersClient { ) -> Result { Ok(self.0.move_to_organization(cipher, organization_id)?) } + + /// Prepare ciphers for bulk share to an organization + pub async fn prepare_ciphers_for_bulk_share( + &self, + ciphers: Vec, + organization_id: OrganizationId, + collection_ids: Vec, + ) -> Result> { + Ok(self + .0 + .prepare_ciphers_for_bulk_share(ciphers, organization_id, collection_ids) + .await?) + } } diff --git a/crates/bitwarden-vault/src/cipher/cipher_client/share_cipher.rs b/crates/bitwarden-vault/src/cipher/cipher_client/share_cipher.rs index c2ebd0637..c51c53bc2 100644 --- a/crates/bitwarden-vault/src/cipher/cipher_client/share_cipher.rs +++ b/crates/bitwarden-vault/src/cipher/cipher_client/share_cipher.rs @@ -221,14 +221,12 @@ impl CiphersClient { Ok(()) } - /// Moves a group of ciphers into an organization, adds them to collections, and calls the - /// share_ciphers API. - pub async fn share_ciphers_bulk( + async fn prepare_encrypted_ciphers_for_bulk_share( &self, cipher_views: Vec, organization_id: OrganizationId, collection_ids: Vec, - ) -> Result, CipherError> { + ) -> Result, CipherError> { let mut encrypted_ciphers: Vec = Vec::new(); for mut cv in cipher_views { cv = self.update_organization_and_collections( @@ -239,6 +237,38 @@ impl CiphersClient { self.update_password_history(&mut cv, None).await?; encrypted_ciphers.push(self.encrypt(cv)?); } + Ok(encrypted_ciphers) + } + + #[cfg(feature = "uniffi")] + /// Prepares ciphers for bulk sharing by assigning them to an organization, adding them to + /// collections, updating password history, and encrypting them. This method is exposed for + /// UniFFI bindings. Can be removed once Mobile supports authenticated API calls via the SDK. + pub async fn prepare_ciphers_for_bulk_share( + &self, + cipher_views: Vec, + organization_id: OrganizationId, + collection_ids: Vec, + ) -> Result, CipherError> { + self.prepare_encrypted_ciphers_for_bulk_share(cipher_views, organization_id, collection_ids) + .await + } + + /// Moves a group of ciphers into an organization, adds them to collections, and calls the + /// share_ciphers API. + pub async fn share_ciphers_bulk( + &self, + cipher_views: Vec, + organization_id: OrganizationId, + collection_ids: Vec, + ) -> Result, CipherError> { + let encrypted_ciphers = self + .prepare_encrypted_ciphers_for_bulk_share( + cipher_views, + organization_id, + collection_ids.clone(), + ) + .await?; let api_client = &self .client