You've already forked AstralRinth
forked from didirus/AstralRinth
Fix auth params, Add params to indexing, Order version game versions, Remove version moderation, Return donation platforms in get routes
This commit is contained in:
@@ -113,7 +113,7 @@ pub async fn init(
|
||||
"https://github.com/login/oauth/authorize?client_id={}&state={}&scope={}",
|
||||
client_id,
|
||||
to_base62(state.0 as u64),
|
||||
"read%3Auser%20user%3Aemail"
|
||||
"read%3Auser"
|
||||
);
|
||||
|
||||
Ok(HttpResponse::TemporaryRedirect()
|
||||
|
||||
@@ -81,11 +81,7 @@ pub fn teams_config(cfg: &mut web::ServiceConfig) {
|
||||
}
|
||||
|
||||
pub fn moderation_config(cfg: &mut web::ServiceConfig) {
|
||||
cfg.service(
|
||||
web::scope("moderation")
|
||||
.service(moderation::mods)
|
||||
.service(moderation::versions),
|
||||
);
|
||||
cfg.service(web::scope("moderation").service(moderation::mods));
|
||||
}
|
||||
|
||||
#[derive(thiserror::Error, Debug)]
|
||||
|
||||
@@ -493,6 +493,8 @@ async fn mod_create_inner(
|
||||
donation_urls.push(models::mod_item::DonationUrl {
|
||||
mod_id: mod_id.into(),
|
||||
platform_id,
|
||||
platform_short: "".to_string(),
|
||||
platform_name: "".to_string(),
|
||||
url: url.url.clone(),
|
||||
})
|
||||
}
|
||||
|
||||
@@ -1,8 +1,7 @@
|
||||
use super::ApiError;
|
||||
use crate::auth::check_is_moderator_from_headers;
|
||||
use crate::database;
|
||||
use crate::models;
|
||||
use crate::models::mods::{ModId, ModStatus, VersionType};
|
||||
use crate::models::mods::{ModId, ModStatus};
|
||||
use crate::models::teams::TeamId;
|
||||
use actix_web::{get, web, HttpRequest, HttpResponse};
|
||||
use serde::{Deserialize, Serialize};
|
||||
@@ -103,50 +102,3 @@ pub async fn mods(
|
||||
|
||||
Ok(HttpResponse::Ok().json(mods))
|
||||
}
|
||||
|
||||
/// Returns a list of versions that need to be approved
|
||||
#[get("versions")]
|
||||
pub async fn versions(
|
||||
req: HttpRequest,
|
||||
pool: web::Data<PgPool>,
|
||||
count: web::Query<ResultCount>,
|
||||
) -> Result<HttpResponse, ApiError> {
|
||||
check_is_moderator_from_headers(req.headers(), &**pool).await?;
|
||||
|
||||
use futures::stream::TryStreamExt;
|
||||
|
||||
let versions = sqlx::query!(
|
||||
"
|
||||
SELECT * FROM versions
|
||||
WHERE accepted = FALSE
|
||||
ORDER BY date_published ASC
|
||||
LIMIT $1;
|
||||
",
|
||||
count.count as i64
|
||||
)
|
||||
.fetch_many(&**pool)
|
||||
.try_filter_map(|e| async {
|
||||
Ok(e.right().map(|m| models::mods::Version {
|
||||
id: database::models::ids::VersionId(m.id).into(),
|
||||
mod_id: database::models::ids::ModId(m.mod_id).into(),
|
||||
author_id: database::models::ids::UserId(m.author_id).into(),
|
||||
featured: m.featured,
|
||||
name: m.name,
|
||||
version_number: m.version_number,
|
||||
changelog: m.changelog,
|
||||
changelog_url: m.changelog_url,
|
||||
date_published: m.date_published,
|
||||
downloads: m.downloads as u32,
|
||||
version_type: VersionType::Release,
|
||||
files: vec![],
|
||||
dependencies: vec![],
|
||||
game_versions: vec![],
|
||||
loaders: vec![],
|
||||
}))
|
||||
})
|
||||
.try_collect::<Vec<models::mods::Version>>()
|
||||
.await
|
||||
.map_err(|e| ApiError::DatabaseError(e.into()))?;
|
||||
|
||||
Ok(HttpResponse::Ok().json(versions))
|
||||
}
|
||||
|
||||
@@ -223,7 +223,16 @@ fn convert_mod(data: database::models::mod_item::QueryMod) -> models::mods::Mod
|
||||
source_url: m.source_url,
|
||||
wiki_url: m.wiki_url,
|
||||
discord_url: m.discord_url,
|
||||
donation_urls: None,
|
||||
donation_urls: Some(
|
||||
data.donation_urls
|
||||
.into_iter()
|
||||
.map(|d| DonationLink {
|
||||
id: d.platform_short,
|
||||
platform: d.platform_name,
|
||||
url: d.url,
|
||||
})
|
||||
.collect(),
|
||||
),
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -49,8 +49,7 @@ pub fn check_version(version: &InitialVersionData) -> Result<(), CreateError> {
|
||||
version
|
||||
.file_parts
|
||||
.iter()
|
||||
.map(|f| check_length(1..=256, "file part name", f))
|
||||
.collect::<Result<_, _>>()?;
|
||||
.try_for_each(|f| check_length(1..=256, "file part name", f))?;
|
||||
|
||||
check_length(1..=64, "version number", &version.version_number)?;
|
||||
check_length(3..=256, "version title", &version.version_title)?;
|
||||
@@ -61,13 +60,11 @@ pub fn check_version(version: &InitialVersionData) -> Result<(), CreateError> {
|
||||
version
|
||||
.game_versions
|
||||
.iter()
|
||||
.map(|v| check_length(1..=256, "game version", &v.0))
|
||||
.collect::<Result<_, _>>()?;
|
||||
.try_for_each(|v| check_length(1..=256, "game version", &v.0))?;
|
||||
version
|
||||
.loaders
|
||||
.iter()
|
||||
.map(|l| check_length(1..=256, "loader name", &l.0))
|
||||
.collect::<Result<_, _>>()?;
|
||||
.try_for_each(|l| check_length(1..=256, "loader name", &l.0))?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
@@ -54,7 +54,6 @@ pub struct VersionIds {
|
||||
|
||||
#[get("versions")]
|
||||
pub async fn versions_get(
|
||||
req: HttpRequest,
|
||||
web::Query(ids): web::Query<VersionIds>,
|
||||
pool: web::Data<PgPool>,
|
||||
) -> Result<HttpResponse, ApiError> {
|
||||
@@ -66,39 +65,11 @@ pub async fn versions_get(
|
||||
.await
|
||||
.map_err(|e| ApiError::DatabaseError(e.into()))?;
|
||||
|
||||
let user_option = get_user_from_headers(req.headers(), &**pool).await.ok();
|
||||
|
||||
let mut versions = Vec::new();
|
||||
|
||||
for version_data in versions_data {
|
||||
if let Some(version) = version_data {
|
||||
let mut authorized = version.accepted;
|
||||
|
||||
if let Some(user) = &user_option {
|
||||
if !authorized {
|
||||
if user.role.is_mod() {
|
||||
authorized = true;
|
||||
} else {
|
||||
let user_id: database::models::ids::UserId = user.id.into();
|
||||
|
||||
let member_exists = sqlx::query!(
|
||||
"SELECT EXISTS(SELECT 1 FROM team_members tm INNER JOIN mods m ON m.team_id = tm.team_id AND m.id = $1 WHERE tm.user_id = $2)",
|
||||
version.mod_id as database::models::ModId,
|
||||
user_id as database::models::ids::UserId,
|
||||
)
|
||||
.fetch_one(&**pool)
|
||||
.await
|
||||
.map_err(|e| ApiError::DatabaseError(e.into()))?
|
||||
.exists;
|
||||
|
||||
authorized = member_exists.unwrap_or(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if authorized {
|
||||
versions.push(convert_version(version));
|
||||
}
|
||||
versions.push(convert_version(version));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -107,7 +78,6 @@ pub async fn versions_get(
|
||||
|
||||
#[get("{version_id}")]
|
||||
pub async fn version_get(
|
||||
req: HttpRequest,
|
||||
info: web::Path<(models::ids::VersionId,)>,
|
||||
pool: web::Data<PgPool>,
|
||||
) -> Result<HttpResponse, ApiError> {
|
||||
@@ -115,33 +85,8 @@ pub async fn version_get(
|
||||
let version_data = database::models::Version::get_full(id.into(), &**pool)
|
||||
.await
|
||||
.map_err(|e| ApiError::DatabaseError(e.into()))?;
|
||||
let user_option = get_user_from_headers(req.headers(), &**pool).await.ok();
|
||||
|
||||
if let Some(data) = version_data {
|
||||
if !data.accepted {
|
||||
if let Some(user) = user_option {
|
||||
if !user.role.is_mod() {
|
||||
let user_id: database::models::ids::UserId = user.id.into();
|
||||
|
||||
let member_exists = sqlx::query!(
|
||||
"SELECT EXISTS(SELECT 1 FROM team_members tm INNER JOIN mods m ON m.team_id = tm.team_id AND m.id = $1 WHERE tm.user_id = $2)",
|
||||
data.mod_id as database::models::ModId,
|
||||
user_id as database::models::ids::UserId,
|
||||
)
|
||||
.fetch_one(&**pool)
|
||||
.await
|
||||
.map_err(|e| ApiError::DatabaseError(e.into()))?
|
||||
.exists;
|
||||
|
||||
if !member_exists.unwrap_or(false) {
|
||||
return Ok(HttpResponse::NotFound().body(""));
|
||||
}
|
||||
}
|
||||
} else {
|
||||
return Ok(HttpResponse::NotFound().body(""));
|
||||
}
|
||||
}
|
||||
|
||||
Ok(HttpResponse::Ok().json(convert_version(data)))
|
||||
} else {
|
||||
Ok(HttpResponse::NotFound().body(""))
|
||||
@@ -212,7 +157,6 @@ pub struct EditVersion {
|
||||
pub dependencies: Option<Vec<models::ids::VersionId>>,
|
||||
pub game_versions: Option<Vec<models::mods::GameVersion>>,
|
||||
pub loaders: Option<Vec<models::mods::ModLoader>>,
|
||||
pub accepted: Option<bool>,
|
||||
pub featured: Option<bool>,
|
||||
pub primary_file: Option<(String, String)>,
|
||||
}
|
||||
@@ -262,28 +206,6 @@ pub async fn version_edit(
|
||||
.await
|
||||
.map_err(|e| ApiError::DatabaseError(e.into()))?;
|
||||
|
||||
if let Some(accepted) = &new_version.accepted {
|
||||
if !user.role.is_mod() {
|
||||
return Err(ApiError::CustomAuthenticationError(
|
||||
"You do not have the permissions to edit the approval of this version!"
|
||||
.to_string(),
|
||||
));
|
||||
}
|
||||
|
||||
sqlx::query!(
|
||||
"
|
||||
UPDATE versions
|
||||
SET accepted = $1
|
||||
WHERE (id = $2)
|
||||
",
|
||||
accepted,
|
||||
id as database::models::ids::VersionId,
|
||||
)
|
||||
.execute(&mut *transaction)
|
||||
.await
|
||||
.map_err(|e| ApiError::DatabaseError(e.into()))?;
|
||||
}
|
||||
|
||||
if let Some(name) = &new_version.name {
|
||||
sqlx::query!(
|
||||
"
|
||||
|
||||
Reference in New Issue
Block a user