Update names of collab auth functions to clarify behavior (#32648)
Release Notes: - N/A
This commit is contained in:
parent
cef0c415f6
commit
1078f929aa
7 changed files with 23 additions and 16 deletions
|
@ -97,7 +97,7 @@ impl std::fmt::Display for SystemIdHeader {
|
||||||
|
|
||||||
pub fn routes(rpc_server: Arc<rpc::Server>) -> Router<(), Body> {
|
pub fn routes(rpc_server: Arc<rpc::Server>) -> Router<(), Body> {
|
||||||
Router::new()
|
Router::new()
|
||||||
.route("/user", get(get_authenticated_user))
|
.route("/user", get(update_or_create_authenticated_user))
|
||||||
.route("/users/look_up", get(look_up_user))
|
.route("/users/look_up", get(look_up_user))
|
||||||
.route("/users/:id/access_tokens", post(create_access_token))
|
.route("/users/:id/access_tokens", post(create_access_token))
|
||||||
.route("/rpc_server_snapshot", get(get_rpc_server_snapshot))
|
.route("/rpc_server_snapshot", get(get_rpc_server_snapshot))
|
||||||
|
@ -157,7 +157,7 @@ struct AuthenticatedUserResponse {
|
||||||
feature_flags: Vec<String>,
|
feature_flags: Vec<String>,
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn get_authenticated_user(
|
async fn update_or_create_authenticated_user(
|
||||||
Query(params): Query<AuthenticatedUserParams>,
|
Query(params): Query<AuthenticatedUserParams>,
|
||||||
Extension(app): Extension<Arc<AppState>>,
|
Extension(app): Extension<Arc<AppState>>,
|
||||||
) -> Result<Json<AuthenticatedUserResponse>> {
|
) -> Result<Json<AuthenticatedUserResponse>> {
|
||||||
|
@ -165,7 +165,7 @@ async fn get_authenticated_user(
|
||||||
|
|
||||||
let user = app
|
let user = app
|
||||||
.db
|
.db
|
||||||
.get_or_create_user_by_github_account(
|
.update_or_create_user_by_github_account(
|
||||||
¶ms.github_login,
|
¶ms.github_login,
|
||||||
params.github_user_id,
|
params.github_user_id,
|
||||||
params.github_email.as_deref(),
|
params.github_email.as_deref(),
|
||||||
|
|
|
@ -71,7 +71,7 @@ impl Database {
|
||||||
) -> Result<()> {
|
) -> Result<()> {
|
||||||
self.weak_transaction(|tx| async move {
|
self.weak_transaction(|tx| async move {
|
||||||
let user = self
|
let user = self
|
||||||
.get_or_create_user_by_github_account_tx(
|
.update_or_create_user_by_github_account_tx(
|
||||||
github_login,
|
github_login,
|
||||||
github_user_id,
|
github_user_id,
|
||||||
github_email,
|
github_email,
|
||||||
|
|
|
@ -111,7 +111,7 @@ impl Database {
|
||||||
.await
|
.await
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn get_or_create_user_by_github_account(
|
pub async fn update_or_create_user_by_github_account(
|
||||||
&self,
|
&self,
|
||||||
github_login: &str,
|
github_login: &str,
|
||||||
github_user_id: i32,
|
github_user_id: i32,
|
||||||
|
@ -121,7 +121,7 @@ impl Database {
|
||||||
initial_channel_id: Option<ChannelId>,
|
initial_channel_id: Option<ChannelId>,
|
||||||
) -> Result<User> {
|
) -> Result<User> {
|
||||||
self.transaction(|tx| async move {
|
self.transaction(|tx| async move {
|
||||||
self.get_or_create_user_by_github_account_tx(
|
self.update_or_create_user_by_github_account_tx(
|
||||||
github_login,
|
github_login,
|
||||||
github_user_id,
|
github_user_id,
|
||||||
github_email,
|
github_email,
|
||||||
|
@ -135,7 +135,7 @@ impl Database {
|
||||||
.await
|
.await
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn get_or_create_user_by_github_account_tx(
|
pub async fn update_or_create_user_by_github_account_tx(
|
||||||
&self,
|
&self,
|
||||||
github_login: &str,
|
github_login: &str,
|
||||||
github_user_id: i32,
|
github_user_id: i32,
|
||||||
|
|
|
@ -72,12 +72,12 @@ async fn test_get_users(db: &Arc<Database>) {
|
||||||
}
|
}
|
||||||
|
|
||||||
test_both_dbs!(
|
test_both_dbs!(
|
||||||
test_get_or_create_user_by_github_account,
|
test_update_or_create_user_by_github_account,
|
||||||
test_get_or_create_user_by_github_account_postgres,
|
test_update_or_create_user_by_github_account_postgres,
|
||||||
test_get_or_create_user_by_github_account_sqlite
|
test_update_or_create_user_by_github_account_sqlite
|
||||||
);
|
);
|
||||||
|
|
||||||
async fn test_get_or_create_user_by_github_account(db: &Arc<Database>) {
|
async fn test_update_or_create_user_by_github_account(db: &Arc<Database>) {
|
||||||
db.create_user(
|
db.create_user(
|
||||||
"user1@example.com",
|
"user1@example.com",
|
||||||
None,
|
None,
|
||||||
|
@ -104,7 +104,14 @@ async fn test_get_or_create_user_by_github_account(db: &Arc<Database>) {
|
||||||
.user_id;
|
.user_id;
|
||||||
|
|
||||||
let user = db
|
let user = db
|
||||||
.get_or_create_user_by_github_account("the-new-login2", 102, None, None, Utc::now(), None)
|
.update_or_create_user_by_github_account(
|
||||||
|
"the-new-login2",
|
||||||
|
102,
|
||||||
|
None,
|
||||||
|
None,
|
||||||
|
Utc::now(),
|
||||||
|
None,
|
||||||
|
)
|
||||||
.await
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
assert_eq!(user.id, user_id2);
|
assert_eq!(user.id, user_id2);
|
||||||
|
@ -112,7 +119,7 @@ async fn test_get_or_create_user_by_github_account(db: &Arc<Database>) {
|
||||||
assert_eq!(user.github_user_id, 102);
|
assert_eq!(user.github_user_id, 102);
|
||||||
|
|
||||||
let user = db
|
let user = db
|
||||||
.get_or_create_user_by_github_account(
|
.update_or_create_user_by_github_account(
|
||||||
"login3",
|
"login3",
|
||||||
103,
|
103,
|
||||||
Some("user3@example.com"),
|
Some("user3@example.com"),
|
||||||
|
|
|
@ -127,7 +127,7 @@ pub async fn seed(config: &Config, db: &Database, force: bool) -> anyhow::Result
|
||||||
log::info!("Seeding {:?} from GitHub", github_user.login);
|
log::info!("Seeding {:?} from GitHub", github_user.login);
|
||||||
|
|
||||||
let user = db
|
let user = db
|
||||||
.get_or_create_user_by_github_account(
|
.update_or_create_user_by_github_account(
|
||||||
&github_user.login,
|
&github_user.login,
|
||||||
github_user.id,
|
github_user.id,
|
||||||
github_user.email.as_deref(),
|
github_user.email.as_deref(),
|
||||||
|
|
|
@ -180,7 +180,7 @@ async fn test_channel_requires_zed_cla(cx_a: &mut TestAppContext, cx_b: &mut Tes
|
||||||
server
|
server
|
||||||
.app_state
|
.app_state
|
||||||
.db
|
.db
|
||||||
.get_or_create_user_by_github_account("user_b", 100, None, None, Utc::now(), None)
|
.update_or_create_user_by_github_account("user_b", 100, None, None, Utc::now(), None)
|
||||||
.await
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
|
|
|
@ -82,7 +82,7 @@ impl UserBackfiller {
|
||||||
{
|
{
|
||||||
Ok(github_user) => {
|
Ok(github_user) => {
|
||||||
self.db
|
self.db
|
||||||
.get_or_create_user_by_github_account(
|
.update_or_create_user_by_github_account(
|
||||||
&user.github_login,
|
&user.github_login,
|
||||||
github_user.id,
|
github_user.id,
|
||||||
user.email_address.as_deref(),
|
user.email_address.as_deref(),
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue