From a4c7fadbf4ffa242fb78ebd152080028e7f2993c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Garc=C3=ADa?= Date: Mon, 24 Jun 2024 21:17:59 +0200 Subject: [PATCH] Change some missing PascalCase keys (#4671) --- src/api/admin.rs | 8 ++-- src/api/core/ciphers.rs | 72 ++++++++++++++++++++--------------- src/api/core/organizations.rs | 32 +++++++--------- 3 files changed, 58 insertions(+), 54 deletions(-) diff --git a/src/api/admin.rs b/src/api/admin.rs index 22e6f80b..58a056b6 100644 --- a/src/api/admin.rs +++ b/src/api/admin.rs @@ -364,8 +364,8 @@ async fn users_overview(_token: AdminToken, mut conn: DbConn) -> ApiResult JsonResult { if let Some(u) = User::find_by_mail(mail, &mut conn).await { let mut usr = u.to_json(&mut conn).await; - usr["UserEnabled"] = json!(u.enabled); - usr["CreatedAt"] = json!(format_naive_datetime_local(&u.created_at, DT_FMT)); + usr["userEnabled"] = json!(u.enabled); + usr["createdAt"] = json!(format_naive_datetime_local(&u.created_at, DT_FMT)); Ok(Json(usr)) } else { err_code!("User doesn't exist", Status::NotFound.code); @@ -376,8 +376,8 @@ async fn get_user_by_mail_json(mail: &str, _token: AdminToken, mut conn: DbConn) async fn get_user_json(uuid: &str, _token: AdminToken, mut conn: DbConn) -> JsonResult { let u = get_user_or_404(uuid, &mut conn).await?; let mut usr = u.to_json(&mut conn).await; - usr["UserEnabled"] = json!(u.enabled); - usr["CreatedAt"] = json!(format_naive_datetime_local(&u.created_at, DT_FMT)); + usr["userEnabled"] = json!(u.enabled); + usr["createdAt"] = json!(format_naive_datetime_local(&u.created_at, DT_FMT)); Ok(Json(usr)) } diff --git a/src/api/core/ciphers.rs b/src/api/core/ciphers.rs index 0884ef1f..4a6bc8b4 100644 --- a/src/api/core/ciphers.rs +++ b/src/api/core/ciphers.rs @@ -1336,23 +1336,38 @@ async fn delete_cipher_admin(uuid: &str, headers: Headers, mut conn: DbConn, nt: } #[delete("/ciphers", data = "")] -async fn delete_cipher_selected(data: Json, headers: Headers, conn: DbConn, nt: Notify<'_>) -> EmptyResult { +async fn delete_cipher_selected( + data: Json, + headers: Headers, + conn: DbConn, + nt: Notify<'_>, +) -> EmptyResult { _delete_multiple_ciphers(data, headers, conn, false, nt).await // permanent delete } #[post("/ciphers/delete", data = "")] -async fn delete_cipher_selected_post(data: Json, headers: Headers, conn: DbConn, nt: Notify<'_>) -> EmptyResult { +async fn delete_cipher_selected_post( + data: Json, + headers: Headers, + conn: DbConn, + nt: Notify<'_>, +) -> EmptyResult { _delete_multiple_ciphers(data, headers, conn, false, nt).await // permanent delete } #[put("/ciphers/delete", data = "")] -async fn delete_cipher_selected_put(data: Json, headers: Headers, conn: DbConn, nt: Notify<'_>) -> EmptyResult { +async fn delete_cipher_selected_put( + data: Json, + headers: Headers, + conn: DbConn, + nt: Notify<'_>, +) -> EmptyResult { _delete_multiple_ciphers(data, headers, conn, true, nt).await // soft delete } #[delete("/ciphers/admin", data = "")] async fn delete_cipher_selected_admin( - data: Json, + data: Json, headers: Headers, conn: DbConn, nt: Notify<'_>, @@ -1362,7 +1377,7 @@ async fn delete_cipher_selected_admin( #[post("/ciphers/delete-admin", data = "")] async fn delete_cipher_selected_post_admin( - data: Json, + data: Json, headers: Headers, conn: DbConn, nt: Notify<'_>, @@ -1372,7 +1387,7 @@ async fn delete_cipher_selected_post_admin( #[put("/ciphers/delete-admin", data = "")] async fn delete_cipher_selected_put_admin( - data: Json, + data: Json, headers: Headers, conn: DbConn, nt: Notify<'_>, @@ -1391,7 +1406,12 @@ async fn restore_cipher_put_admin(uuid: &str, headers: Headers, mut conn: DbConn } #[put("/ciphers/restore", data = "")] -async fn restore_cipher_selected(data: Json, headers: Headers, mut conn: DbConn, nt: Notify<'_>) -> JsonResult { +async fn restore_cipher_selected( + data: Json, + headers: Headers, + mut conn: DbConn, + nt: Notify<'_>, +) -> JsonResult { _restore_multiple_ciphers(data, &headers, &mut conn, &nt).await } @@ -1581,25 +1601,23 @@ async fn _delete_cipher_by_uuid( Ok(()) } +#[derive(Deserialize)] +#[serde(rename_all = "camelCase")] +struct CipherIdsData { + ids: Vec, +} + async fn _delete_multiple_ciphers( - data: Json, + data: Json, headers: Headers, mut conn: DbConn, soft_delete: bool, nt: Notify<'_>, ) -> EmptyResult { - let data: Value = data.into_inner(); + let data = data.into_inner(); - let uuids = match data.get("Ids") { - Some(ids) => match ids.as_array() { - Some(ids) => ids.iter().filter_map(Value::as_str), - None => err!("Posted ids field is not an array"), - }, - None => err!("Request missing ids field"), - }; - - for uuid in uuids { - if let error @ Err(_) = _delete_cipher_by_uuid(uuid, &headers, &mut conn, soft_delete, &nt).await { + for uuid in data.ids { + if let error @ Err(_) = _delete_cipher_by_uuid(&uuid, &headers, &mut conn, soft_delete, &nt).await { return error; }; } @@ -1647,24 +1665,16 @@ async fn _restore_cipher_by_uuid(uuid: &str, headers: &Headers, conn: &mut DbCon } async fn _restore_multiple_ciphers( - data: Json, + data: Json, headers: &Headers, conn: &mut DbConn, nt: &Notify<'_>, ) -> JsonResult { - let data: Value = data.into_inner(); - - let uuids = match data.get("Ids") { - Some(ids) => match ids.as_array() { - Some(ids) => ids.iter().filter_map(Value::as_str), - None => err!("Posted ids field is not an array"), - }, - None => err!("Request missing ids field"), - }; + let data = data.into_inner(); let mut ciphers: Vec = Vec::new(); - for uuid in uuids { - match _restore_cipher_by_uuid(uuid, headers, conn, nt).await { + for uuid in data.ids { + match _restore_cipher_by_uuid(&uuid, headers, conn, nt).await { Ok(json) => ciphers.push(json.into_inner()), err => return err, } diff --git a/src/api/core/organizations.rs b/src/api/core/organizations.rs index 13fc4961..204dd56f 100644 --- a/src/api/core/organizations.rs +++ b/src/api/core/organizations.rs @@ -2093,7 +2093,7 @@ async fn activate_organization_user( #[put("/organizations//users/activate", data = "")] async fn bulk_activate_organization_user( org_id: &str, - data: Json, + data: Json, headers: AdminHeaders, conn: DbConn, ) -> Json { @@ -2113,32 +2113,26 @@ async fn restore_organization_user( #[put("/organizations//users/restore", data = "")] async fn bulk_restore_organization_user( org_id: &str, - data: Json, + data: Json, headers: AdminHeaders, mut conn: DbConn, ) -> Json { let data = data.into_inner(); let mut bulk_response = Vec::new(); - match data["Ids"].as_array() { - Some(org_users) => { - for org_user_id in org_users { - let org_user_id = org_user_id.as_str().unwrap_or_default(); - let err_msg = match _restore_organization_user(org_id, org_user_id, &headers, &mut conn).await { - Ok(_) => String::new(), - Err(e) => format!("{e:?}"), - }; + for org_user_id in data.ids { + let err_msg = match _restore_organization_user(org_id, &org_user_id, &headers, &mut conn).await { + Ok(_) => String::new(), + Err(e) => format!("{e:?}"), + }; - bulk_response.push(json!( - { - "object": "OrganizationUserBulkResponseModel", - "id": org_user_id, - "error": err_msg - } - )); + bulk_response.push(json!( + { + "object": "OrganizationUserBulkResponseModel", + "id": org_user_id, + "error": err_msg } - } - None => error!("No users to restore"), + )); } Json(json!({