From bdeac79d48f0b92f2762023d502b1042e23d6818 Mon Sep 17 00:00:00 2001 From: Marshall Bowers Date: Mon, 9 Dec 2024 16:55:26 -0500 Subject: [PATCH] collab: Prevent `max_monthly_llm_usage_spending_in_cents` from being negative (#21768) This PR fixes an issue where the `max_monthly_llm_usage_spending_in_cents` preference could be set to a negative value. Release Notes: - N/A --- crates/collab/src/api/billing.rs | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/crates/collab/src/api/billing.rs b/crates/collab/src/api/billing.rs index 88201bb5cc5e4b990eb8059cadd81199b912de4f..f6c2d88105faed19e9709a42934a7cad657f4d1f 100644 --- a/crates/collab/src/api/billing.rs +++ b/crates/collab/src/api/billing.rs @@ -102,6 +102,9 @@ async fn update_billing_preferences( .await? .ok_or_else(|| anyhow!("user not found"))?; + let max_monthly_llm_usage_spending_in_cents = + body.max_monthly_llm_usage_spending_in_cents.max(0); + let billing_preferences = if let Some(_billing_preferences) = app.db.get_billing_preferences(user.id).await? { app.db @@ -109,7 +112,7 @@ async fn update_billing_preferences( user.id, &UpdateBillingPreferencesParams { max_monthly_llm_usage_spending_in_cents: ActiveValue::set( - body.max_monthly_llm_usage_spending_in_cents, + max_monthly_llm_usage_spending_in_cents, ), }, ) @@ -119,8 +122,7 @@ async fn update_billing_preferences( .create_billing_preferences( user.id, &crate::db::CreateBillingPreferencesParams { - max_monthly_llm_usage_spending_in_cents: body - .max_monthly_llm_usage_spending_in_cents, + max_monthly_llm_usage_spending_in_cents, }, ) .await?