Skip to content

Commit 4edd573

Browse files
committed
Add 'Staff view' links
1 parent a7f5003 commit 4edd573

File tree

2 files changed

+37
-3
lines changed

2 files changed

+37
-3
lines changed

src/frontend.rs

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,9 @@ use axum::{
66
extract::{OriginalUri, Path, Query, State},
77
response::{Html, IntoResponse, Response},
88
};
9-
use futures::future::join_all;
9+
use futures::future::{join, join_all};
1010
use http::{header::CONTENT_TYPE, StatusCode, Uri};
11+
use octocrab::Octocrab;
1112
use serde::Deserialize;
1213
use tower_sessions::Session;
1314

@@ -18,7 +19,7 @@ use crate::{
1819
TraineeStatus,
1920
},
2021
google_groups::{get_groups, groups_client, GoogleGroup},
21-
octocrab::octocrab,
22+
octocrab::{all_pages, octocrab},
2223
prs::{MaybeReviewerStaffOnlyDetails, PrState, ReviewerInfo},
2324
reviewer_staff_info::get_reviewer_staff_info,
2425
sheets::sheets_client,
@@ -42,6 +43,11 @@ pub async fn list_courses(
4243
.await
4344
.into_iter()
4445
.collect::<Result<Vec<_>, _>>()?;
46+
47+
let is_staff = is_staff(&octocrab, &server_state.config.github_org)
48+
.await
49+
.unwrap_or(false);
50+
4551
let courses_with_batch_metadata = courses
4652
.keys()
4753
.zip(batch_metadata)
@@ -75,16 +81,39 @@ pub async fn list_courses(
7581
Ok(Html(
7682
ListCoursesTemplate {
7783
courses_with_batch_metadata,
84+
is_staff,
7885
}
7986
.render()
8087
.unwrap(),
8188
))
8289
}
8390

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+
84112
#[derive(Template)]
85113
#[template(path = "list-courses.html")]
86114
struct ListCoursesTemplate {
87115
pub courses_with_batch_metadata: Vec<CourseScheduleWithBatchMetadata>,
116+
pub is_staff: bool,
88117
}
89118

90119
struct CourseScheduleWithBatchMetadata {

templates/list-courses.html

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,12 @@ <h2>{{ cwbm.course.name }}</h2>
88
{% for batch in cwbm.batch_metadata %}
99
<li><a href="/courses/{{ cwbm.course.name }}/batches/{{ batch.github_team_slug }}">{{ batch.name }}</a></li>
1010
{% endfor %}
11-
<li><a href="/courses/{{ cwbm.course.name }}/reviewers">Reviewers</a></li>
11+
<li>
12+
<a href="/courses/{{ cwbm.course.name }}/reviewers">Reviewers</a>
13+
{% if is_staff %}
14+
(<a href="/courses/{{ cwbm.course.name }}/reviewers?staff=true">Staff view</a>)
15+
{% endif %}
16+
</li>
1217
</ul>
1318
{% endfor %}
1419
</body>

0 commit comments

Comments
 (0)