summaryrefslogtreecommitdiff
path: root/src/api
diff options
context:
space:
mode:
authorDaniel GarcĂ­a <[email protected]>2024-06-24 21:17:59 +0200
committerGitHub <[email protected]>2024-06-24 21:17:59 +0200
commita4c7fadbf4ffa242fb78ebd152080028e7f2993c (patch)
tree37e0289ac7e9defcc70ac766c62c9cdff65b8629 /src/api
parent8e2a87fd79d56e4aa9ddd4d17080eebce0cf83af (diff)
downloadvaultwarden-a4c7fadbf4ffa242fb78ebd152080028e7f2993c.tar.gz
vaultwarden-a4c7fadbf4ffa242fb78ebd152080028e7f2993c.zip
Change some missing PascalCase keys (#4671)
Diffstat (limited to 'src/api')
-rw-r--r--src/api/admin.rs8
-rw-r--r--src/api/core/ciphers.rs72
-rw-r--r--src/api/core/organizations.rs32
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<Html<
async fn get_user_by_mail_json(mail: &str, _token: AdminToken, mut conn: DbConn) -> 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 = "<data>")]
-async fn delete_cipher_selected(data: Json<Value>, headers: Headers, conn: DbConn, nt: Notify<'_>) -> EmptyResult {
+async fn delete_cipher_selected(
+ data: Json<CipherIdsData>,
+ headers: Headers,
+ conn: DbConn,
+ nt: Notify<'_>,
+) -> EmptyResult {
_delete_multiple_ciphers(data, headers, conn, false, nt).await // permanent delete
}
#[post("/ciphers/delete", data = "<data>")]
-async fn delete_cipher_selected_post(data: Json<Value>, headers: Headers, conn: DbConn, nt: Notify<'_>) -> EmptyResult {
+async fn delete_cipher_selected_post(
+ data: Json<CipherIdsData>,
+ headers: Headers,
+ conn: DbConn,
+ nt: Notify<'_>,
+) -> EmptyResult {
_delete_multiple_ciphers(data, headers, conn, false, nt).await // permanent delete
}
#[put("/ciphers/delete", data = "<data>")]
-async fn delete_cipher_selected_put(data: Json<Value>, headers: Headers, conn: DbConn, nt: Notify<'_>) -> EmptyResult {
+async fn delete_cipher_selected_put(
+ data: Json<CipherIdsData>,
+ headers: Headers,
+ conn: DbConn,
+ nt: Notify<'_>,
+) -> EmptyResult {
_delete_multiple_ciphers(data, headers, conn, true, nt).await // soft delete
}
#[delete("/ciphers/admin", data = "<data>")]
async fn delete_cipher_selected_admin(
- data: Json<Value>,
+ data: Json<CipherIdsData>,
headers: Headers,
conn: DbConn,
nt: Notify<'_>,
@@ -1362,7 +1377,7 @@ async fn delete_cipher_selected_admin(
#[post("/ciphers/delete-admin", data = "<data>")]
async fn delete_cipher_selected_post_admin(
- data: Json<Value>,
+ data: Json<CipherIdsData>,
headers: Headers,
conn: DbConn,
nt: Notify<'_>,
@@ -1372,7 +1387,7 @@ async fn delete_cipher_selected_post_admin(
#[put("/ciphers/delete-admin", data = "<data>")]
async fn delete_cipher_selected_put_admin(
- data: Json<Value>,
+ data: Json<CipherIdsData>,
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 = "<data>")]
-async fn restore_cipher_selected(data: Json<Value>, headers: Headers, mut conn: DbConn, nt: Notify<'_>) -> JsonResult {
+async fn restore_cipher_selected(
+ data: Json<CipherIdsData>,
+ 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<String>,
+}
+
async fn _delete_multiple_ciphers(
- data: Json<Value>,
+ data: Json<CipherIdsData>,
headers: Headers,
mut conn: DbConn,
soft_delete: bool,
nt: Notify<'_>,
) -> EmptyResult {
- 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();
- 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<Value>,
+ data: Json<CipherIdsData>,
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<Value> = 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/<org_id>/users/activate", data = "<data>")]
async fn bulk_activate_organization_user(
org_id: &str,
- data: Json<Value>,
+ data: Json<OrgBulkIds>,
headers: AdminHeaders,
conn: DbConn,
) -> Json<Value> {
@@ -2113,32 +2113,26 @@ async fn restore_organization_user(
#[put("/organizations/<org_id>/users/restore", data = "<data>")]
async fn bulk_restore_organization_user(
org_id: &str,
- data: Json<Value>,
+ data: Json<OrgBulkIds>,
headers: AdminHeaders,
mut conn: DbConn,
) -> Json<Value> {
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!({