1// Copyright Materialize, Inc. and contributors. All rights reserved.
2//
3// Use of this software is governed by the Business Source License
4// included in the LICENSE file.
5//
6// As of the Change Date specified in that file, in accordance with
7// the Business Source License, use of this software will be governed
8// by the Apache License, Version 2.0.
910use axum::extract::Request;
11use axum::{extract::State, middleware::Next, response::IntoResponse};
1213use crate::server::Context;
14use std::sync::Arc;
1516pub async fn role_update_middleware(
17 State(context): State<Arc<Context>>,
18 request: Request,
19 next: Next,
20) -> impl IntoResponse {
21 {
22let mut role_updates_rx = context.role_updates_rx.lock().unwrap();
23while let Ok((email, roles)) = role_updates_rx.try_recv() {
24let mut users = context.users.lock().unwrap();
25 users.get_mut(&email).unwrap().roles = roles;
26 }
27 }
28 next.run(request).await
29}