@@ -42,6 +42,8 @@ pub fn get_router() -> Router<Arc<AppState>> {
42
42
#[ cfg_attr( feature = "dummy" , derive( fake:: Dummy ) ) ]
43
43
#[ serde( rename_all = "camelCase" ) ]
44
44
struct OAuthRequest {
45
+ #[ serde( rename = "__isEngineeringAccount__" , default ) ]
46
+ is_engineering_account : bool ,
45
47
connection_definition_id : Id ,
46
48
client_id : String ,
47
49
group : String ,
@@ -68,7 +70,12 @@ async fn oauth_handler(
68
70
Json ( payload) : Json < OAuthRequest > ,
69
71
) -> ApiResult < Json < Connection > > {
70
72
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 ?;
72
79
73
80
let secret = get_secret :: < PlatformSecret > (
74
81
& state,
@@ -79,7 +86,11 @@ async fn oauth_handler(
79
86
"Settings does not have a secret service id for the connection platform provided, settings"
80
87
)
81
88
} ) ?,
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
+ } ,
83
94
} ,
84
95
)
85
96
. await ?;
@@ -430,11 +441,21 @@ async fn find_oauth_definition(
430
441
Ok ( oauth_definition)
431
442
}
432
443
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 > {
434
449
let settings_store: & MongoStore < Settings > = & state. app_stores . settings ;
435
450
451
+ let ownership_id = if !is_admin {
452
+ ownership. id . to_string ( )
453
+ } else {
454
+ state. config . engineering_account_id . clone ( )
455
+ } ;
456
+
436
457
let setting: Settings = settings_store
437
- . get_one ( doc ! { "ownership.buildableId" : & ownership . id . to_string ( ) } )
458
+ . get_one ( doc ! { "ownership.buildableId" : & ownership_id } )
438
459
. await
439
460
. map_err ( |e| {
440
461
error ! ( "Failed to retrieve from settings store: {}" , e) ;
0 commit comments