Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion apps/labrinth/src/routes/v2/project_creation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ struct ProjectCreateData {
#[validate(nested)]
pub donation_urls: Option<Vec<DonationLink>>,

/// 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<bool>,

/// The license id that the project follows
Expand Down
20 changes: 8 additions & 12 deletions apps/labrinth/src/routes/v3/project_creation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@ pub struct ProjectCreateData {
#[serde(default)]
pub link_urls: HashMap<String, String>,

/// 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<bool>,

/// The license id that the project follows
Expand Down Expand Up @@ -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))
})?;
Expand Down Expand Up @@ -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,
Expand Down
3 changes: 1 addition & 2 deletions apps/labrinth/src/test/api_v2/request_data.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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}"),
Expand All @@ -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",
}
Expand Down
3 changes: 1 addition & 2 deletions apps/labrinth/src/test/api_v3/request_data.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,15 +94,14 @@ pub fn get_public_project_creation_data_json(
json!([])
};

let is_draft = version_jar.is_none();
json!(
{
"name": format!("Test Project {slug}"),
"slug": slug,
"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",
}
Expand Down
16 changes: 13 additions & 3 deletions apps/labrinth/src/test/dummy_data.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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",
Expand Down Expand Up @@ -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
}
Expand Down
Loading