From 059afbb5d82743c4c76a48ae61cebe1e543a972a Mon Sep 17 00:00:00 2001 From: Samuel <39674930+samgj18@users.noreply.github.com> Date: Tue, 7 May 2024 17:09:40 +0100 Subject: [PATCH] Revert "Removing isEngineeringAccountFlag (#18)" (#20) This reverts commit a1a7a84c24a0046f2bdadb606b972138545de627. --- api/src/endpoints/oauth.rs | 29 +++++++++++++++++++++++++---- 1 file changed, 25 insertions(+), 4 deletions(-) diff --git a/api/src/endpoints/oauth.rs b/api/src/endpoints/oauth.rs index 68016cc0..e0535d4c 100644 --- a/api/src/endpoints/oauth.rs +++ b/api/src/endpoints/oauth.rs @@ -42,6 +42,8 @@ pub fn get_router() -> Router> { #[cfg_attr(feature = "dummy", derive(fake::Dummy))] #[serde(rename_all = "camelCase")] struct OAuthRequest { + #[serde(rename = "__isEngineeringAccount__", default)] + is_engineering_account: bool, connection_definition_id: Id, client_id: String, group: String, @@ -68,7 +70,12 @@ async fn oauth_handler( Json(payload): Json, ) -> ApiResult> { let oauth_definition = find_oauth_definition(&state, &platform).await?; - let setting = find_settings(&state, &user_event_access.ownership).await?; + let setting = find_settings( + &state, + &user_event_access.ownership, + payload.is_engineering_account, + ) + .await?; let secret = get_secret::( &state, @@ -79,7 +86,11 @@ async fn oauth_handler( "Settings does not have a secret service id for the connection platform provided, settings" ) })?, - buildable_id: user_event_access.clone().ownership.id.to_string() + buildable_id: if payload.is_engineering_account { + state.config.engineering_account_id.clone() + } else { + user_event_access.clone().ownership.id.to_string() + }, }, ) .await?; @@ -430,11 +441,21 @@ async fn find_oauth_definition( Ok(oauth_definition) } -async fn find_settings(state: &State>, ownership: &Ownership) -> ApiResult { +async fn find_settings( + state: &State>, + ownership: &Ownership, + is_admin: bool, +) -> ApiResult { let settings_store: &MongoStore = &state.app_stores.settings; + let ownership_id = if !is_admin { + ownership.id.to_string() + } else { + state.config.engineering_account_id.clone() + }; + let setting: Settings = settings_store - .get_one(doc! {"ownership.buildableId": &ownership.id.to_string()}) + .get_one(doc! {"ownership.buildableId": &ownership_id}) .await .map_err(|e| { error!("Failed to retrieve from settings store: {}", e);