collab: Clean up LLM token creation (#26955)
This PR cleans up the LLM token creation a bit. We now pass in the entire list of feature flags to the `LlmTokenClaims::create` method to prevent having a bunch of confusable `bool` parameters. Release Notes: - N/A
This commit is contained in:
parent
2b2b9c1624
commit
1397e01735
3 changed files with 26 additions and 14 deletions
|
@ -4047,8 +4047,8 @@ async fn get_llm_api_token(
|
|||
|
||||
let flags = db.get_user_flags(session.user_id()).await?;
|
||||
let has_language_models_feature_flag = flags.iter().any(|flag| flag == "language-models");
|
||||
let has_llm_closed_beta_feature_flag = flags.iter().any(|flag| flag == "llm-closed-beta");
|
||||
let has_predict_edits_feature_flag = flags.iter().any(|flag| flag == "predict-edits");
|
||||
let has_bypass_account_age_check_feature_flag =
|
||||
flags.iter().any(|flag| flag == "bypass-account-age-check");
|
||||
|
||||
if !session.is_staff() && !has_language_models_feature_flag {
|
||||
Err(anyhow!("permission denied"))?
|
||||
|
@ -4067,13 +4067,9 @@ async fn get_llm_api_token(
|
|||
let has_llm_subscription = session.has_llm_subscription(&db).await?;
|
||||
|
||||
let bypass_account_age_check =
|
||||
has_llm_subscription || flags.iter().any(|flag| flag == "bypass-account-age-check");
|
||||
has_llm_subscription || has_bypass_account_age_check_feature_flag;
|
||||
if !bypass_account_age_check {
|
||||
let mut account_created_at = user.created_at;
|
||||
if let Some(github_created_at) = user.github_user_created_at {
|
||||
account_created_at = account_created_at.min(github_created_at);
|
||||
}
|
||||
if Utc::now().naive_utc() - account_created_at < MIN_ACCOUNT_AGE_FOR_LLM_USE {
|
||||
if Utc::now().naive_utc() - user.account_created_at() < MIN_ACCOUNT_AGE_FOR_LLM_USE {
|
||||
Err(anyhow!("account too young"))?
|
||||
}
|
||||
}
|
||||
|
@ -4084,8 +4080,7 @@ async fn get_llm_api_token(
|
|||
&user,
|
||||
session.is_staff(),
|
||||
billing_preferences,
|
||||
has_llm_closed_beta_feature_flag,
|
||||
has_predict_edits_feature_flag,
|
||||
&flags,
|
||||
has_llm_subscription,
|
||||
session.current_plan(&db).await?,
|
||||
session.system_id.clone(),
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue