forked from didirus/AstralRinth
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:
@@ -8,6 +8,7 @@ use crate::file_hosting::{FileHost, FileHostPublicity};
|
||||
use crate::models::collections::{Collection, CollectionStatus};
|
||||
use crate::models::ids::{CollectionId, ProjectId};
|
||||
use crate::models::pats::Scopes;
|
||||
use crate::models::v3::user_limits::UserLimits;
|
||||
use crate::queue::session::AuthQueue;
|
||||
use crate::routes::ApiError;
|
||||
use crate::routes::v3::project_creation::CreateError;
|
||||
@@ -76,6 +77,12 @@ pub async fn collection_create(
|
||||
.await?
|
||||
.1;
|
||||
|
||||
let limits =
|
||||
UserLimits::get_for_collections(¤t_user, &client).await?;
|
||||
if limits.current >= limits.max {
|
||||
return Err(CreateError::LimitReached);
|
||||
}
|
||||
|
||||
collection_create_data.validate().map_err(|err| {
|
||||
CreateError::InvalidInput(validation_errors_to_string(err, None))
|
||||
})?;
|
||||
|
||||
Reference in New Issue
Block a user