From db1f7d166957e7a8f2fa89dbf21f8ae5fa99fc4a Mon Sep 17 00:00:00 2001 From: Samuel <39674930+samgj18@users.noreply.github.com> Date: Thu, 9 May 2024 20:09:31 +0100 Subject: [PATCH] Using proper id for creating OAuth connection (#26) --- api/src/endpoints/oauth.rs | 25 ++++++++++++++++++------- 1 file changed, 18 insertions(+), 7 deletions(-) diff --git a/api/src/endpoints/oauth.rs b/api/src/endpoints/oauth.rs index 0915a503..4512abed 100644 --- a/api/src/endpoints/oauth.rs +++ b/api/src/endpoints/oauth.rs @@ -73,12 +73,16 @@ async fn oauth_handler( Json(payload): Json, ) -> Result, IntegrationOSError> { let conn_oauth_definition = get_conn_oauth_definition(&state, &platform).await?; - let setting = get_user_settings(&state, &user_event_access.ownership) - .await - .map_err(|e| { - error!("Failed to get user settings: {:?}", e); - e - })?; + let setting = get_user_settings( + &state, + &user_event_access.ownership, + payload.is_engineering_account, + ) + .await + .map_err(|e| { + error!("Failed to get user settings: {:?}", e); + e + })?; let secret = get_secret::( &state, @@ -452,11 +456,18 @@ async fn get_conn_oauth_definition( pub async fn get_user_settings( state: &State>, ownership: &Ownership, + is_engineering_account: bool, ) -> Result { let settings_store: &MongoStore = &state.app_stores.settings; + let ownership_id = if is_engineering_account { + state.config.engineering_account_id.clone() + } else { + ownership.id.to_string() + }; + let setting: Settings = settings_store - .get_one(doc! {"ownership.buildableId": &ownership.id.to_string()}) + .get_one(doc! {"ownership.buildableId": &ownership_id}) .await? .ok_or_else(|| ApplicationError::not_found("Settings", None))?;