collab: Restrict usage of the LLM service to accounts older than 30 days (#16133)
This PR restricts usage of the LLM service to accounts older than 30 days. We now store the GitHub user's `created_at` timestamp to check the GitHub account age. If this is not set—which it won't be for existing users—then we use the `created_at` timestamp in the Zed database. Release Notes: - N/A --------- Co-authored-by: Max <max@zed.dev>
This commit is contained in:
parent
f398ecc3fb
commit
98516b5527
12 changed files with 64 additions and 9 deletions
|
@ -65,6 +65,7 @@ impl Database {
|
|||
github_login: &str,
|
||||
github_user_id: Option<i32>,
|
||||
github_email: Option<&str>,
|
||||
github_user_created_at: Option<DateTimeUtc>,
|
||||
initial_channel_id: Option<ChannelId>,
|
||||
) -> Result<()> {
|
||||
self.transaction(|tx| async move {
|
||||
|
@ -73,6 +74,7 @@ impl Database {
|
|||
github_login,
|
||||
github_user_id,
|
||||
github_email,
|
||||
github_user_created_at.map(|time| time.naive_utc()),
|
||||
initial_channel_id,
|
||||
&tx,
|
||||
)
|
||||
|
|
|
@ -1,3 +1,5 @@
|
|||
use chrono::NaiveDateTime;
|
||||
|
||||
use super::*;
|
||||
|
||||
impl Database {
|
||||
|
@ -99,6 +101,7 @@ impl Database {
|
|||
github_login: &str,
|
||||
github_user_id: Option<i32>,
|
||||
github_email: Option<&str>,
|
||||
github_user_created_at: Option<DateTimeUtc>,
|
||||
initial_channel_id: Option<ChannelId>,
|
||||
) -> Result<User> {
|
||||
self.transaction(|tx| async move {
|
||||
|
@ -106,6 +109,7 @@ impl Database {
|
|||
github_login,
|
||||
github_user_id,
|
||||
github_email,
|
||||
github_user_created_at.map(|created_at| created_at.naive_utc()),
|
||||
initial_channel_id,
|
||||
&tx,
|
||||
)
|
||||
|
@ -119,6 +123,7 @@ impl Database {
|
|||
github_login: &str,
|
||||
github_user_id: Option<i32>,
|
||||
github_email: Option<&str>,
|
||||
github_user_created_at: Option<NaiveDateTime>,
|
||||
initial_channel_id: Option<ChannelId>,
|
||||
tx: &DatabaseTransaction,
|
||||
) -> Result<User> {
|
||||
|
@ -130,6 +135,10 @@ impl Database {
|
|||
{
|
||||
let mut user_by_github_user_id = user_by_github_user_id.into_active_model();
|
||||
user_by_github_user_id.github_login = ActiveValue::set(github_login.into());
|
||||
if github_user_created_at.is_some() {
|
||||
user_by_github_user_id.github_user_created_at =
|
||||
ActiveValue::set(github_user_created_at);
|
||||
}
|
||||
Ok(user_by_github_user_id.update(tx).await?)
|
||||
} else if let Some(user_by_github_login) = user::Entity::find()
|
||||
.filter(user::Column::GithubLogin.eq(github_login))
|
||||
|
@ -138,12 +147,17 @@ impl Database {
|
|||
{
|
||||
let mut user_by_github_login = user_by_github_login.into_active_model();
|
||||
user_by_github_login.github_user_id = ActiveValue::set(Some(github_user_id));
|
||||
if github_user_created_at.is_some() {
|
||||
user_by_github_login.github_user_created_at =
|
||||
ActiveValue::set(github_user_created_at);
|
||||
}
|
||||
Ok(user_by_github_login.update(tx).await?)
|
||||
} else {
|
||||
let user = user::Entity::insert(user::ActiveModel {
|
||||
email_address: ActiveValue::set(github_email.map(|email| email.into())),
|
||||
github_login: ActiveValue::set(github_login.into()),
|
||||
github_user_id: ActiveValue::set(Some(github_user_id)),
|
||||
github_user_created_at: ActiveValue::set(github_user_created_at),
|
||||
admin: ActiveValue::set(false),
|
||||
invite_count: ActiveValue::set(0),
|
||||
invite_code: ActiveValue::set(None),
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue