You've already forked authentication-service
mirror of
https://github.com/matrix-org/matrix-authentication-service.git
synced 2025-08-06 06:02:40 +03:00
Use dynamic filters on upstream OAuth 2.0 providers
This commit is contained in:
@@ -34,5 +34,5 @@
|
||||
false
|
||||
]
|
||||
},
|
||||
"hash": "94fd87e99088671b6a20bb7b9a3838ecce8df564257b348adf22f2e9356e6dae"
|
||||
"hash": "9aa8fa3a6277f67b2bf5a5ea5429a61e7997ff4f3e8d0dc772448a1f97e1e390"
|
||||
}
|
@@ -31,8 +31,11 @@ use ulid::Ulid;
|
||||
use uuid::Uuid;
|
||||
|
||||
use crate::{
|
||||
iden::UpstreamOAuthProviders, pagination::QueryBuilderExt, tracing::ExecuteExt, DatabaseError,
|
||||
DatabaseInconsistencyError,
|
||||
filter::{Filter, StatementExt},
|
||||
iden::UpstreamOAuthProviders,
|
||||
pagination::QueryBuilderExt,
|
||||
tracing::ExecuteExt,
|
||||
DatabaseError, DatabaseInconsistencyError,
|
||||
};
|
||||
|
||||
/// An implementation of [`UpstreamOAuthProviderRepository`] for a PostgreSQL
|
||||
@@ -174,6 +177,19 @@ impl TryFrom<ProviderLookup> for UpstreamOAuthProvider {
|
||||
}
|
||||
}
|
||||
|
||||
impl Filter for UpstreamOAuthProviderFilter<'_> {
|
||||
fn generate_condition(&self, _has_joins: bool) -> impl sea_query::IntoCondition {
|
||||
sea_query::Condition::all().add_option(self.enabled().map(|enabled| {
|
||||
Expr::col((
|
||||
UpstreamOAuthProviders::Table,
|
||||
UpstreamOAuthProviders::DisabledAt,
|
||||
))
|
||||
.is_null()
|
||||
.eq(enabled)
|
||||
}))
|
||||
}
|
||||
}
|
||||
|
||||
#[async_trait]
|
||||
impl<'c> UpstreamOAuthProviderRepository for PgUpstreamOAuthProviderRepository<'c> {
|
||||
type Error = DatabaseError;
|
||||
@@ -676,14 +692,7 @@ impl<'c> UpstreamOAuthProviderRepository for PgUpstreamOAuthProviderRepository<'
|
||||
ProviderLookupIden::AdditionalParameters,
|
||||
)
|
||||
.from(UpstreamOAuthProviders::Table)
|
||||
.and_where_option(filter.enabled().map(|enabled| {
|
||||
Expr::col((
|
||||
UpstreamOAuthProviders::Table,
|
||||
UpstreamOAuthProviders::DisabledAt,
|
||||
))
|
||||
.is_null()
|
||||
.eq(enabled)
|
||||
}))
|
||||
.apply_filter(filter)
|
||||
.generate_pagination(
|
||||
(
|
||||
UpstreamOAuthProviders::Table,
|
||||
@@ -726,14 +735,7 @@ impl<'c> UpstreamOAuthProviderRepository for PgUpstreamOAuthProviderRepository<'
|
||||
.count(),
|
||||
)
|
||||
.from(UpstreamOAuthProviders::Table)
|
||||
.and_where_option(filter.enabled().map(|enabled| {
|
||||
Expr::col((
|
||||
UpstreamOAuthProviders::Table,
|
||||
UpstreamOAuthProviders::DisabledAt,
|
||||
))
|
||||
.is_null()
|
||||
.eq(enabled)
|
||||
}))
|
||||
.apply_filter(filter)
|
||||
.build_sqlx(PostgresQueryBuilder);
|
||||
|
||||
let count: i64 = sqlx::query_scalar_with(&sql, arguments)
|
||||
|
Reference in New Issue
Block a user