From 0310418837a59f9f599869cea52228bdee712ba7 Mon Sep 17 00:00:00 2001 From: trisua Date: Sun, 15 Jun 2025 11:58:07 -0400 Subject: [PATCH] add: stack block limits --- .../app/src/public/html/profile/settings.lisp | 4 +++- crates/core/src/database/stackblocks.rs | 22 +++++++++++++++++++ 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/crates/app/src/public/html/profile/settings.lisp b/crates/app/src/public/html/profile/settings.lisp index d317d95..33f6117 100644 --- a/crates/app/src/public/html/profile/settings.lisp +++ b/crates/app/src/public/html/profile/settings.lisp @@ -579,7 +579,9 @@ (li (text "Ability to create forges")) (li - (text "Ability to create more than 1 app"))) + (text "Ability to create more than 1 app")) + (li + (text "Create up to 10 stack blocks"))) (a ("href" "{{ config.stripe.payment_link }}?client_reference_id={{ user.id }}") ("class" "button") diff --git a/crates/core/src/database/stackblocks.rs b/crates/core/src/database/stackblocks.rs index 0ae9e82..8d2d633 100644 --- a/crates/core/src/database/stackblocks.rs +++ b/crates/core/src/database/stackblocks.rs @@ -112,12 +112,34 @@ impl DataManager { Ok(res.unwrap()) } + const MAXIMUM_FREE_STACKBLOCKS: usize = 5; + const MAXIMUM_SUPPORTER_STACKBLOCKS: usize = 10; + /// Create a new stack block in the database. /// /// # Arguments /// * `data` - a mock [`StackBlock`] object to insert pub async fn create_stackblock(&self, data: StackBlock) -> Result<()> { let initiator = self.get_user_by_id(data.initiator).await?; + + // check number of stackblocks + let stackblocks = self.get_stackblocks_by_initiator(data.initiator).await; + + if !initiator.permissions.check(FinePermission::SUPPORTER) { + if stackblocks.len() >= Self::MAXIMUM_FREE_STACKBLOCKS { + return Err(Error::MiscError( + "You already have the maximum number of stack blocks you can have".to_string(), + )); + } + } else { + if stackblocks.len() >= Self::MAXIMUM_SUPPORTER_STACKBLOCKS { + return Err(Error::MiscError( + "You already have the maximum number of stack blocks you can have".to_string(), + )); + } + } + + // ... let stack = self.get_stack_by_id(data.stack).await?; if initiator.id != stack.owner