You've already forked AstralRinth
forked from didirus/AstralRinth
Staff support dashboard routes (#3160)
* Staff support dashboard routes * Fix clippy
This commit is contained in:
@@ -757,12 +757,7 @@ impl VersionField {
|
||||
l.field_id.0,
|
||||
l.version_id.0,
|
||||
l.int_value,
|
||||
if let Some(enum_value) = l.enum_value.as_ref().map(|e| e.0)
|
||||
{
|
||||
enum_value
|
||||
} else {
|
||||
-1
|
||||
},
|
||||
l.enum_value.as_ref().map(|e| e.0).unwrap_or(-1),
|
||||
l.string_value.clone(),
|
||||
)
|
||||
})
|
||||
|
||||
@@ -83,12 +83,18 @@ pub async fn products(
|
||||
Ok(HttpResponse::Ok().json(products))
|
||||
}
|
||||
|
||||
#[derive(Deserialize)]
|
||||
struct SubscriptionsQuery {
|
||||
pub user_id: Option<crate::models::ids::UserId>,
|
||||
}
|
||||
|
||||
#[get("subscriptions")]
|
||||
pub async fn subscriptions(
|
||||
req: HttpRequest,
|
||||
pool: web::Data<PgPool>,
|
||||
redis: web::Data<RedisPool>,
|
||||
session_queue: web::Data<AuthQueue>,
|
||||
query: web::Query<SubscriptionsQuery>,
|
||||
) -> Result<HttpResponse, ApiError> {
|
||||
let user = get_user_from_headers(
|
||||
&req,
|
||||
@@ -102,7 +108,18 @@ pub async fn subscriptions(
|
||||
|
||||
let subscriptions =
|
||||
user_subscription_item::UserSubscriptionItem::get_all_user(
|
||||
user.id.into(),
|
||||
if let Some(user_id) = query.user_id {
|
||||
if user.role.is_admin() {
|
||||
user_id.into()
|
||||
} else {
|
||||
return Err(ApiError::InvalidInput(
|
||||
"You cannot see the subscriptions of other users!"
|
||||
.to_string(),
|
||||
));
|
||||
}
|
||||
} else {
|
||||
user.id.into()
|
||||
},
|
||||
&**pool,
|
||||
)
|
||||
.await?
|
||||
@@ -573,12 +590,18 @@ pub async fn user_customer(
|
||||
Ok(HttpResponse::Ok().json(customer))
|
||||
}
|
||||
|
||||
#[derive(Deserialize)]
|
||||
pub struct ChargesQuery {
|
||||
pub user_id: Option<crate::models::ids::UserId>,
|
||||
}
|
||||
|
||||
#[get("payments")]
|
||||
pub async fn charges(
|
||||
req: HttpRequest,
|
||||
pool: web::Data<PgPool>,
|
||||
redis: web::Data<RedisPool>,
|
||||
session_queue: web::Data<AuthQueue>,
|
||||
query: web::Query<ChargesQuery>,
|
||||
) -> Result<HttpResponse, ApiError> {
|
||||
let user = get_user_from_headers(
|
||||
&req,
|
||||
@@ -592,7 +615,18 @@ pub async fn charges(
|
||||
|
||||
let charges =
|
||||
crate::database::models::charge_item::ChargeItem::get_from_user(
|
||||
user.id.into(),
|
||||
if let Some(user_id) = query.user_id {
|
||||
if user.role.is_admin() {
|
||||
user_id.into()
|
||||
} else {
|
||||
return Err(ApiError::InvalidInput(
|
||||
"You cannot see the subscriptions of other users!"
|
||||
.to_string(),
|
||||
));
|
||||
}
|
||||
} else {
|
||||
user.id.into()
|
||||
},
|
||||
&**pool,
|
||||
)
|
||||
.await?;
|
||||
|
||||
@@ -85,11 +85,13 @@ pub async fn users_get(
|
||||
|
||||
#[get("{id}")]
|
||||
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 response = v3::users::user_get(info, pool, redis)
|
||||
let response = v3::users::user_get(req, info, pool, redis, session_queue)
|
||||
.await
|
||||
.or_else(v2_reroute::flatten_404_error)?;
|
||||
|
||||
|
||||
@@ -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(),
|
||||
})
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user