Allow duplicate version numbers, fix version sorting, edit validators (#414)

This commit is contained in:
Geometrically 2022-08-06 17:44:16 -07:00 committed by GitHub
parent 411b8e3cb6
commit 33988ed3fb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 9 additions and 72 deletions

View File

@ -2991,27 +2991,6 @@
},
"query": "\n SELECT id FROM mods_gallery\n WHERE image_url = $1\n "
},
"7cae1137ab3aaa8de1617d820fb5635eb7498e61174e79da3cdd0da7e99aaca3": {
"describe": {
"columns": [
{
"name": "exists",
"ordinal": 0,
"type_info": "Bool"
}
],
"nullable": [
null
],
"parameters": {
"Left": [
"Text",
"Int8"
]
}
},
"query": "SELECT EXISTS(SELECT 1 FROM versions WHERE (version_number = $1) AND (mod_id = $2))"
},
"7cb691738c28e0d1f28c84ba2dbcfa21a6dbd859bcf0f565f90cd7ce2ea5aa1c": {
"describe": {
"columns": [],

View File

@ -128,7 +128,7 @@ impl ids::ProjectTypeId {
}
pub fn convert_postgres_date(input: &str) -> DateTime<Utc> {
DateTime::parse_from_rfc3339(&*format!("{}:00Z", input.replace(' ', "T")))
DateTime::parse_from_str(input, "%Y-%m-%d %T%#z")
.map(|x| x.with_timezone(&Utc))
.unwrap_or_else(|_| Utc::now())
}

View File

@ -18,7 +18,6 @@ use chrono::Utc;
use futures::stream::StreamExt;
use serde::{Deserialize, Serialize};
use sqlx::postgres::PgPool;
use std::collections::HashSet;
use std::sync::Arc;
use thiserror::Error;
use validator::Validate;
@ -362,12 +361,6 @@ pub async fn project_create_inner(
CreateError::InvalidInput(validation_errors_to_string(err, None))
})?;
let mut uniq = HashSet::new();
create_data
.initial_versions
.iter()
.all(|x| uniq.insert(x.version_number.clone()));
let slug_project_id_option: Option<ProjectId> =
serde_json::from_str(&*format!("\"{}\"", create_data.slug)).ok();

View File

@ -169,23 +169,6 @@ async fn version_create_inner(
));
}
// Check whether there is already a version of this project with the
// same version number
let results = sqlx::query!(
"SELECT EXISTS(SELECT 1 FROM versions WHERE (version_number = $1) AND (mod_id = $2))",
version_create_data.version_number,
project_id as models::ProjectId,
)
.fetch_one(&mut *transaction)
.await?;
if results.exists.unwrap_or(true) {
return Err(CreateError::InvalidInput(
"A version with that version_number already exists"
.to_string(),
));
}
// Check that the user creating this version is a team member
// of the project the version is being added to.
let team_member = models::TeamMember::get_from_user_id_project(
@ -367,10 +350,9 @@ async fn version_create_inner(
)
.fetch_many(&mut *transaction)
.try_filter_map(|e| async {
Ok(e.right()
.map(|m| crate::database::models::ids::UserId(m.follower_id)))
Ok(e.right().map(|m| models::ids::UserId(m.follower_id)))
})
.try_collect::<Vec<crate::database::models::ids::UserId>>()
.try_collect::<Vec<models::ids::UserId>>()
.await?;
let project_id: ProjectId = builder.project_id.into();

View File

@ -253,23 +253,6 @@ pub async fn version_edit(
}
if let Some(number) = &new_version.version_number {
let results = sqlx::query!(
"SELECT EXISTS(SELECT 1 FROM versions WHERE (version_number = $1) AND (mod_id = $2))",
number,
version_item.project_id as database::models::ids::ProjectId,
)
.fetch_one(&mut *transaction)
.await?;
if results.exists.unwrap_or(true)
&& &version_item.version_number != number
{
return Err(ApiError::InvalidInput(
"A version with that version_number already exists"
.to_string(),
));
}
sqlx::query!(
"
UPDATE versions

View File

@ -93,11 +93,11 @@ impl super::Validator for VelocityValidator {
&self,
archive: &mut ZipArchive<Cursor<bytes::Bytes>>,
) -> Result<ValidationResult, ValidationError> {
archive.by_name("velocity-plugin.json").map_err(|_| {
ValidationError::InvalidInput(
"No velocity-plugin.json present for plugin file.".into(),
)
})?;
if archive.by_name("velocity-plugin.json").is_err() {
return Ok(ValidationResult::Warning(
"No velocity-plugin.json present for plugin file.",
));
}
Ok(ValidationResult::Pass)
}

View File

@ -34,7 +34,7 @@ impl super::Validator for PackValidator {
) -> Result<ValidationResult, ValidationError> {
archive.by_name("pack.mcmeta").map_err(|_| {
ValidationError::InvalidInput(
"No pack.mcmeta present for pack file.".into(),
"No pack.mcmeta present for pack file. Tip: Make sure pack.mcmeta is in the root directory of your pack!".into(),
)
})?;