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:
parent
fcfeea4825
commit
92f21ee39d
1 changed files with 17 additions and 8 deletions
|
@ -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 {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue