collab: Return current plan based on subscription status (#29341)

This PR makes collab return the current plan based on subscription
status instead of based on the staff bit.

Release Notes:

- N/A
This commit is contained in:
Marshall Bowers 2025-04-24 09:04:25 -04:00 committed by GitHub
parent fcfeea4825
commit 92f21ee39d
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -1,6 +1,7 @@
mod connection_pool; mod connection_pool;
use crate::api::{CloudflareIpCountryHeader, SystemIdHeader}; use crate::api::{CloudflareIpCountryHeader, SystemIdHeader};
use crate::db::billing_subscription::SubscriptionKind;
use crate::llm::LlmTokenClaims; use crate::llm::LlmTokenClaims;
use crate::{ use crate::{
AppState, Error, Result, auth, AppState, Error, Result, auth,
@ -178,15 +179,23 @@ impl Session {
Ok(db.has_active_billing_subscription(user_id).await?) Ok(db.has_active_billing_subscription(user_id).await?)
} }
pub async fn current_plan( pub async fn current_plan(&self, db: &MutexGuard<'_, DbHandle>) -> anyhow::Result<proto::Plan> {
&self, let user_id = self.user_id();
_db: &MutexGuard<'_, DbHandle>,
) -> anyhow::Result<proto::Plan> { let subscription = db.get_active_billing_subscription(user_id).await?;
if self.is_staff() { let subscription_kind = subscription.and_then(|subscription| subscription.kind);
Ok(proto::Plan::ZedPro)
} else { let plan = if let Some(subscription_kind) = subscription_kind {
Ok(proto::Plan::Free) match subscription_kind {
SubscriptionKind::ZedPro => proto::Plan::ZedPro,
SubscriptionKind::ZedProTrial => proto::Plan::ZedProTrial,
SubscriptionKind::ZedFree => proto::Plan::Free,
} }
} else {
proto::Plan::Free
};
Ok(plan)
} }
fn user_id(&self) -> UserId { fn user_id(&self) -> UserId {