diff --git a/crates/cli/src/commands/server.rs b/crates/cli/src/commands/server.rs index e45a5c0c..3bad4f8a 100644 --- a/crates/cli/src/commands/server.rs +++ b/crates/cli/src/commands/server.rs @@ -194,8 +194,12 @@ impl Options { // Listen for SIGHUP register_sighup(&templates, &activity_tracker)?; - let graphql_schema = - mas_handlers::graphql_schema(&pool, &policy_factory, homeserver_connection.clone()); + let graphql_schema = mas_handlers::graphql_schema( + &pool, + &policy_factory, + homeserver_connection.clone(), + site_config.clone(), + ); let state = { let mut s = AppState { diff --git a/crates/graphql/src/state.rs b/crates/graphql/src/state.rs index 441d9a74..b2e806e1 100644 --- a/crates/graphql/src/state.rs +++ b/crates/graphql/src/state.rs @@ -12,6 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. +use mas_data_model::SiteConfig; use mas_matrix::HomeserverConnection; use mas_policy::Policy; use mas_storage::{BoxClock, BoxRepository, BoxRng, RepositoryError}; @@ -25,6 +26,7 @@ pub trait State { fn homeserver_connection(&self) -> &dyn HomeserverConnection; fn clock(&self) -> BoxClock; fn rng(&self) -> BoxRng; + fn site_config(&self) -> &SiteConfig; } pub type BoxState = Box; diff --git a/crates/handlers/src/graphql/mod.rs b/crates/handlers/src/graphql/mod.rs index 7306435a..5ba67c83 100644 --- a/crates/handlers/src/graphql/mod.rs +++ b/crates/handlers/src/graphql/mod.rs @@ -31,7 +31,7 @@ use hyper::header::CACHE_CONTROL; use mas_axum_utils::{ cookies::CookieJar, sentry::SentryEventID, FancyError, SessionInfo, SessionInfoExt, }; -use mas_data_model::User; +use mas_data_model::{SiteConfig, User}; use mas_graphql::{Requester, Schema}; use mas_matrix::HomeserverConnection; use mas_policy::{InstantiateError, Policy, PolicyFactory}; @@ -54,6 +54,7 @@ struct GraphQLState { pool: PgPool, homeserver_connection: Arc>, policy_factory: Arc, + site_config: SiteConfig, } #[async_trait] @@ -70,6 +71,10 @@ impl mas_graphql::State for GraphQLState { self.policy_factory.instantiate().await } + fn site_config(&self) -> &SiteConfig { + &self.site_config + } + fn homeserver_connection(&self) -> &dyn HomeserverConnection { self.homeserver_connection.as_ref() } @@ -93,11 +98,13 @@ pub fn schema( pool: &PgPool, policy_factory: &Arc, homeserver_connection: impl HomeserverConnection + 'static, + site_config: SiteConfig, ) -> Schema { let state = GraphQLState { pool: pool.clone(), policy_factory: Arc::clone(policy_factory), homeserver_connection: Arc::new(homeserver_connection), + site_config, }; let state: mas_graphql::BoxState = Box::new(state); diff --git a/crates/handlers/src/test_utils.rs b/crates/handlers/src/test_utils.rs index 3aaf02b2..8f450d57 100644 --- a/crates/handlers/src/test_utils.rs +++ b/crates/handlers/src/test_utils.rs @@ -193,6 +193,7 @@ impl TestState { pool: pool.clone(), policy_factory: Arc::clone(&policy_factory), homeserver_connection: Arc::clone(&homeserver_connection), + site_config: site_config.clone(), rng: Arc::clone(&rng), clock: Arc::clone(&clock), }; @@ -307,6 +308,7 @@ impl TestState { struct TestGraphQLState { pool: PgPool, homeserver_connection: Arc, + site_config: SiteConfig, policy_factory: Arc, clock: Arc, rng: Arc>, @@ -336,6 +338,10 @@ impl mas_graphql::State for TestGraphQLState { Box::new(self.clock.clone()) } + fn site_config(&self) -> &SiteConfig { + &self.site_config + } + fn rng(&self) -> BoxRng { let mut parent_rng = self.rng.lock().expect("Failed to lock RNG"); let rng = ChaChaRng::from_rng(&mut *parent_rng).expect("Failed to seed RNG");