Skip to content

Commit d9c7550

Browse files
authored
Fix posting cipher with readonly collections (#6578)
* Fix posting cipher with readonly collections This fix will check if a collection is writeable for the user, and if not error out early instead of creating the cipher first and leaving it. It will also save some database transactions. Fixes #6562 Signed-off-by: BlackDex <black.dex@gmail.com> * Adjust code to delete on error Signed-off-by: BlackDex <black.dex@gmail.com> --------- Signed-off-by: BlackDex <black.dex@gmail.com>
1 parent 0ab7784 commit d9c7550

File tree

1 file changed

+5
-7
lines changed

1 file changed

+5
-7
lines changed

src/api/core/ciphers.rs

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -322,12 +322,6 @@ async fn post_ciphers_create(
322322
) -> JsonResult {
323323
let mut data: ShareCipherData = data.into_inner();
324324

325-
// Check if there are one more more collections selected when this cipher is part of an organization.
326-
// err if this is not the case before creating an empty cipher.
327-
if data.cipher.organization_id.is_some() && data.collection_ids.is_empty() {
328-
err!("You must select at least one collection.");
329-
}
330-
331325
// This check is usually only needed in update_cipher_from_data(), but we
332326
// need it here as well to avoid creating an empty cipher in the call to
333327
// cipher.save() below.
@@ -345,7 +339,11 @@ async fn post_ciphers_create(
345339
// or otherwise), we can just ignore this field entirely.
346340
data.cipher.last_known_revision_date = None;
347341

348-
share_cipher_by_uuid(&cipher.uuid, data, &headers, &conn, &nt, None).await
342+
let res = share_cipher_by_uuid(&cipher.uuid, data, &headers, &conn, &nt, None).await;
343+
if res.is_err() {
344+
cipher.delete(&conn).await?;
345+
}
346+
res
349347
}
350348

351349
/// Called when creating a new user-owned cipher.

0 commit comments

Comments
 (0)