Skip to content

Commit

Permalink
Revert "Removing isEngineeringAccountFlag (#18)" (#20)
Browse files Browse the repository at this point in the history
This reverts commit a1a7a84.
  • Loading branch information
sagojez authored May 7, 2024
1 parent a1a7a84 commit 059afbb
Showing 1 changed file with 25 additions and 4 deletions.
29 changes: 25 additions & 4 deletions api/src/endpoints/oauth.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ pub fn get_router() -> Router<Arc<AppState>> {
#[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,
Expand All @@ -68,7 +70,12 @@ async fn oauth_handler(
Json(payload): Json<OAuthRequest>,
) -> ApiResult<Json<Connection>> {
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::<PlatformSecret>(
&state,
Expand All @@ -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?;
Expand Down Expand Up @@ -430,11 +441,21 @@ async fn find_oauth_definition(
Ok(oauth_definition)
}

async fn find_settings(state: &State<Arc<AppState>>, ownership: &Ownership) -> ApiResult<Settings> {
async fn find_settings(
state: &State<Arc<AppState>>,
ownership: &Ownership,
is_admin: bool,
) -> ApiResult<Settings> {
let settings_store: &MongoStore<Settings> = &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);
Expand Down

0 comments on commit 059afbb

Please sign in to comment.