Staff support dashboard routes (#3160)

* Staff support dashboard routes

* Fix clippy
This commit is contained in:
Jai Agrawal
2025-01-17 16:41:49 -08:00
committed by GitHub
parent d7814e115d
commit 75b357a069
9 changed files with 371 additions and 36 deletions

View File

@@ -86,8 +86,6 @@ pub enum CreateError {
CustomAuthenticationError(String),
#[error("Image Parsing Error: {0}")]
ImageError(#[from] ImageError),
#[error("Reroute Error: {0}")]
RerouteError(#[from] reqwest::Error),
}
impl actix_web::ResponseError for CreateError {
@@ -119,7 +117,6 @@ impl actix_web::ResponseError for CreateError {
CreateError::ValidationError(..) => StatusCode::BAD_REQUEST,
CreateError::FileValidationError(..) => StatusCode::BAD_REQUEST,
CreateError::ImageError(..) => StatusCode::BAD_REQUEST,
CreateError::RerouteError(..) => StatusCode::INTERNAL_SERVER_ERROR,
}
}
@@ -146,7 +143,6 @@ impl actix_web::ResponseError for CreateError {
CreateError::ValidationError(..) => "invalid_input",
CreateError::FileValidationError(..) => "invalid_input",
CreateError::ImageError(..) => "invalid_image",
CreateError::RerouteError(..) => "reroute_error",
},
description: self.to_string(),
})

View File

@@ -128,14 +128,33 @@ pub async fn users_get(
}
pub async fn user_get(
req: HttpRequest,
info: web::Path<(String,)>,
pool: web::Data<PgPool>,
redis: web::Data<RedisPool>,
session_queue: web::Data<AuthQueue>,
) -> Result<HttpResponse, ApiError> {
let user_data = User::get(&info.into_inner().0, &**pool, &redis).await?;
if let Some(data) = user_data {
let response: crate::models::users::User = data.into();
let auth_user = get_user_from_headers(
&req,
&**pool,
&redis,
&session_queue,
Some(&[Scopes::SESSION_ACCESS]),
)
.await
.map(|x| x.1)
.ok();
let response: crate::models::users::User =
if auth_user.map(|x| x.role.is_admin()).unwrap_or(false) {
crate::models::users::User::from_full(data)
} else {
data.into()
};
Ok(HttpResponse::Ok().json(response))
} else {
Err(ApiError::NotFound)

View File

@@ -985,7 +985,7 @@ pub async fn upload_file(
let client = reqwest::Client::new();
let delphi_url = dotenvy::var("DELPHI_URL")?;
let res = client
match client
.post(delphi_url)
.json(&serde_json::json!({
"url": url,
@@ -993,10 +993,16 @@ pub async fn upload_file(
"version_id": version_id,
}))
.send()
.await?;
if !res.status().is_success() {
error!("Failed to upload file to Delphi: {url}");
.await
{
Ok(res) => {
if !res.status().is_success() {
error!("Failed to upload file to Delphi: {url}");
}
}
Err(e) => {
error!("Failed to upload file to Delphi: {url}: {e}");
}
}
version_files.push(VersionFileBuilder {