Spiegel von
https://github.com/dani-garcia/vaultwarden.git
synchronisiert 2024-11-22 05:10:29 +01:00
CollectionCipher::save() and delete() should return QueryResult instead of bool
Dieser Commit ist enthalten in:
Ursprung
1049646e27
Commit
5292d38c73
3 geänderte Dateien mit 22 neuen und 16 gelöschten Zeilen
|
@ -333,9 +333,15 @@ fn post_collections_admin(uuid: String, data: JsonUpcase<CollectionsAdminData>,
|
||||||
Some(collection) => {
|
Some(collection) => {
|
||||||
if collection.is_writable_by_user(&headers.user.uuid, &conn) {
|
if collection.is_writable_by_user(&headers.user.uuid, &conn) {
|
||||||
if posted_collections.contains(&collection.uuid) { // Add to collection
|
if posted_collections.contains(&collection.uuid) { // Add to collection
|
||||||
CollectionCipher::save(&cipher.uuid, &collection.uuid, &conn);
|
match CollectionCipher::save(&cipher.uuid, &collection.uuid, &conn) {
|
||||||
|
Ok(()) => (),
|
||||||
|
Err(_) => err!("Failed to add cipher to collection")
|
||||||
|
};
|
||||||
} else { // Remove from collection
|
} else { // Remove from collection
|
||||||
CollectionCipher::delete(&cipher.uuid, &collection.uuid, &conn);
|
match CollectionCipher::delete(&cipher.uuid, &collection.uuid, &conn) {
|
||||||
|
Ok(()) => (),
|
||||||
|
Err(_) => err!("Failed to remove cipher from collection")
|
||||||
|
};
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
err!("No rights to modify the collection")
|
err!("No rights to modify the collection")
|
||||||
|
@ -438,7 +444,10 @@ fn share_cipher_by_uuid(uuid: &str, data: ShareCipherData, headers: &Headers, co
|
||||||
None => err!("Invalid collection ID provided"),
|
None => err!("Invalid collection ID provided"),
|
||||||
Some(collection) => {
|
Some(collection) => {
|
||||||
if collection.is_writable_by_user(&headers.user.uuid, &conn) {
|
if collection.is_writable_by_user(&headers.user.uuid, &conn) {
|
||||||
CollectionCipher::save(&cipher.uuid.clone(), &collection.uuid, &conn);
|
match CollectionCipher::save(&cipher.uuid.clone(), &collection.uuid, &conn) {
|
||||||
|
Ok(()) => (),
|
||||||
|
Err(_) => err!("Failed to add cipher to collection")
|
||||||
|
};
|
||||||
shared_to_collection = true;
|
shared_to_collection = true;
|
||||||
} else {
|
} else {
|
||||||
err!("No rights to modify the collection")
|
err!("No rights to modify the collection")
|
||||||
|
|
|
@ -663,7 +663,10 @@ fn post_org_import(query: OrgIdData, data: JsonUpcase<ImportData>, headers: Head
|
||||||
Err(_) => err!("Failed to assign to collection")
|
Err(_) => err!("Failed to assign to collection")
|
||||||
};
|
};
|
||||||
|
|
||||||
CollectionCipher::save(cipher_id, coll_id, &conn);
|
match CollectionCipher::save(cipher_id, coll_id, &conn) {
|
||||||
|
Ok(()) => (),
|
||||||
|
Err(_) => err!("Failed to add cipher to collection")
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
let mut user = headers.user;
|
let mut user = headers.user;
|
||||||
|
|
|
@ -259,25 +259,19 @@ pub struct CollectionCipher {
|
||||||
|
|
||||||
/// Database methods
|
/// Database methods
|
||||||
impl CollectionCipher {
|
impl CollectionCipher {
|
||||||
pub fn save(cipher_uuid: &str, collection_uuid: &str, conn: &DbConn) -> bool {
|
pub fn save(cipher_uuid: &str, collection_uuid: &str, conn: &DbConn) -> QueryResult<()> {
|
||||||
match diesel::replace_into(ciphers_collections::table)
|
diesel::replace_into(ciphers_collections::table)
|
||||||
.values((
|
.values((
|
||||||
ciphers_collections::cipher_uuid.eq(cipher_uuid),
|
ciphers_collections::cipher_uuid.eq(cipher_uuid),
|
||||||
ciphers_collections::collection_uuid.eq(collection_uuid),
|
ciphers_collections::collection_uuid.eq(collection_uuid),
|
||||||
)).execute(&**conn) {
|
)).execute(&**conn).and(Ok(()))
|
||||||
Ok(1) => true, // One row inserted
|
|
||||||
_ => false,
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn delete(cipher_uuid: &str, collection_uuid: &str, conn: &DbConn) -> bool {
|
pub fn delete(cipher_uuid: &str, collection_uuid: &str, conn: &DbConn) -> QueryResult<()> {
|
||||||
match diesel::delete(ciphers_collections::table
|
diesel::delete(ciphers_collections::table
|
||||||
.filter(ciphers_collections::cipher_uuid.eq(cipher_uuid))
|
.filter(ciphers_collections::cipher_uuid.eq(cipher_uuid))
|
||||||
.filter(ciphers_collections::collection_uuid.eq(collection_uuid)))
|
.filter(ciphers_collections::collection_uuid.eq(collection_uuid)))
|
||||||
.execute(&**conn) {
|
.execute(&**conn).and(Ok(()))
|
||||||
Ok(1) => true, // One row deleted
|
|
||||||
_ => false,
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn delete_all_by_cipher(cipher_uuid: &str, conn: &DbConn) -> QueryResult<()> {
|
pub fn delete_all_by_cipher(cipher_uuid: &str, conn: &DbConn) -> QueryResult<()> {
|
||||||
|
|
Laden …
In neuem Issue referenzieren