Skip to content

Commit b9c110e

Browse files
authored
collab: Remove GET /users/look_up endpoint (#36279)
This PR removes the `GET /users/look_up` endpoint from Collab, as it has been moved to Cloud. Release Notes: - N/A
1 parent f642f76 commit b9c110e

File tree

1 file changed

+1
-100
lines changed

1 file changed

+1
-100
lines changed

crates/collab/src/api.rs

Lines changed: 1 addition & 100 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,7 @@ pub mod extensions;
44
pub mod ips_file;
55
pub mod slack;
66

7-
use crate::db::Database;
8-
use crate::{
9-
AppState, Error, Result, auth,
10-
db::{User, UserId},
11-
rpc,
12-
};
7+
use crate::{AppState, Error, Result, auth, db::UserId, rpc};
138
use anyhow::Context as _;
149
use axum::{
1510
Extension, Json, Router,
@@ -96,7 +91,6 @@ impl std::fmt::Display for SystemIdHeader {
9691

9792
pub fn routes(rpc_server: Arc<rpc::Server>) -> Router<(), Body> {
9893
Router::new()
99-
.route("/users/look_up", get(look_up_user))
10094
.route("/users/:id/access_tokens", post(create_access_token))
10195
.route("/rpc_server_snapshot", get(get_rpc_server_snapshot))
10296
.merge(contributors::router())
@@ -138,99 +132,6 @@ pub async fn validate_api_token<B>(req: Request<B>, next: Next<B>) -> impl IntoR
138132
Ok::<_, Error>(next.run(req).await)
139133
}
140134

141-
#[derive(Debug, Deserialize)]
142-
struct LookUpUserParams {
143-
identifier: String,
144-
}
145-
146-
#[derive(Debug, Serialize)]
147-
struct LookUpUserResponse {
148-
user: Option<User>,
149-
}
150-
151-
async fn look_up_user(
152-
Query(params): Query<LookUpUserParams>,
153-
Extension(app): Extension<Arc<AppState>>,
154-
) -> Result<Json<LookUpUserResponse>> {
155-
let user = resolve_identifier_to_user(&app.db, &params.identifier).await?;
156-
let user = if let Some(user) = user {
157-
match user {
158-
UserOrId::User(user) => Some(user),
159-
UserOrId::Id(id) => app.db.get_user_by_id(id).await?,
160-
}
161-
} else {
162-
None
163-
};
164-
165-
Ok(Json(LookUpUserResponse { user }))
166-
}
167-
168-
enum UserOrId {
169-
User(User),
170-
Id(UserId),
171-
}
172-
173-
async fn resolve_identifier_to_user(
174-
db: &Arc<Database>,
175-
identifier: &str,
176-
) -> Result<Option<UserOrId>> {
177-
if let Some(identifier) = identifier.parse::<i32>().ok() {
178-
let user = db.get_user_by_id(UserId(identifier)).await?;
179-
180-
return Ok(user.map(UserOrId::User));
181-
}
182-
183-
if identifier.starts_with("cus_") {
184-
let billing_customer = db
185-
.get_billing_customer_by_stripe_customer_id(&identifier)
186-
.await?;
187-
188-
return Ok(billing_customer.map(|billing_customer| UserOrId::Id(billing_customer.user_id)));
189-
}
190-
191-
if identifier.starts_with("sub_") {
192-
let billing_subscription = db
193-
.get_billing_subscription_by_stripe_subscription_id(&identifier)
194-
.await?;
195-
196-
if let Some(billing_subscription) = billing_subscription {
197-
let billing_customer = db
198-
.get_billing_customer_by_id(billing_subscription.billing_customer_id)
199-
.await?;
200-
201-
return Ok(
202-
billing_customer.map(|billing_customer| UserOrId::Id(billing_customer.user_id))
203-
);
204-
} else {
205-
return Ok(None);
206-
}
207-
}
208-
209-
if identifier.contains('@') {
210-
let user = db.get_user_by_email(identifier).await?;
211-
212-
return Ok(user.map(UserOrId::User));
213-
}
214-
215-
if let Some(user) = db.get_user_by_github_login(identifier).await? {
216-
return Ok(Some(UserOrId::User(user)));
217-
}
218-
219-
Ok(None)
220-
}
221-
222-
#[derive(Deserialize, Debug)]
223-
struct CreateUserParams {
224-
github_user_id: i32,
225-
github_login: String,
226-
email_address: String,
227-
email_confirmation_code: Option<String>,
228-
#[serde(default)]
229-
admin: bool,
230-
#[serde(default)]
231-
invite_count: i32,
232-
}
233-
234135
async fn get_rpc_server_snapshot(
235136
Extension(rpc_server): Extension<Arc<rpc::Server>>,
236137
) -> Result<ErasedJson> {

0 commit comments

Comments
 (0)