@@ -6,8 +6,9 @@ use axum::{
6
6
extract:: { OriginalUri , Path , Query , State } ,
7
7
response:: { Html , IntoResponse , Response } ,
8
8
} ;
9
- use futures:: future:: join_all;
9
+ use futures:: future:: { join , join_all} ;
10
10
use http:: { header:: CONTENT_TYPE , StatusCode , Uri } ;
11
+ use octocrab:: Octocrab ;
11
12
use serde:: Deserialize ;
12
13
use tower_sessions:: Session ;
13
14
@@ -18,7 +19,7 @@ use crate::{
18
19
TraineeStatus ,
19
20
} ,
20
21
google_groups:: { get_groups, groups_client, GoogleGroup } ,
21
- octocrab:: octocrab,
22
+ octocrab:: { all_pages , octocrab} ,
22
23
prs:: { MaybeReviewerStaffOnlyDetails , PrState , ReviewerInfo } ,
23
24
reviewer_staff_info:: get_reviewer_staff_info,
24
25
sheets:: sheets_client,
@@ -42,6 +43,11 @@ pub async fn list_courses(
42
43
. await
43
44
. into_iter ( )
44
45
. collect :: < Result < Vec < _ > , _ > > ( ) ?;
46
+
47
+ let is_staff = is_staff ( & octocrab, & server_state. config . github_org )
48
+ . await
49
+ . unwrap_or ( false ) ;
50
+
45
51
let courses_with_batch_metadata = courses
46
52
. keys ( )
47
53
. zip ( batch_metadata)
@@ -75,16 +81,39 @@ pub async fn list_courses(
75
81
Ok ( Html (
76
82
ListCoursesTemplate {
77
83
courses_with_batch_metadata,
84
+ is_staff,
78
85
}
79
86
. render ( )
80
87
. unwrap ( ) ,
81
88
) )
82
89
}
83
90
91
+ async fn is_staff ( octocrab : & Octocrab , github_org : & str ) -> Result < bool , Error > {
92
+ let team_future = all_pages ( "staff team members" , octocrab, async || {
93
+ octocrab
94
+ . teams ( github_org)
95
+ . members ( "cyf-staff-team" )
96
+ . send ( )
97
+ . await
98
+ } ) ;
99
+ let current = octocrab. current ( ) ;
100
+ let self_future = current. user ( ) ;
101
+ let ( team_members, user) = join ( team_future, self_future) . await ;
102
+ let team_members = team_members?;
103
+ let user = user. context ( "Failed to get current user" ) ?;
104
+ for team_member in team_members {
105
+ if team_member. login == user. login {
106
+ return Ok ( true ) ;
107
+ }
108
+ }
109
+ Ok ( false )
110
+ }
111
+
84
112
#[ derive( Template ) ]
85
113
#[ template( path = "list-courses.html" ) ]
86
114
struct ListCoursesTemplate {
87
115
pub courses_with_batch_metadata : Vec < CourseScheduleWithBatchMetadata > ,
116
+ pub is_staff : bool ,
88
117
}
89
118
90
119
struct CourseScheduleWithBatchMetadata {
0 commit comments