You've already forked authentication-service
mirror of
https://github.com/matrix-org/matrix-authentication-service.git
synced 2025-08-09 04:22:45 +03:00
Finish moving the site config
This commit is contained in:
@@ -19,9 +19,10 @@ use axum::{
|
|||||||
extract::{FromRef, FromRequestParts},
|
extract::{FromRef, FromRequestParts},
|
||||||
};
|
};
|
||||||
use ipnetwork::IpNetwork;
|
use ipnetwork::IpNetwork;
|
||||||
|
use mas_data_model::SiteConfig;
|
||||||
use mas_handlers::{
|
use mas_handlers::{
|
||||||
passwords::PasswordManager, ActivityTracker, BoundActivityTracker, CookieManager, ErrorWrapper,
|
passwords::PasswordManager, ActivityTracker, BoundActivityTracker, CookieManager, ErrorWrapper,
|
||||||
HttpClientFactory, MetadataCache, SiteConfig,
|
HttpClientFactory, MetadataCache,
|
||||||
};
|
};
|
||||||
use mas_i18n::Translator;
|
use mas_i18n::Translator;
|
||||||
use mas_keystore::{Encrypter, Keystore};
|
use mas_keystore::{Encrypter, Keystore};
|
||||||
|
@@ -19,11 +19,12 @@ use mas_config::{
|
|||||||
BrandingConfig, DatabaseConfig, EmailConfig, EmailSmtpMode, EmailTransportKind,
|
BrandingConfig, DatabaseConfig, EmailConfig, EmailSmtpMode, EmailTransportKind,
|
||||||
ExperimentalConfig, MatrixConfig, PasswordsConfig, PolicyConfig, TemplatesConfig,
|
ExperimentalConfig, MatrixConfig, PasswordsConfig, PolicyConfig, TemplatesConfig,
|
||||||
};
|
};
|
||||||
|
use mas_data_model::SiteConfig;
|
||||||
use mas_email::{MailTransport, Mailer};
|
use mas_email::{MailTransport, Mailer};
|
||||||
use mas_handlers::{passwords::PasswordManager, ActivityTracker, SiteConfig, SiteConfigExt};
|
use mas_handlers::{passwords::PasswordManager, ActivityTracker};
|
||||||
use mas_policy::PolicyFactory;
|
use mas_policy::PolicyFactory;
|
||||||
use mas_router::UrlBuilder;
|
use mas_router::UrlBuilder;
|
||||||
use mas_templates::{TemplateLoadingError, Templates};
|
use mas_templates::{SiteConfigExt, TemplateLoadingError, Templates};
|
||||||
use sqlx::{
|
use sqlx::{
|
||||||
postgres::{PgConnectOptions, PgPoolOptions},
|
postgres::{PgConnectOptions, PgPoolOptions},
|
||||||
ConnectOptions, PgConnection, PgPool,
|
ConnectOptions, PgConnection, PgPool,
|
||||||
|
@@ -16,7 +16,9 @@ use axum::{extract::State, response::IntoResponse, Json, TypedHeader};
|
|||||||
use chrono::Duration;
|
use chrono::Duration;
|
||||||
use hyper::StatusCode;
|
use hyper::StatusCode;
|
||||||
use mas_axum_utils::sentry::SentryEventID;
|
use mas_axum_utils::sentry::SentryEventID;
|
||||||
use mas_data_model::{CompatSession, CompatSsoLoginState, Device, TokenType, User, UserAgent};
|
use mas_data_model::{
|
||||||
|
CompatSession, CompatSsoLoginState, Device, SiteConfig, TokenType, User, UserAgent,
|
||||||
|
};
|
||||||
use mas_matrix::BoxHomeserverConnection;
|
use mas_matrix::BoxHomeserverConnection;
|
||||||
use mas_storage::{
|
use mas_storage::{
|
||||||
compat::{
|
compat::{
|
||||||
@@ -34,10 +36,7 @@ use thiserror::Error;
|
|||||||
use zeroize::Zeroizing;
|
use zeroize::Zeroizing;
|
||||||
|
|
||||||
use super::MatrixError;
|
use super::MatrixError;
|
||||||
use crate::{
|
use crate::{impl_from_error_for_route, passwords::PasswordManager, BoundActivityTracker};
|
||||||
impl_from_error_for_route, passwords::PasswordManager, site_config::SiteConfig,
|
|
||||||
BoundActivityTracker,
|
|
||||||
};
|
|
||||||
|
|
||||||
#[derive(Debug, Serialize)]
|
#[derive(Debug, Serialize)]
|
||||||
#[serde(tag = "type")]
|
#[serde(tag = "type")]
|
||||||
|
@@ -16,7 +16,7 @@ use axum::{extract::State, response::IntoResponse, Json};
|
|||||||
use chrono::Duration;
|
use chrono::Duration;
|
||||||
use hyper::StatusCode;
|
use hyper::StatusCode;
|
||||||
use mas_axum_utils::sentry::SentryEventID;
|
use mas_axum_utils::sentry::SentryEventID;
|
||||||
use mas_data_model::{TokenFormatError, TokenType};
|
use mas_data_model::{SiteConfig, TokenFormatError, TokenType};
|
||||||
use mas_storage::{
|
use mas_storage::{
|
||||||
compat::{CompatAccessTokenRepository, CompatRefreshTokenRepository, CompatSessionRepository},
|
compat::{CompatAccessTokenRepository, CompatRefreshTokenRepository, CompatSessionRepository},
|
||||||
BoxClock, BoxRepository, BoxRng, Clock,
|
BoxClock, BoxRepository, BoxRng, Clock,
|
||||||
@@ -26,7 +26,7 @@ use serde_with::{serde_as, DurationMilliSeconds};
|
|||||||
use thiserror::Error;
|
use thiserror::Error;
|
||||||
|
|
||||||
use super::MatrixError;
|
use super::MatrixError;
|
||||||
use crate::{impl_from_error_for_route, site_config::SiteConfig, BoundActivityTracker};
|
use crate::{impl_from_error_for_route, BoundActivityTracker};
|
||||||
|
|
||||||
#[derive(Debug, Deserialize)]
|
#[derive(Debug, Deserialize)]
|
||||||
pub struct RequestBody {
|
pub struct RequestBody {
|
||||||
|
@@ -41,6 +41,7 @@ use hyper::{
|
|||||||
StatusCode, Version,
|
StatusCode, Version,
|
||||||
};
|
};
|
||||||
use mas_axum_utils::{cookies::CookieJar, FancyError};
|
use mas_axum_utils::{cookies::CookieJar, FancyError};
|
||||||
|
use mas_data_model::SiteConfig;
|
||||||
use mas_http::CorsLayerExt;
|
use mas_http::CorsLayerExt;
|
||||||
use mas_keystore::{Encrypter, Keystore};
|
use mas_keystore::{Encrypter, Keystore};
|
||||||
use mas_matrix::BoxHomeserverConnection;
|
use mas_matrix::BoxHomeserverConnection;
|
||||||
@@ -63,7 +64,6 @@ mod views;
|
|||||||
|
|
||||||
mod activity_tracker;
|
mod activity_tracker;
|
||||||
mod preferred_language;
|
mod preferred_language;
|
||||||
mod site_config;
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod test_utils;
|
mod test_utils;
|
||||||
|
|
||||||
@@ -91,7 +91,6 @@ pub use self::{
|
|||||||
activity_tracker::{ActivityTracker, Bound as BoundActivityTracker},
|
activity_tracker::{ActivityTracker, Bound as BoundActivityTracker},
|
||||||
graphql::schema as graphql_schema,
|
graphql::schema as graphql_schema,
|
||||||
preferred_language::PreferredLanguage,
|
preferred_language::PreferredLanguage,
|
||||||
site_config::{SiteConfig, SiteConfigExt},
|
|
||||||
upstream_oauth2::cache::MetadataCache,
|
upstream_oauth2::cache::MetadataCache,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@@ -22,7 +22,7 @@ use mas_axum_utils::{
|
|||||||
sentry::SentryEventID,
|
sentry::SentryEventID,
|
||||||
};
|
};
|
||||||
use mas_data_model::{
|
use mas_data_model::{
|
||||||
AuthorizationGrantStage, Client, Device, DeviceCodeGrantState, TokenType, UserAgent,
|
AuthorizationGrantStage, Client, Device, DeviceCodeGrantState, SiteConfig, TokenType, UserAgent,
|
||||||
};
|
};
|
||||||
use mas_keystore::{Encrypter, Keystore};
|
use mas_keystore::{Encrypter, Keystore};
|
||||||
use mas_oidc_client::types::scope::ScopeToken;
|
use mas_oidc_client::types::scope::ScopeToken;
|
||||||
@@ -54,7 +54,7 @@ use ulid::Ulid;
|
|||||||
use url::Url;
|
use url::Url;
|
||||||
|
|
||||||
use super::{generate_id_token, generate_token_pair};
|
use super::{generate_id_token, generate_token_pair};
|
||||||
use crate::{impl_from_error_for_route, site_config::SiteConfig, BoundActivityTracker};
|
use crate::{impl_from_error_for_route, BoundActivityTracker};
|
||||||
|
|
||||||
#[serde_as]
|
#[serde_as]
|
||||||
#[skip_serializing_none]
|
#[skip_serializing_none]
|
||||||
|
@@ -37,6 +37,7 @@ use mas_axum_utils::{
|
|||||||
http_client_factory::HttpClientFactory,
|
http_client_factory::HttpClientFactory,
|
||||||
ErrorWrapper,
|
ErrorWrapper,
|
||||||
};
|
};
|
||||||
|
use mas_data_model::SiteConfig;
|
||||||
use mas_i18n::Translator;
|
use mas_i18n::Translator;
|
||||||
use mas_keystore::{Encrypter, JsonWebKey, JsonWebKeySet, Keystore, PrivateKey};
|
use mas_keystore::{Encrypter, JsonWebKey, JsonWebKeySet, Keystore, PrivateKey};
|
||||||
use mas_matrix::{BoxHomeserverConnection, HomeserverConnection, MockHomeserverConnection};
|
use mas_matrix::{BoxHomeserverConnection, HomeserverConnection, MockHomeserverConnection};
|
||||||
@@ -44,7 +45,7 @@ use mas_policy::{InstantiateError, Policy, PolicyFactory};
|
|||||||
use mas_router::{SimpleRoute, UrlBuilder};
|
use mas_router::{SimpleRoute, UrlBuilder};
|
||||||
use mas_storage::{clock::MockClock, BoxClock, BoxRepository, BoxRng, Repository};
|
use mas_storage::{clock::MockClock, BoxClock, BoxRepository, BoxRng, Repository};
|
||||||
use mas_storage_pg::{DatabaseError, PgRepository};
|
use mas_storage_pg::{DatabaseError, PgRepository};
|
||||||
use mas_templates::Templates;
|
use mas_templates::{SiteConfigExt, Templates};
|
||||||
use rand::SeedableRng;
|
use rand::SeedableRng;
|
||||||
use rand_chacha::ChaChaRng;
|
use rand_chacha::ChaChaRng;
|
||||||
use serde::{de::DeserializeOwned, Serialize};
|
use serde::{de::DeserializeOwned, Serialize};
|
||||||
@@ -54,9 +55,8 @@ use url::Url;
|
|||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
passwords::{Hasher, PasswordManager},
|
passwords::{Hasher, PasswordManager},
|
||||||
site_config::SiteConfig,
|
|
||||||
upstream_oauth2::cache::MetadataCache,
|
upstream_oauth2::cache::MetadataCache,
|
||||||
ActivityTracker, BoundActivityTracker, SiteConfigExt,
|
ActivityTracker, BoundActivityTracker,
|
||||||
};
|
};
|
||||||
|
|
||||||
// This might fail if it's not the first time it's being called, which is fine,
|
// This might fail if it's not the first time it's being called, which is fine,
|
||||||
|
@@ -15,6 +15,7 @@
|
|||||||
//! Contexts used in templates
|
//! Contexts used in templates
|
||||||
|
|
||||||
mod branding;
|
mod branding;
|
||||||
|
mod ext;
|
||||||
mod features;
|
mod features;
|
||||||
|
|
||||||
use std::{
|
use std::{
|
||||||
@@ -40,7 +41,7 @@ use serde::{ser::SerializeStruct, Deserialize, Serialize};
|
|||||||
use ulid::Ulid;
|
use ulid::Ulid;
|
||||||
use url::Url;
|
use url::Url;
|
||||||
|
|
||||||
pub use self::{branding::SiteBranding, features::SiteFeatures};
|
pub use self::{branding::SiteBranding, ext::SiteConfigExt, features::SiteFeatures};
|
||||||
use crate::{FieldError, FormField, FormState};
|
use crate::{FieldError, FormField, FormState};
|
||||||
|
|
||||||
/// Helper trait to construct context wrappers
|
/// Helper trait to construct context wrappers
|
||||||
|
@@ -1,4 +1,4 @@
|
|||||||
// Copyright 2023, 2024 The Matrix.org Foundation C.I.C.
|
// Copyright 2024 The Matrix.org Foundation C.I.C.
|
||||||
//
|
//
|
||||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
// you may not use this file except in compliance with the License.
|
// you may not use this file except in compliance with the License.
|
||||||
@@ -12,12 +12,22 @@
|
|||||||
// See the License for the specific language governing permissions and
|
// See the License for the specific language governing permissions and
|
||||||
// limitations under the License.
|
// limitations under the License.
|
||||||
|
|
||||||
pub use mas_data_model::SiteConfig;
|
use mas_data_model::SiteConfig;
|
||||||
use mas_templates::{SiteBranding, SiteFeatures};
|
|
||||||
|
|
||||||
#[allow(clippy::module_name_repetitions)]
|
use super::{SiteBranding, SiteFeatures};
|
||||||
pub trait SiteConfigExt {
|
|
||||||
|
mod private {
|
||||||
|
pub trait Sealed {}
|
||||||
|
impl Sealed for mas_data_model::SiteConfig {}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Extension trait for [`SiteConfig`] to construct [`SiteBranding`] and
|
||||||
|
/// [`SiteFeatures`] from it.
|
||||||
|
pub trait SiteConfigExt: private::Sealed {
|
||||||
|
/// Construct a [`SiteBranding`] from the [`SiteConfig`].
|
||||||
fn templates_branding(&self) -> SiteBranding;
|
fn templates_branding(&self) -> SiteBranding;
|
||||||
|
|
||||||
|
/// Construct a [`SiteFeatures`] from the [`SiteConfig`].
|
||||||
fn templates_features(&self) -> SiteFeatures;
|
fn templates_features(&self) -> SiteFeatures;
|
||||||
}
|
}
|
||||||
|
|
@@ -47,8 +47,8 @@ pub use self::{
|
|||||||
EmailVerificationPageContext, EmptyContext, ErrorContext, FormPostContext, IndexContext,
|
EmailVerificationPageContext, EmptyContext, ErrorContext, FormPostContext, IndexContext,
|
||||||
LoginContext, LoginFormField, NotFoundContext, PolicyViolationContext, PostAuthContext,
|
LoginContext, LoginFormField, NotFoundContext, PolicyViolationContext, PostAuthContext,
|
||||||
PostAuthContextInner, ReauthContext, ReauthFormField, RegisterContext, RegisterFormField,
|
PostAuthContextInner, ReauthContext, ReauthFormField, RegisterContext, RegisterFormField,
|
||||||
SiteBranding, SiteFeatures, TemplateContext, UpstreamExistingLinkContext, UpstreamRegister,
|
SiteBranding, SiteConfigExt, SiteFeatures, TemplateContext, UpstreamExistingLinkContext,
|
||||||
UpstreamRegisterFormField, UpstreamSuggestLink, WithCsrf, WithLanguage,
|
UpstreamRegister, UpstreamRegisterFormField, UpstreamSuggestLink, WithCsrf, WithLanguage,
|
||||||
WithOptionalSession, WithSession,
|
WithOptionalSession, WithSession,
|
||||||
},
|
},
|
||||||
forms::{FieldError, FormError, FormField, FormState, ToFormState},
|
forms::{FieldError, FormError, FormField, FormState, ToFormState},
|
||||||
|
Reference in New Issue
Block a user