mirror of
https://github.com/dani-garcia/vaultwarden
synced 2024-11-21 19:33:11 +00:00
Change some missing PascalCase keys (#4671)
This commit is contained in:
parent
8e2a87fd79
commit
a4c7fadbf4
3 changed files with 58 additions and 54 deletions
|
@ -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 {
|
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 {
|
if let Some(u) = User::find_by_mail(mail, &mut conn).await {
|
||||||
let mut usr = u.to_json(&mut conn).await;
|
let mut usr = u.to_json(&mut conn).await;
|
||||||
usr["UserEnabled"] = json!(u.enabled);
|
usr["userEnabled"] = json!(u.enabled);
|
||||||
usr["CreatedAt"] = json!(format_naive_datetime_local(&u.created_at, DT_FMT));
|
usr["createdAt"] = json!(format_naive_datetime_local(&u.created_at, DT_FMT));
|
||||||
Ok(Json(usr))
|
Ok(Json(usr))
|
||||||
} else {
|
} else {
|
||||||
err_code!("User doesn't exist", Status::NotFound.code);
|
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 {
|
async fn get_user_json(uuid: &str, _token: AdminToken, mut conn: DbConn) -> JsonResult {
|
||||||
let u = get_user_or_404(uuid, &mut conn).await?;
|
let u = get_user_or_404(uuid, &mut conn).await?;
|
||||||
let mut usr = u.to_json(&mut conn).await;
|
let mut usr = u.to_json(&mut conn).await;
|
||||||
usr["UserEnabled"] = json!(u.enabled);
|
usr["userEnabled"] = json!(u.enabled);
|
||||||
usr["CreatedAt"] = json!(format_naive_datetime_local(&u.created_at, DT_FMT));
|
usr["createdAt"] = json!(format_naive_datetime_local(&u.created_at, DT_FMT));
|
||||||
Ok(Json(usr))
|
Ok(Json(usr))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1336,23 +1336,38 @@ async fn delete_cipher_admin(uuid: &str, headers: Headers, mut conn: DbConn, nt:
|
||||||
}
|
}
|
||||||
|
|
||||||
#[delete("/ciphers", data = "<data>")]
|
#[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
|
_delete_multiple_ciphers(data, headers, conn, false, nt).await // permanent delete
|
||||||
}
|
}
|
||||||
|
|
||||||
#[post("/ciphers/delete", data = "<data>")]
|
#[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
|
_delete_multiple_ciphers(data, headers, conn, false, nt).await // permanent delete
|
||||||
}
|
}
|
||||||
|
|
||||||
#[put("/ciphers/delete", data = "<data>")]
|
#[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_multiple_ciphers(data, headers, conn, true, nt).await // soft delete
|
||||||
}
|
}
|
||||||
|
|
||||||
#[delete("/ciphers/admin", data = "<data>")]
|
#[delete("/ciphers/admin", data = "<data>")]
|
||||||
async fn delete_cipher_selected_admin(
|
async fn delete_cipher_selected_admin(
|
||||||
data: Json<Value>,
|
data: Json<CipherIdsData>,
|
||||||
headers: Headers,
|
headers: Headers,
|
||||||
conn: DbConn,
|
conn: DbConn,
|
||||||
nt: Notify<'_>,
|
nt: Notify<'_>,
|
||||||
|
@ -1362,7 +1377,7 @@ async fn delete_cipher_selected_admin(
|
||||||
|
|
||||||
#[post("/ciphers/delete-admin", data = "<data>")]
|
#[post("/ciphers/delete-admin", data = "<data>")]
|
||||||
async fn delete_cipher_selected_post_admin(
|
async fn delete_cipher_selected_post_admin(
|
||||||
data: Json<Value>,
|
data: Json<CipherIdsData>,
|
||||||
headers: Headers,
|
headers: Headers,
|
||||||
conn: DbConn,
|
conn: DbConn,
|
||||||
nt: Notify<'_>,
|
nt: Notify<'_>,
|
||||||
|
@ -1372,7 +1387,7 @@ async fn delete_cipher_selected_post_admin(
|
||||||
|
|
||||||
#[put("/ciphers/delete-admin", data = "<data>")]
|
#[put("/ciphers/delete-admin", data = "<data>")]
|
||||||
async fn delete_cipher_selected_put_admin(
|
async fn delete_cipher_selected_put_admin(
|
||||||
data: Json<Value>,
|
data: Json<CipherIdsData>,
|
||||||
headers: Headers,
|
headers: Headers,
|
||||||
conn: DbConn,
|
conn: DbConn,
|
||||||
nt: Notify<'_>,
|
nt: Notify<'_>,
|
||||||
|
@ -1391,7 +1406,12 @@ async fn restore_cipher_put_admin(uuid: &str, headers: Headers, mut conn: DbConn
|
||||||
}
|
}
|
||||||
|
|
||||||
#[put("/ciphers/restore", data = "<data>")]
|
#[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
|
_restore_multiple_ciphers(data, &headers, &mut conn, &nt).await
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1581,25 +1601,23 @@ async fn _delete_cipher_by_uuid(
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Deserialize)]
|
||||||
|
#[serde(rename_all = "camelCase")]
|
||||||
|
struct CipherIdsData {
|
||||||
|
ids: Vec<String>,
|
||||||
|
}
|
||||||
|
|
||||||
async fn _delete_multiple_ciphers(
|
async fn _delete_multiple_ciphers(
|
||||||
data: Json<Value>,
|
data: Json<CipherIdsData>,
|
||||||
headers: Headers,
|
headers: Headers,
|
||||||
mut conn: DbConn,
|
mut conn: DbConn,
|
||||||
soft_delete: bool,
|
soft_delete: bool,
|
||||||
nt: Notify<'_>,
|
nt: Notify<'_>,
|
||||||
) -> EmptyResult {
|
) -> EmptyResult {
|
||||||
let data: Value = data.into_inner();
|
let data = data.into_inner();
|
||||||
|
|
||||||
let uuids = match data.get("Ids") {
|
for uuid in data.ids {
|
||||||
Some(ids) => match ids.as_array() {
|
if let error @ Err(_) = _delete_cipher_by_uuid(&uuid, &headers, &mut conn, soft_delete, &nt).await {
|
||||||
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 {
|
|
||||||
return error;
|
return error;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
@ -1647,24 +1665,16 @@ async fn _restore_cipher_by_uuid(uuid: &str, headers: &Headers, conn: &mut DbCon
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn _restore_multiple_ciphers(
|
async fn _restore_multiple_ciphers(
|
||||||
data: Json<Value>,
|
data: Json<CipherIdsData>,
|
||||||
headers: &Headers,
|
headers: &Headers,
|
||||||
conn: &mut DbConn,
|
conn: &mut DbConn,
|
||||||
nt: &Notify<'_>,
|
nt: &Notify<'_>,
|
||||||
) -> JsonResult {
|
) -> JsonResult {
|
||||||
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"),
|
|
||||||
};
|
|
||||||
|
|
||||||
let mut ciphers: Vec<Value> = Vec::new();
|
let mut ciphers: Vec<Value> = Vec::new();
|
||||||
for uuid in uuids {
|
for uuid in data.ids {
|
||||||
match _restore_cipher_by_uuid(uuid, headers, conn, nt).await {
|
match _restore_cipher_by_uuid(&uuid, headers, conn, nt).await {
|
||||||
Ok(json) => ciphers.push(json.into_inner()),
|
Ok(json) => ciphers.push(json.into_inner()),
|
||||||
err => return err,
|
err => return err,
|
||||||
}
|
}
|
||||||
|
|
|
@ -2093,7 +2093,7 @@ async fn activate_organization_user(
|
||||||
#[put("/organizations/<org_id>/users/activate", data = "<data>")]
|
#[put("/organizations/<org_id>/users/activate", data = "<data>")]
|
||||||
async fn bulk_activate_organization_user(
|
async fn bulk_activate_organization_user(
|
||||||
org_id: &str,
|
org_id: &str,
|
||||||
data: Json<Value>,
|
data: Json<OrgBulkIds>,
|
||||||
headers: AdminHeaders,
|
headers: AdminHeaders,
|
||||||
conn: DbConn,
|
conn: DbConn,
|
||||||
) -> Json<Value> {
|
) -> Json<Value> {
|
||||||
|
@ -2113,32 +2113,26 @@ async fn restore_organization_user(
|
||||||
#[put("/organizations/<org_id>/users/restore", data = "<data>")]
|
#[put("/organizations/<org_id>/users/restore", data = "<data>")]
|
||||||
async fn bulk_restore_organization_user(
|
async fn bulk_restore_organization_user(
|
||||||
org_id: &str,
|
org_id: &str,
|
||||||
data: Json<Value>,
|
data: Json<OrgBulkIds>,
|
||||||
headers: AdminHeaders,
|
headers: AdminHeaders,
|
||||||
mut conn: DbConn,
|
mut conn: DbConn,
|
||||||
) -> Json<Value> {
|
) -> Json<Value> {
|
||||||
let data = data.into_inner();
|
let data = data.into_inner();
|
||||||
|
|
||||||
let mut bulk_response = Vec::new();
|
let mut bulk_response = Vec::new();
|
||||||
match data["Ids"].as_array() {
|
for org_user_id in data.ids {
|
||||||
Some(org_users) => {
|
let err_msg = match _restore_organization_user(org_id, &org_user_id, &headers, &mut conn).await {
|
||||||
for org_user_id in org_users {
|
Ok(_) => String::new(),
|
||||||
let org_user_id = org_user_id.as_str().unwrap_or_default();
|
Err(e) => format!("{e:?}"),
|
||||||
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!(
|
bulk_response.push(json!(
|
||||||
{
|
{
|
||||||
"object": "OrganizationUserBulkResponseModel",
|
"object": "OrganizationUserBulkResponseModel",
|
||||||
"id": org_user_id,
|
"id": org_user_id,
|
||||||
"error": err_msg
|
"error": err_msg
|
||||||
}
|
|
||||||
));
|
|
||||||
}
|
}
|
||||||
}
|
));
|
||||||
None => error!("No users to restore"),
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Json(json!({
|
Json(json!({
|
||||||
|
|
Loading…
Reference in a new issue