Skip to content

Commit 059afbb

Browse files
authored
Revert "Removing isEngineeringAccountFlag (#18)" (#20)
This reverts commit a1a7a84.
1 parent a1a7a84 commit 059afbb

File tree

1 file changed

+25
-4
lines changed

1 file changed

+25
-4
lines changed

api/src/endpoints/oauth.rs

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,8 @@ pub fn get_router() -> Router<Arc<AppState>> {
4242
#[cfg_attr(feature = "dummy", derive(fake::Dummy))]
4343
#[serde(rename_all = "camelCase")]
4444
struct OAuthRequest {
45+
#[serde(rename = "__isEngineeringAccount__", default)]
46+
is_engineering_account: bool,
4547
connection_definition_id: Id,
4648
client_id: String,
4749
group: String,
@@ -68,7 +70,12 @@ async fn oauth_handler(
6870
Json(payload): Json<OAuthRequest>,
6971
) -> ApiResult<Json<Connection>> {
7072
let oauth_definition = find_oauth_definition(&state, &platform).await?;
71-
let setting = find_settings(&state, &user_event_access.ownership).await?;
73+
let setting = find_settings(
74+
&state,
75+
&user_event_access.ownership,
76+
payload.is_engineering_account,
77+
)
78+
.await?;
7279

7380
let secret = get_secret::<PlatformSecret>(
7481
&state,
@@ -79,7 +86,11 @@ async fn oauth_handler(
7986
"Settings does not have a secret service id for the connection platform provided, settings"
8087
)
8188
})?,
82-
buildable_id: user_event_access.clone().ownership.id.to_string()
89+
buildable_id: if payload.is_engineering_account {
90+
state.config.engineering_account_id.clone()
91+
} else {
92+
user_event_access.clone().ownership.id.to_string()
93+
},
8394
},
8495
)
8596
.await?;
@@ -430,11 +441,21 @@ async fn find_oauth_definition(
430441
Ok(oauth_definition)
431442
}
432443

433-
async fn find_settings(state: &State<Arc<AppState>>, ownership: &Ownership) -> ApiResult<Settings> {
444+
async fn find_settings(
445+
state: &State<Arc<AppState>>,
446+
ownership: &Ownership,
447+
is_admin: bool,
448+
) -> ApiResult<Settings> {
434449
let settings_store: &MongoStore<Settings> = &state.app_stores.settings;
435450

451+
let ownership_id = if !is_admin {
452+
ownership.id.to_string()
453+
} else {
454+
state.config.engineering_account_id.clone()
455+
};
456+
436457
let setting: Settings = settings_store
437-
.get_one(doc! {"ownership.buildableId": &ownership.id.to_string()})
458+
.get_one(doc! {"ownership.buildableId": &ownership_id})
438459
.await
439460
.map_err(|e| {
440461
error!("Failed to retrieve from settings store: {}", e);

0 commit comments

Comments
 (0)