mirror of
https://github.com/modrinth/code.git
synced 2026-07-31 21:26:40 +00:00
Allow v2 version creation route to accept environment (#6454)
* Allow v2 version creation route to accept environment * fix
This commit is contained in:
@@ -184,6 +184,12 @@ pub async fn project_create(
|
|||||||
server_side,
|
server_side,
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
|
if let Some(environment) = v.environment {
|
||||||
|
fields.insert(
|
||||||
|
"environment".to_string(),
|
||||||
|
json!(environment),
|
||||||
|
);
|
||||||
|
}
|
||||||
fields.insert(
|
fields.insert(
|
||||||
"game_versions".to_string(),
|
"game_versions".to_string(),
|
||||||
json!(v.game_versions),
|
json!(v.game_versions),
|
||||||
|
|||||||
@@ -55,6 +55,7 @@ pub struct InitialVersionData {
|
|||||||
pub dependencies: Vec<Dependency>,
|
pub dependencies: Vec<Dependency>,
|
||||||
#[validate(length(min = 1))]
|
#[validate(length(min = 1))]
|
||||||
pub game_versions: Vec<String>,
|
pub game_versions: Vec<String>,
|
||||||
|
pub environment: Option<String>,
|
||||||
#[serde(alias = "version_type")]
|
#[serde(alias = "version_type")]
|
||||||
pub release_channel: VersionType,
|
pub release_channel: VersionType,
|
||||||
#[validate(length(min = 1))]
|
#[validate(length(min = 1))]
|
||||||
@@ -160,22 +161,26 @@ pub async fn version_create(
|
|||||||
.iter()
|
.iter()
|
||||||
.any(|field| field == "environment")
|
.any(|field| field == "environment")
|
||||||
{
|
{
|
||||||
// If so, we get the field of an example version of the project, and set the side types to match.
|
let environment =
|
||||||
fields.insert(
|
if let Some(environment) = legacy_create.environment {
|
||||||
"environment".into(),
|
json!(environment)
|
||||||
get_example_version_fields(
|
} else {
|
||||||
legacy_create.project_id,
|
// If so, we get the field of an example version of the project, and set the side types to match.
|
||||||
client,
|
get_example_version_fields(
|
||||||
&redis,
|
legacy_create.project_id,
|
||||||
)
|
client,
|
||||||
.await?
|
&redis,
|
||||||
.into_iter()
|
)
|
||||||
.flatten()
|
.await?
|
||||||
.find(|f| f.field_name == "environment")
|
.into_iter()
|
||||||
.map_or(json!("unknown"), |f| {
|
.flatten()
|
||||||
f.value.serialize_internal()
|
.find(|f| f.field_name == "environment")
|
||||||
}),
|
.map_or(json!("unknown"), |f| {
|
||||||
);
|
f.value.serialize_internal()
|
||||||
|
})
|
||||||
|
};
|
||||||
|
|
||||||
|
fields.insert("environment".into(), environment);
|
||||||
}
|
}
|
||||||
// Handle project type via file extension prediction
|
// Handle project type via file extension prediction
|
||||||
let mut project_type = None;
|
let mut project_type = None;
|
||||||
|
|||||||
@@ -4,9 +4,10 @@ use crate::common::api_v2::ApiV2;
|
|||||||
use actix_http::StatusCode;
|
use actix_http::StatusCode;
|
||||||
use actix_web::test;
|
use actix_web::test;
|
||||||
use futures::StreamExt;
|
use futures::StreamExt;
|
||||||
use labrinth::models::ids::VersionId;
|
|
||||||
use labrinth::{
|
use labrinth::{
|
||||||
|
models::ids::VersionId,
|
||||||
models::projects::{Loader, VersionStatus, VersionType},
|
models::projects::{Loader, VersionStatus, VersionType},
|
||||||
|
models::v2::projects::LegacySideType,
|
||||||
routes::v2::version_file::FileUpdateData,
|
routes::v2::version_file::FileUpdateData,
|
||||||
};
|
};
|
||||||
use serde_json::json;
|
use serde_json::json;
|
||||||
@@ -515,6 +516,84 @@ async fn add_version_project_types_v2() {
|
|||||||
.await;
|
.await;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[actix_rt::test]
|
||||||
|
async fn add_version_accepts_environment_v2() {
|
||||||
|
with_test_environment(
|
||||||
|
None,
|
||||||
|
|test_env: TestEnvironment<ApiV2>| async move {
|
||||||
|
let api = &test_env.api;
|
||||||
|
|
||||||
|
let (test_project, test_versions) = api
|
||||||
|
.add_public_project(
|
||||||
|
"test-version-environment",
|
||||||
|
None,
|
||||||
|
None,
|
||||||
|
USER_USER_PAT,
|
||||||
|
)
|
||||||
|
.await;
|
||||||
|
assert_eq!(test_versions.len(), 0);
|
||||||
|
|
||||||
|
let patch = json!([{
|
||||||
|
"op": "add",
|
||||||
|
"path": "/environment",
|
||||||
|
"value": "server_only_client_optional"
|
||||||
|
}]);
|
||||||
|
|
||||||
|
let resp = api
|
||||||
|
.add_public_version(
|
||||||
|
test_project.id,
|
||||||
|
"1.0.0",
|
||||||
|
TestFile::build_random_jar(),
|
||||||
|
None,
|
||||||
|
Some(serde_json::from_value(patch).unwrap()),
|
||||||
|
USER_USER_PAT,
|
||||||
|
)
|
||||||
|
.await;
|
||||||
|
assert_status!(&resp, StatusCode::OK);
|
||||||
|
|
||||||
|
let project = api
|
||||||
|
.get_project_deserialized(
|
||||||
|
&test_project.slug.unwrap(),
|
||||||
|
USER_USER_PAT,
|
||||||
|
)
|
||||||
|
.await;
|
||||||
|
assert_eq!(project.client_side, LegacySideType::Optional);
|
||||||
|
assert_eq!(project.server_side, LegacySideType::Required);
|
||||||
|
},
|
||||||
|
)
|
||||||
|
.await;
|
||||||
|
}
|
||||||
|
|
||||||
|
#[actix_rt::test]
|
||||||
|
async fn create_project_initial_version_accepts_environment_v2() {
|
||||||
|
with_test_environment(
|
||||||
|
None,
|
||||||
|
|test_env: TestEnvironment<ApiV2>| async move {
|
||||||
|
let api = &test_env.api;
|
||||||
|
let slug = "test-project-version-environment";
|
||||||
|
let patch = json!([{
|
||||||
|
"op": "add",
|
||||||
|
"path": "/initial_versions/0/environment",
|
||||||
|
"value": "client_only_server_optional"
|
||||||
|
}]);
|
||||||
|
let creation_data = get_public_project_creation_data(
|
||||||
|
slug,
|
||||||
|
Some(TestFile::build_random_jar()),
|
||||||
|
Some(serde_json::from_value(patch).unwrap()),
|
||||||
|
);
|
||||||
|
|
||||||
|
let resp = api.create_project(creation_data, USER_USER_PAT).await;
|
||||||
|
assert_status!(&resp, StatusCode::OK);
|
||||||
|
|
||||||
|
let project =
|
||||||
|
api.get_project_deserialized(slug, USER_USER_PAT).await;
|
||||||
|
assert_eq!(project.client_side, LegacySideType::Required);
|
||||||
|
assert_eq!(project.server_side, LegacySideType::Optional);
|
||||||
|
},
|
||||||
|
)
|
||||||
|
.await;
|
||||||
|
}
|
||||||
|
|
||||||
#[actix_rt::test]
|
#[actix_rt::test]
|
||||||
async fn test_incorrect_file_parts() {
|
async fn test_incorrect_file_parts() {
|
||||||
// Ensures that a version get that 'should' have mrpack_loaders does still display them
|
// Ensures that a version get that 'should' have mrpack_loaders does still display them
|
||||||
|
|||||||
Reference in New Issue
Block a user