diff --git a/apps/labrinth/src/routes/v2/project_creation.rs b/apps/labrinth/src/routes/v2/project_creation.rs index 1c685a0779f..70f39dfeb5d 100644 --- a/apps/labrinth/src/routes/v2/project_creation.rs +++ b/apps/labrinth/src/routes/v2/project_creation.rs @@ -112,7 +112,7 @@ struct ProjectCreateData { #[validate(nested)] pub donation_urls: Option>, - /// An optional boolean. If true, the project will be created as a draft. + /// Projects are always created as drafts; explicitly setting false is rejected. pub is_draft: Option, /// The license id that the project follows diff --git a/apps/labrinth/src/routes/v3/project_creation.rs b/apps/labrinth/src/routes/v3/project_creation.rs index a604f3f6902..6a09e132d03 100644 --- a/apps/labrinth/src/routes/v3/project_creation.rs +++ b/apps/labrinth/src/routes/v3/project_creation.rs @@ -248,7 +248,7 @@ pub struct ProjectCreateData { #[serde(default)] pub link_urls: HashMap, - /// An optional boolean. If true, the project will be created as a draft. + /// Projects are always created as drafts; explicitly setting false is rejected. pub is_draft: Option, /// The license id that the project follows @@ -560,6 +560,12 @@ async fn project_create_inner( } let create_data: ProjectCreateData = serde_json::from_slice(&data)?; + if create_data.is_draft == Some(false) { + return Err(CreateError::InvalidInput(String::from( + "projects must be created as drafts; `is_draft` cannot be false", + ))); + } + create_data.validate().map_err(|err| { CreateError::InvalidInput(validation_errors_to_string(err, None)) })?; @@ -914,17 +920,7 @@ async fn project_create_inner( let team_id = team.insert(&mut *transaction).await?; - let status; - if project_create_data.is_draft.unwrap_or(false) { - status = ProjectStatus::Draft; - } else { - status = ProjectStatus::Processing; - if project_create_data.initial_versions.is_empty() { - return Err(CreateError::InvalidInput(String::from( - "Project submitted for review with no initial versions", - ))); - } - } + let status = ProjectStatus::Draft; let license_id = spdx::Expression::parse( &project_create_data.license_id, diff --git a/apps/labrinth/src/test/api_v2/request_data.rs b/apps/labrinth/src/test/api_v2/request_data.rs index 4d98e9c572c..a75c31e2429 100644 --- a/apps/labrinth/src/test/api_v2/request_data.rs +++ b/apps/labrinth/src/test/api_v2/request_data.rs @@ -84,7 +84,6 @@ pub fn get_public_project_creation_data_json( json!([]) }; - let is_draft = version_jar.is_none(); json!( { "title": format!("Test Project {slug}"), @@ -95,7 +94,7 @@ pub fn get_public_project_creation_data_json( "client_side": "required", "server_side": "optional", "initial_versions": initial_versions, - "is_draft": is_draft, + "is_draft": true, "categories": [], "license_id": "MIT", } diff --git a/apps/labrinth/src/test/api_v3/request_data.rs b/apps/labrinth/src/test/api_v3/request_data.rs index 6865f50add1..4d6c28780d6 100644 --- a/apps/labrinth/src/test/api_v3/request_data.rs +++ b/apps/labrinth/src/test/api_v3/request_data.rs @@ -94,7 +94,6 @@ pub fn get_public_project_creation_data_json( json!([]) }; - let is_draft = version_jar.is_none(); json!( { "name": format!("Test Project {slug}"), @@ -102,7 +101,7 @@ pub fn get_public_project_creation_data_json( "summary": "A dummy project for testing with.", "description": "This project is approved and its versions are listed. It contains enough descriptive information to satisfy project review validation requirements and explain what the project provides to its users.", "initial_versions": initial_versions, - "is_draft": is_draft, + "is_draft": true, "categories": [], "license_id": "MIT", } diff --git a/apps/labrinth/src/test/dummy_data.rs b/apps/labrinth/src/test/dummy_data.rs index 880dfbe1fcb..01ab2a23ff6 100644 --- a/apps/labrinth/src/test/dummy_data.rs +++ b/apps/labrinth/src/test/dummy_data.rs @@ -7,7 +7,11 @@ use crate::models::{ projects::{Project, Version}, }; use crate::test::asserts::assert_status; -use crate::test::{api_common::Api, api_v3, database::USER_USER_PAT}; +use crate::test::{ + api_common::Api, + api_v3, + database::{ADMIN_USER_PAT, USER_USER_PAT}, +}; use actix_http::StatusCode; use actix_web::test::{self, TestRequest}; use serde_json::json; @@ -21,7 +25,7 @@ use super::{ use super::{database::USER_USER_ID, get_json_val_str}; -pub const DUMMY_DATA_UPDATE: i64 = 10; +pub const DUMMY_DATA_UPDATE: i64 = 11; pub const DUMMY_CATEGORIES: &[&str] = &[ "combat", @@ -430,7 +434,13 @@ pub async fn add_project_beta(api: &ApiV3) -> (Project, Version) { Some(jar), Some(modify_json), ); - api.create_project(creation_data, USER_USER_PAT).await; + let resp = api.create_project(creation_data, USER_USER_PAT).await; + assert_status!(&resp, StatusCode::OK); + + let resp = api + .edit_project("beta", json!({ "status": "processing" }), ADMIN_USER_PAT) + .await; + assert_status!(&resp, StatusCode::NO_CONTENT); get_project_beta(api).await }