Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions crates/bitwarden-uniffi/src/vault/ciphers.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use bitwarden_collections::collection::CollectionId;
use bitwarden_core::OrganizationId;
use bitwarden_vault::{
Cipher, CipherListView, CipherView, DecryptCipherListResult, EncryptionContext,
Expand Down Expand Up @@ -53,4 +54,17 @@ impl CiphersClient {
) -> Result<CipherView> {
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<CipherView>,
organization_id: OrganizationId,
collection_ids: Vec<CollectionId>,
) -> Result<Vec<EncryptionContext>> {
Ok(self
.0
.prepare_ciphers_for_bulk_share(ciphers, organization_id, collection_ids)
.await?)
}
}
38 changes: 34 additions & 4 deletions crates/bitwarden-vault/src/cipher/cipher_client/share_cipher.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<CipherView>,
organization_id: OrganizationId,
collection_ids: Vec<CollectionId>,
) -> Result<Vec<Cipher>, CipherError> {
) -> Result<Vec<EncryptionContext>, CipherError> {
let mut encrypted_ciphers: Vec<EncryptionContext> = Vec::new();
for mut cv in cipher_views {
cv = self.update_organization_and_collections(
Expand All @@ -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<CipherView>,
organization_id: OrganizationId,
collection_ids: Vec<CollectionId>,
) -> Result<Vec<EncryptionContext>, 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<CipherView>,
organization_id: OrganizationId,
collection_ids: Vec<CollectionId>,
) -> Result<Vec<Cipher>, CipherError> {
let encrypted_ciphers = self
.prepare_encrypted_ciphers_for_bulk_share(
cipher_views,
organization_id,
collection_ids.clone(),
)
.await?;

let api_client = &self
.client
Expand Down
Loading