@@ -98,7 +98,38 @@ pub fn summary(source: Option<&str>, detail: Option<&str>) -> Option<String> {
9898}
9999
100100/// `GET /api/ui/me`.
101- pub async fn me ( Authenticated ( user) : Authenticated < User > ) -> laravel:: Result < Json < Value > > {
101+ /// The forges a person can sign in with here: those whose OAuth application has its ID and secret.
102+ #[ derive( Clone , laravel:: config:: Section ) ]
103+ pub struct SignInApps {
104+ #[ env( "GITHUB_CLIENT_ID" ) ]
105+ pub github_id : Option < String > ,
106+ #[ env( "GITHUB_CLIENT_SECRET" ) ]
107+ pub github_secret : Option < String > ,
108+ #[ env( "GITLAB_CLIENT_ID" ) ]
109+ pub gitlab_id : Option < String > ,
110+ #[ env( "GITLAB_CLIENT_SECRET" ) ]
111+ pub gitlab_secret : Option < String > ,
112+ }
113+
114+ impl SignInApps {
115+ #[ must_use]
116+ pub fn forges ( & self ) -> Vec < & ' static str > {
117+ let set = |v : & Option < String > | v. as_deref ( ) . is_some_and ( |s| !s. trim ( ) . is_empty ( ) ) ;
118+ let mut forges = Vec :: new ( ) ;
119+ if set ( & self . github_id ) && set ( & self . github_secret ) {
120+ forges. push ( "github" ) ;
121+ }
122+ if set ( & self . gitlab_id ) && set ( & self . gitlab_secret ) {
123+ forges. push ( "gitlab" ) ;
124+ }
125+ forges
126+ }
127+ }
128+
129+ pub async fn me (
130+ Authenticated ( user) : Authenticated < User > ,
131+ apps : laravel:: config:: Section < SignInApps > ,
132+ ) -> laravel:: Result < Json < Value > > {
102133 let user_id = user. id ;
103134 let row = db:: query!(
104135 "SELECT staff, heard_about_pending, email_low_credits, email_receipts, \
@@ -119,6 +150,7 @@ pub async fn me(Authenticated(user): Authenticated<User>) -> laravel::Result<Jso
119150 "name" : user. name, "email" : user. email, "avatar_url" : user. avatar_url,
120151 "login" : identities. get( 0 ) . and_then( |i| i. get( "login" ) ) . cloned( ) , "identities" : identities,
121152 } ,
153+ "forges" : apps. forges( ) ,
122154 "organizations" : organizations,
123155 "invitations" : invitations:: pending_for( & user) . await ?,
124156 "staff" : row. try_get:: <bool >( "staff" ) ?,
@@ -218,7 +250,6 @@ pub async fn update_billing_email(
218250 match row. try_get :: < Option < String > > ( "role" ) ?. as_deref ( ) . and_then ( Role :: parse) {
219251 Some ( Role :: Admin ) => { }
220252 Some ( _) => return Err ( laravel:: abort_with ( 403 , "only admins can change the billing email" ) ) ,
221- None if user. staff => { }
222253 None => return Err ( laravel:: abort ( 404 ) ) ,
223254 }
224255 let email = p. billing_email . as_deref ( ) . unwrap_or ( "" ) . trim ( ) ;
@@ -354,16 +385,19 @@ impl NotifySignups {
354385 ) -> laravel:: Result < ( ) > {
355386 let result = queue_signups ( & team, & app. url ) . await ;
356387 let stale = WAIT_MINUTES + STALE_MINUTES ;
357- let oldest : Option < i64 > = db:: query!(
388+ let waiting = db:: query!(
358389 "SELECT count(*) FROM users WHERE signup_notified_at IS NULL \
359390 AND created_at < now() - make_interval(mins => {stale}::int)"
360391 )
361- . scalar ( )
362- . await
363- . unwrap_or ( None ) ;
364- let health = match ( & result, oldest ) {
392+ . scalar :: < i64 > ( )
393+ . await ;
394+ // A database that can't answer fails the heartbeat too.
395+ let health = match ( & result, waiting ) {
365396 ( Err ( e) , _) => Err ( e. to_string ( ) ) ,
366- ( Ok ( _) , Some ( n) ) if n > 0 => Err ( format ! ( "{n} sign-ups waited over {stale} minutes for the team's email" ) ) ,
397+ ( Ok ( _) , Err ( e) ) => Err ( e. to_string ( ) ) ,
398+ ( Ok ( _) , Ok ( Some ( n) ) ) if n > 0 => {
399+ Err ( format ! ( "{n} sign-ups waited over {stale} minutes for the team's email" ) )
400+ }
367401 _ => Ok ( ( ) ) ,
368402 } ;
369403 crate :: heartbeat:: push ( "VISUALCI_SIGNUPS_HEARTBEAT" , health) . await ;
0 commit comments