Hard caps on creating projects/orgs/collections (#4430)

* implement backend limits on project creation

* implement collection, org creation hard caps

* Fix limit api

* Fix clippy

* Fix limits

* Update sqlx queries

* Address PR comments on user limit structure

* sqlx prepare and clippy

* fix test maybe
This commit is contained in:
aecsocket
2025-09-28 11:01:00 +01:00
committed by GitHub
parent 3f55711f9e
commit f466470d06
503 changed files with 14260 additions and 11 deletions

View File

@@ -0,0 +1,46 @@
use actix_http::StatusCode;
use actix_web::test;
use labrinth::models::v3::user_limits::UserLimits;
use crate::{
assert_status,
common::{
api_common::{Api, AppendsOptionalPat},
api_v3::ApiV3,
},
};
impl ApiV3 {
pub async fn get_project_limits(&self, pat: Option<&str>) -> UserLimits {
let req = test::TestRequest::get()
.uri("/v3/limits/projects")
.append_pat(pat)
.to_request();
let resp = self.call(req).await;
assert_status!(&resp, StatusCode::OK);
test::read_body_json(resp).await
}
pub async fn get_organization_limits(
&self,
pat: Option<&str>,
) -> UserLimits {
let req = test::TestRequest::get()
.uri("/v3/limits/organizations")
.append_pat(pat)
.to_request();
let resp = self.call(req).await;
assert_status!(&resp, StatusCode::OK);
test::read_body_json(resp).await
}
pub async fn get_collection_limits(&self, pat: Option<&str>) -> UserLimits {
let req = test::TestRequest::get()
.uri("/v3/limits/collections")
.append_pat(pat)
.to_request();
let resp = self.call(req).await;
assert_status!(&resp, StatusCode::OK);
test::read_body_json(resp).await
}
}

View File

@@ -8,6 +8,7 @@ use labrinth::LabrinthConfig;
use std::rc::Rc;
pub mod collections;
pub mod limits;
pub mod oauth;
pub mod oauth_clients;
pub mod organization;

View File

@@ -0,0 +1,32 @@
use common::api_v3::ApiV3;
use common::database::USER_USER_PAT;
use common::environment::{TestEnvironment, with_test_environment};
use crate::common::api_common::ApiProject;
pub mod common;
#[actix_rt::test]
pub async fn limits() {
with_test_environment(
None,
|test_env: TestEnvironment<ApiV3>| async move {
let api = &test_env.api;
let project_limits = api.get_project_limits(USER_USER_PAT).await;
assert_eq!(project_limits.current, 2);
assert!(project_limits.max < u64::MAX);
api.add_public_project(
"limit-test-project",
None,
None,
USER_USER_PAT,
)
.await;
let project_limits = api.get_project_limits(USER_USER_PAT).await;
assert_eq!(project_limits.current, 3);
},
)
.await;
}