mirror of
https://github.com/zed-industries/zed.git
synced 2026-06-01 03:14:56 +07:00
collab: Remove unused user queries (#42400)
This PR removes queries on users that were no longer being used. Release Notes: - N/A
This commit is contained in:
parent
e488b6cd0b
commit
83e7c21b2c
4 changed files with 1 additions and 222 deletions
|
|
@ -66,40 +66,6 @@ impl Database {
|
||||||
.await
|
.await
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns all users flagged as staff.
|
|
||||||
pub async fn get_staff_users(&self) -> Result<Vec<user::Model>> {
|
|
||||||
self.transaction(|tx| async {
|
|
||||||
let tx = tx;
|
|
||||||
Ok(user::Entity::find()
|
|
||||||
.filter(user::Column::Admin.eq(true))
|
|
||||||
.all(&*tx)
|
|
||||||
.await?)
|
|
||||||
})
|
|
||||||
.await
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Returns a user by email address. There are no access checks here, so this should only be used internally.
|
|
||||||
pub async fn get_user_by_email(&self, email: &str) -> Result<Option<User>> {
|
|
||||||
self.transaction(|tx| async move {
|
|
||||||
Ok(user::Entity::find()
|
|
||||||
.filter(user::Column::EmailAddress.eq(email))
|
|
||||||
.one(&*tx)
|
|
||||||
.await?)
|
|
||||||
})
|
|
||||||
.await
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Returns a user by GitHub user ID. There are no access checks here, so this should only be used internally.
|
|
||||||
pub async fn get_user_by_github_user_id(&self, github_user_id: i32) -> Result<Option<User>> {
|
|
||||||
self.transaction(|tx| async move {
|
|
||||||
Ok(user::Entity::find()
|
|
||||||
.filter(user::Column::GithubUserId.eq(github_user_id))
|
|
||||||
.one(&*tx)
|
|
||||||
.await?)
|
|
||||||
})
|
|
||||||
.await
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Returns a user by GitHub login. There are no access checks here, so this should only be used internally.
|
/// Returns a user by GitHub login. There are no access checks here, so this should only be used internally.
|
||||||
pub async fn get_user_by_github_login(&self, github_login: &str) -> Result<Option<User>> {
|
pub async fn get_user_by_github_login(&self, github_login: &str) -> Result<Option<User>> {
|
||||||
self.transaction(|tx| async move {
|
self.transaction(|tx| async move {
|
||||||
|
|
@ -270,39 +236,6 @@ impl Database {
|
||||||
.await
|
.await
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Sets "accepted_tos_at" on the user to the given timestamp.
|
|
||||||
pub async fn set_user_accepted_tos_at(
|
|
||||||
&self,
|
|
||||||
id: UserId,
|
|
||||||
accepted_tos_at: Option<DateTime>,
|
|
||||||
) -> Result<()> {
|
|
||||||
self.transaction(|tx| async move {
|
|
||||||
user::Entity::update_many()
|
|
||||||
.filter(user::Column::Id.eq(id))
|
|
||||||
.set(user::ActiveModel {
|
|
||||||
accepted_tos_at: ActiveValue::set(accepted_tos_at),
|
|
||||||
..Default::default()
|
|
||||||
})
|
|
||||||
.exec(&*tx)
|
|
||||||
.await?;
|
|
||||||
Ok(())
|
|
||||||
})
|
|
||||||
.await
|
|
||||||
}
|
|
||||||
|
|
||||||
/// hard delete the user.
|
|
||||||
pub async fn destroy_user(&self, id: UserId) -> Result<()> {
|
|
||||||
self.transaction(|tx| async move {
|
|
||||||
access_token::Entity::delete_many()
|
|
||||||
.filter(access_token::Column::UserId.eq(id))
|
|
||||||
.exec(&*tx)
|
|
||||||
.await?;
|
|
||||||
user::Entity::delete_by_id(id).exec(&*tx).await?;
|
|
||||||
Ok(())
|
|
||||||
})
|
|
||||||
.await
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Find users where github_login ILIKE name_query.
|
/// Find users where github_login ILIKE name_query.
|
||||||
pub async fn fuzzy_search_users(&self, name_query: &str, limit: u32) -> Result<Vec<User>> {
|
pub async fn fuzzy_search_users(&self, name_query: &str, limit: u32) -> Result<Vec<User>> {
|
||||||
self.transaction(|tx| async {
|
self.transaction(|tx| async {
|
||||||
|
|
@ -341,14 +274,4 @@ impl Database {
|
||||||
result.push('%');
|
result.push('%');
|
||||||
result
|
result
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn get_users_missing_github_user_created_at(&self) -> Result<Vec<user::Model>> {
|
|
||||||
self.transaction(|tx| async move {
|
|
||||||
Ok(user::Entity::find()
|
|
||||||
.filter(user::Column::GithubUserCreatedAt.is_null())
|
|
||||||
.all(&*tx)
|
|
||||||
.await?)
|
|
||||||
})
|
|
||||||
.await
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,6 @@ mod db_tests;
|
||||||
#[cfg(target_os = "macos")]
|
#[cfg(target_os = "macos")]
|
||||||
mod embedding_tests;
|
mod embedding_tests;
|
||||||
mod extension_tests;
|
mod extension_tests;
|
||||||
mod user_tests;
|
|
||||||
|
|
||||||
use crate::migrations::run_database_migrations;
|
use crate::migrations::run_database_migrations;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,7 @@
|
||||||
use super::*;
|
use super::*;
|
||||||
use crate::test_both_dbs;
|
use crate::test_both_dbs;
|
||||||
use chrono::Utc;
|
use chrono::Utc;
|
||||||
use pretty_assertions::{assert_eq, assert_ne};
|
use pretty_assertions::assert_eq;
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
|
|
||||||
test_both_dbs!(
|
test_both_dbs!(
|
||||||
|
|
@ -457,53 +457,6 @@ async fn test_add_contacts(db: &Arc<Database>) {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
test_both_dbs!(
|
|
||||||
test_metrics_id,
|
|
||||||
test_metrics_id_postgres,
|
|
||||||
test_metrics_id_sqlite
|
|
||||||
);
|
|
||||||
|
|
||||||
async fn test_metrics_id(db: &Arc<Database>) {
|
|
||||||
let NewUserResult {
|
|
||||||
user_id: user1,
|
|
||||||
metrics_id: metrics_id1,
|
|
||||||
..
|
|
||||||
} = db
|
|
||||||
.create_user(
|
|
||||||
"person1@example.com",
|
|
||||||
None,
|
|
||||||
false,
|
|
||||||
NewUserParams {
|
|
||||||
github_login: "person1".into(),
|
|
||||||
github_user_id: 101,
|
|
||||||
},
|
|
||||||
)
|
|
||||||
.await
|
|
||||||
.unwrap();
|
|
||||||
let NewUserResult {
|
|
||||||
user_id: user2,
|
|
||||||
metrics_id: metrics_id2,
|
|
||||||
..
|
|
||||||
} = db
|
|
||||||
.create_user(
|
|
||||||
"person2@example.com",
|
|
||||||
None,
|
|
||||||
false,
|
|
||||||
NewUserParams {
|
|
||||||
github_login: "person2".into(),
|
|
||||||
github_user_id: 102,
|
|
||||||
},
|
|
||||||
)
|
|
||||||
.await
|
|
||||||
.unwrap();
|
|
||||||
|
|
||||||
assert_eq!(db.get_user_metrics_id(user1).await.unwrap(), metrics_id1);
|
|
||||||
assert_eq!(db.get_user_metrics_id(user2).await.unwrap(), metrics_id2);
|
|
||||||
assert_eq!(metrics_id1.len(), 36);
|
|
||||||
assert_eq!(metrics_id2.len(), 36);
|
|
||||||
assert_ne!(metrics_id1, metrics_id2);
|
|
||||||
}
|
|
||||||
|
|
||||||
test_both_dbs!(
|
test_both_dbs!(
|
||||||
test_project_count,
|
test_project_count,
|
||||||
test_project_count_postgres,
|
test_project_count_postgres,
|
||||||
|
|
|
||||||
|
|
@ -1,96 +0,0 @@
|
||||||
use chrono::Utc;
|
|
||||||
|
|
||||||
use crate::{
|
|
||||||
db::{Database, NewUserParams},
|
|
||||||
test_both_dbs,
|
|
||||||
};
|
|
||||||
use std::sync::Arc;
|
|
||||||
|
|
||||||
test_both_dbs!(
|
|
||||||
test_accepted_tos,
|
|
||||||
test_accepted_tos_postgres,
|
|
||||||
test_accepted_tos_sqlite
|
|
||||||
);
|
|
||||||
|
|
||||||
async fn test_accepted_tos(db: &Arc<Database>) {
|
|
||||||
let user_id = db
|
|
||||||
.create_user(
|
|
||||||
"user1@example.com",
|
|
||||||
None,
|
|
||||||
false,
|
|
||||||
NewUserParams {
|
|
||||||
github_login: "user1".to_string(),
|
|
||||||
github_user_id: 1,
|
|
||||||
},
|
|
||||||
)
|
|
||||||
.await
|
|
||||||
.unwrap()
|
|
||||||
.user_id;
|
|
||||||
|
|
||||||
let user = db.get_user_by_id(user_id).await.unwrap().unwrap();
|
|
||||||
assert!(user.accepted_tos_at.is_none());
|
|
||||||
|
|
||||||
let accepted_tos_at = Utc::now().naive_utc();
|
|
||||||
db.set_user_accepted_tos_at(user_id, Some(accepted_tos_at))
|
|
||||||
.await
|
|
||||||
.unwrap();
|
|
||||||
|
|
||||||
let user = db.get_user_by_id(user_id).await.unwrap().unwrap();
|
|
||||||
assert!(user.accepted_tos_at.is_some());
|
|
||||||
assert_eq!(user.accepted_tos_at, Some(accepted_tos_at));
|
|
||||||
|
|
||||||
db.set_user_accepted_tos_at(user_id, None).await.unwrap();
|
|
||||||
|
|
||||||
let user = db.get_user_by_id(user_id).await.unwrap().unwrap();
|
|
||||||
assert!(user.accepted_tos_at.is_none());
|
|
||||||
}
|
|
||||||
|
|
||||||
test_both_dbs!(
|
|
||||||
test_destroy_user_cascade_deletes_access_tokens,
|
|
||||||
test_destroy_user_cascade_deletes_access_tokens_postgres,
|
|
||||||
test_destroy_user_cascade_deletes_access_tokens_sqlite
|
|
||||||
);
|
|
||||||
|
|
||||||
async fn test_destroy_user_cascade_deletes_access_tokens(db: &Arc<Database>) {
|
|
||||||
let user_id = db
|
|
||||||
.create_user(
|
|
||||||
"user1@example.com",
|
|
||||||
Some("user1"),
|
|
||||||
false,
|
|
||||||
NewUserParams {
|
|
||||||
github_login: "user1".to_string(),
|
|
||||||
github_user_id: 12345,
|
|
||||||
},
|
|
||||||
)
|
|
||||||
.await
|
|
||||||
.unwrap()
|
|
||||||
.user_id;
|
|
||||||
|
|
||||||
let user = db.get_user_by_id(user_id).await.unwrap();
|
|
||||||
assert!(user.is_some());
|
|
||||||
|
|
||||||
let token_1_id = db
|
|
||||||
.create_access_token(user_id, None, "token-1", 10)
|
|
||||||
.await
|
|
||||||
.unwrap();
|
|
||||||
|
|
||||||
let token_2_id = db
|
|
||||||
.create_access_token(user_id, None, "token-2", 10)
|
|
||||||
.await
|
|
||||||
.unwrap();
|
|
||||||
|
|
||||||
let token_1 = db.get_access_token(token_1_id).await;
|
|
||||||
let token_2 = db.get_access_token(token_2_id).await;
|
|
||||||
assert!(token_1.is_ok());
|
|
||||||
assert!(token_2.is_ok());
|
|
||||||
|
|
||||||
db.destroy_user(user_id).await.unwrap();
|
|
||||||
|
|
||||||
let user = db.get_user_by_id(user_id).await.unwrap();
|
|
||||||
assert!(user.is_none());
|
|
||||||
|
|
||||||
let token_1 = db.get_access_token(token_1_id).await;
|
|
||||||
let token_2 = db.get_access_token(token_2_id).await;
|
|
||||||
assert!(token_1.is_err());
|
|
||||||
assert!(token_2.is_err());
|
|
||||||
}
|
|
||||||
Loading…
Reference in a new issue