commit f27455a26f90653140c28b702de78c60dec4a420
parent 06888251e3fa8d53f7b7360c5da8acdc2c8a29ca
Author: Daniel GarcĂa <dani-garcia@users.noreply.github.com>
Date: Mon, 25 Jan 2021 12:23:00 +0100
Merge pull request #1328 from jjlin/restore-rev-date
Add cipher response to restore operations
Diffstat:
1 file changed, 17 insertions(+), 11 deletions(-)
diff --git a/src/api/core/ciphers.rs b/src/api/core/ciphers.rs
@@ -967,18 +967,18 @@ fn delete_cipher_selected_put_admin(data: JsonUpcase<Value>, headers: Headers, c
}
#[put("/ciphers/<uuid>/restore")]
-fn restore_cipher_put(uuid: String, headers: Headers, conn: DbConn, nt: Notify) -> EmptyResult {
+fn restore_cipher_put(uuid: String, headers: Headers, conn: DbConn, nt: Notify) -> JsonResult {
_restore_cipher_by_uuid(&uuid, &headers, &conn, &nt)
}
#[put("/ciphers/<uuid>/restore-admin")]
-fn restore_cipher_put_admin(uuid: String, headers: Headers, conn: DbConn, nt: Notify) -> EmptyResult {
+fn restore_cipher_put_admin(uuid: String, headers: Headers, conn: DbConn, nt: Notify) -> JsonResult {
_restore_cipher_by_uuid(&uuid, &headers, &conn, &nt)
}
#[put("/ciphers/restore", data = "<data>")]
-fn restore_cipher_selected(data: JsonUpcase<Value>, headers: Headers, conn: DbConn, nt: Notify) -> EmptyResult {
- _restore_multiple_ciphers(data, headers, conn, nt)
+fn restore_cipher_selected(data: JsonUpcase<Value>, headers: Headers, conn: DbConn, nt: Notify) -> JsonResult {
+ _restore_multiple_ciphers(data, &headers, &conn, &nt)
}
#[derive(Deserialize)]
@@ -1134,7 +1134,7 @@ fn _delete_multiple_ciphers(data: JsonUpcase<Value>, headers: Headers, conn: DbC
Ok(())
}
-fn _restore_cipher_by_uuid(uuid: &str, headers: &Headers, conn: &DbConn, nt: &Notify) -> EmptyResult {
+fn _restore_cipher_by_uuid(uuid: &str, headers: &Headers, conn: &DbConn, nt: &Notify) -> JsonResult {
let mut cipher = match Cipher::find_by_uuid(&uuid, &conn) {
Some(cipher) => cipher,
None => err!("Cipher doesn't exist"),
@@ -1148,10 +1148,10 @@ fn _restore_cipher_by_uuid(uuid: &str, headers: &Headers, conn: &DbConn, nt: &No
cipher.save(&conn)?;
nt.send_cipher_update(UpdateType::CipherUpdate, &cipher, &cipher.update_users_revision(&conn));
- Ok(())
+ Ok(Json(cipher.to_json(&headers.host, &headers.user.uuid, &conn)))
}
-fn _restore_multiple_ciphers(data: JsonUpcase<Value>, headers: Headers, conn: DbConn, nt: Notify) -> EmptyResult {
+fn _restore_multiple_ciphers(data: JsonUpcase<Value>, headers: &Headers, conn: &DbConn, nt: &Notify) -> JsonResult {
let data: Value = data.into_inner().data;
let uuids = match data.get("Ids") {
@@ -1162,13 +1162,19 @@ fn _restore_multiple_ciphers(data: JsonUpcase<Value>, headers: Headers, conn: Db
None => err!("Request missing ids field"),
};
+ let mut ciphers: Vec<Value> = Vec::new();
for uuid in uuids {
- if let error @ Err(_) = _restore_cipher_by_uuid(uuid, &headers, &conn, &nt) {
- return error;
- };
+ match _restore_cipher_by_uuid(uuid, headers, conn, nt) {
+ Ok(json) => ciphers.push(json.into_inner()),
+ err => return err
+ }
}
- Ok(())
+ Ok(Json(json!({
+ "Data": ciphers,
+ "Object": "list",
+ "ContinuationToken": null
+ })))
}
fn _delete_cipher_attachment_by_id(