Skip to content

Commit

Permalink
Adding "UserEnabled" and "CreatedAt" member to the json output of a U…
Browse files Browse the repository at this point in the history
…ser in the admin/users and admin/users/<ID> web routes.
  • Loading branch information
Lowaiz committed Jun 2, 2022
1 parent 3713f2d commit ab87802
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions src/api/admin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -307,10 +307,14 @@ fn logout(cookies: &CookieJar<'_>, referer: Referer) -> Redirect {

#[get("/users")]
async fn get_users_json(_token: AdminToken, conn: DbConn) -> Json<Value> {
const DT_FMT: &str = "%Y-%m-%d %H:%M:%S %Z";
let users_json = stream::iter(User::get_all(&conn).await)
.then(|u| async {
let u = u; // Move out this single variable
u.to_json(&conn).await
let mut usr = u.to_json(&conn).await;
usr["UserEnabled"] = json!(u.enabled);
usr["CreatedAt"] = json!(format_naive_datetime_local(&u.created_at, DT_FMT));
usr
})
.collect::<Vec<Value>>()
.await;
Expand Down Expand Up @@ -346,9 +350,12 @@ async fn users_overview(_token: AdminToken, conn: DbConn) -> ApiResult<Html<Stri

#[get("/users/<uuid>")]
async fn get_user_json(uuid: String, _token: AdminToken, conn: DbConn) -> JsonResult {
let user = get_user_or_404(&uuid, &conn).await?;

Ok(Json(user.to_json(&conn).await))
const DT_FMT: &str = "%Y-%m-%d %H:%M:%S %Z";
let u = get_user_or_404(&uuid, &conn).await?;
let mut usr = u.to_json(&conn).await;
usr["UserEnabled"] = json!(u.enabled);
usr["CreatedAt"] = json!(format_naive_datetime_local(&u.created_at, DT_FMT));
Ok(Json(usr))
}

#[post("/users/<uuid>/delete")]
Expand Down

0 comments on commit ab87802

Please sign in to comment.