add: stack block limits

This commit is contained in:
trisua 2025-06-15 11:58:07 -04:00
parent b71ae1f5a4
commit 0310418837
2 changed files with 25 additions and 1 deletions

View file

@ -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")

View file

@ -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