You've already forked authentication-service
mirror of
https://github.com/matrix-org/matrix-authentication-service.git
synced 2025-11-20 12:02:22 +03:00
Box the repository everywhere
This commit is contained in:
@@ -34,11 +34,10 @@ use mas_storage::{
|
||||
oauth2::OAuth2ClientRepository,
|
||||
upstream_oauth2::{UpstreamOAuthLinkRepository, UpstreamOAuthProviderRepository},
|
||||
user::{BrowserSessionRepository, UserEmailRepository},
|
||||
Pagination, Repository,
|
||||
BoxRepository, Pagination,
|
||||
};
|
||||
use mas_storage_pg::PgRepository;
|
||||
use model::CreationEvent;
|
||||
use sqlx::PgPool;
|
||||
use tokio::sync::Mutex;
|
||||
|
||||
use self::model::{
|
||||
BrowserSession, Cursor, Node, NodeCursor, NodeType, OAuth2Client, UpstreamOAuth2Link,
|
||||
@@ -94,7 +93,7 @@ impl RootQuery {
|
||||
id: ID,
|
||||
) -> Result<Option<OAuth2Client>, async_graphql::Error> {
|
||||
let id = NodeType::OAuth2Client.extract_ulid(&id)?;
|
||||
let mut repo = PgRepository::from_pool(ctx.data::<PgPool>()?).await?;
|
||||
let mut repo = ctx.data::<Mutex<BoxRepository>>()?.lock().await;
|
||||
|
||||
let client = repo.oauth2_client().lookup(id).await?;
|
||||
|
||||
@@ -124,7 +123,7 @@ impl RootQuery {
|
||||
) -> Result<Option<BrowserSession>, async_graphql::Error> {
|
||||
let id = NodeType::BrowserSession.extract_ulid(&id)?;
|
||||
let session = ctx.data_opt::<mas_data_model::BrowserSession>().cloned();
|
||||
let mut repo = PgRepository::from_pool(ctx.data::<PgPool>()?).await?;
|
||||
let mut repo = ctx.data::<Mutex<BoxRepository>>()?.lock().await;
|
||||
|
||||
let Some(session) = session else { return Ok(None) };
|
||||
let current_user = session.user;
|
||||
@@ -150,7 +149,7 @@ impl RootQuery {
|
||||
) -> Result<Option<UserEmail>, async_graphql::Error> {
|
||||
let id = NodeType::UserEmail.extract_ulid(&id)?;
|
||||
let session = ctx.data_opt::<mas_data_model::BrowserSession>().cloned();
|
||||
let mut repo = PgRepository::from_pool(ctx.data::<PgPool>()?).await?;
|
||||
let mut repo = ctx.data::<Mutex<BoxRepository>>()?.lock().await;
|
||||
|
||||
let Some(session) = session else { return Ok(None) };
|
||||
let current_user = session.user;
|
||||
@@ -172,7 +171,7 @@ impl RootQuery {
|
||||
) -> Result<Option<UpstreamOAuth2Link>, async_graphql::Error> {
|
||||
let id = NodeType::UpstreamOAuth2Link.extract_ulid(&id)?;
|
||||
let session = ctx.data_opt::<mas_data_model::BrowserSession>().cloned();
|
||||
let mut repo = PgRepository::from_pool(ctx.data::<PgPool>()?).await?;
|
||||
let mut repo = ctx.data::<Mutex<BoxRepository>>()?.lock().await;
|
||||
|
||||
let Some(session) = session else { return Ok(None) };
|
||||
let current_user = session.user;
|
||||
@@ -192,7 +191,7 @@ impl RootQuery {
|
||||
id: ID,
|
||||
) -> Result<Option<UpstreamOAuth2Provider>, async_graphql::Error> {
|
||||
let id = NodeType::UpstreamOAuth2Provider.extract_ulid(&id)?;
|
||||
let mut repo = PgRepository::from_pool(ctx.data::<PgPool>()?).await?;
|
||||
let mut repo = ctx.data::<Mutex<BoxRepository>>()?.lock().await;
|
||||
|
||||
let provider = repo.upstream_oauth_provider().lookup(id).await?;
|
||||
|
||||
@@ -211,7 +210,7 @@ impl RootQuery {
|
||||
#[graphql(desc = "Returns the first *n* elements from the list.")] first: Option<i32>,
|
||||
#[graphql(desc = "Returns the last *n* elements from the list.")] last: Option<i32>,
|
||||
) -> Result<Connection<Cursor, UpstreamOAuth2Provider>, async_graphql::Error> {
|
||||
let mut repo = PgRepository::from_pool(ctx.data::<PgPool>()?).await?;
|
||||
let mut repo = ctx.data::<Mutex<BoxRepository>>()?.lock().await;
|
||||
|
||||
query(
|
||||
after,
|
||||
|
||||
@@ -15,9 +15,8 @@
|
||||
use anyhow::Context as _;
|
||||
use async_graphql::{Context, Description, Object, ID};
|
||||
use chrono::{DateTime, Utc};
|
||||
use mas_storage::{compat::CompatSessionRepository, user::UserRepository, Repository};
|
||||
use mas_storage_pg::PgRepository;
|
||||
use sqlx::PgPool;
|
||||
use mas_storage::{compat::CompatSessionRepository, user::UserRepository, BoxRepository};
|
||||
use tokio::sync::Mutex;
|
||||
use url::Url;
|
||||
|
||||
use super::{NodeType, User};
|
||||
@@ -36,7 +35,7 @@ impl CompatSession {
|
||||
|
||||
/// The user authorized for this session.
|
||||
async fn user(&self, ctx: &Context<'_>) -> Result<User, async_graphql::Error> {
|
||||
let mut repo = PgRepository::from_pool(ctx.data::<PgPool>()?).await?;
|
||||
let mut repo = ctx.data::<Mutex<BoxRepository>>()?.lock().await;
|
||||
let user = repo
|
||||
.user()
|
||||
.lookup(self.0.user_id)
|
||||
@@ -101,7 +100,7 @@ impl CompatSsoLogin {
|
||||
) -> Result<Option<CompatSession>, async_graphql::Error> {
|
||||
let Some(session_id) = self.0.session_id() else { return Ok(None) };
|
||||
|
||||
let mut repo = PgRepository::from_pool(ctx.data::<PgPool>()?).await?;
|
||||
let mut repo = ctx.data::<Mutex<BoxRepository>>()?.lock().await;
|
||||
let session = repo
|
||||
.compat_session()
|
||||
.lookup(session_id)
|
||||
|
||||
@@ -14,10 +14,9 @@
|
||||
|
||||
use anyhow::Context as _;
|
||||
use async_graphql::{Context, Description, Object, ID};
|
||||
use mas_storage::{oauth2::OAuth2ClientRepository, user::BrowserSessionRepository, Repository};
|
||||
use mas_storage_pg::PgRepository;
|
||||
use mas_storage::{oauth2::OAuth2ClientRepository, user::BrowserSessionRepository, BoxRepository};
|
||||
use oauth2_types::scope::Scope;
|
||||
use sqlx::PgPool;
|
||||
use tokio::sync::Mutex;
|
||||
use ulid::Ulid;
|
||||
use url::Url;
|
||||
|
||||
@@ -37,7 +36,7 @@ impl OAuth2Session {
|
||||
|
||||
/// OAuth 2.0 client used by this session.
|
||||
pub async fn client(&self, ctx: &Context<'_>) -> Result<OAuth2Client, async_graphql::Error> {
|
||||
let mut repo = PgRepository::from_pool(ctx.data::<PgPool>()?).await?;
|
||||
let mut repo = ctx.data::<Mutex<BoxRepository>>()?.lock().await;
|
||||
let client = repo
|
||||
.oauth2_client()
|
||||
.lookup(self.0.client_id)
|
||||
@@ -57,7 +56,7 @@ impl OAuth2Session {
|
||||
&self,
|
||||
ctx: &Context<'_>,
|
||||
) -> Result<BrowserSession, async_graphql::Error> {
|
||||
let mut repo = PgRepository::from_pool(ctx.data::<PgPool>()?).await?;
|
||||
let mut repo = ctx.data::<Mutex<BoxRepository>>()?.lock().await;
|
||||
let browser_session = repo
|
||||
.browser_session()
|
||||
.lookup(self.0.user_session_id)
|
||||
@@ -69,7 +68,7 @@ impl OAuth2Session {
|
||||
|
||||
/// User authorized for this session.
|
||||
pub async fn user(&self, ctx: &Context<'_>) -> Result<User, async_graphql::Error> {
|
||||
let mut repo = PgRepository::from_pool(ctx.data::<PgPool>()?).await?;
|
||||
let mut repo = ctx.data::<Mutex<BoxRepository>>()?.lock().await;
|
||||
let browser_session = repo
|
||||
.browser_session()
|
||||
.lookup(self.0.user_session_id)
|
||||
@@ -139,7 +138,7 @@ impl OAuth2Consent {
|
||||
|
||||
/// OAuth 2.0 client for which the user granted access.
|
||||
pub async fn client(&self, ctx: &Context<'_>) -> Result<OAuth2Client, async_graphql::Error> {
|
||||
let mut repo = PgRepository::from_pool(ctx.data::<PgPool>()?).await?;
|
||||
let mut repo = ctx.data::<Mutex<BoxRepository>>()?.lock().await;
|
||||
let client = repo
|
||||
.oauth2_client()
|
||||
.lookup(self.client_id)
|
||||
|
||||
@@ -16,10 +16,9 @@ use anyhow::Context as _;
|
||||
use async_graphql::{Context, Object, ID};
|
||||
use chrono::{DateTime, Utc};
|
||||
use mas_storage::{
|
||||
upstream_oauth2::UpstreamOAuthProviderRepository, user::UserRepository, Repository,
|
||||
upstream_oauth2::UpstreamOAuthProviderRepository, user::UserRepository, BoxRepository,
|
||||
};
|
||||
use mas_storage_pg::PgRepository;
|
||||
use sqlx::PgPool;
|
||||
use tokio::sync::Mutex;
|
||||
|
||||
use super::{NodeType, User};
|
||||
|
||||
@@ -103,7 +102,7 @@ impl UpstreamOAuth2Link {
|
||||
provider.clone()
|
||||
} else {
|
||||
// Fetch on-the-fly
|
||||
let mut repo = PgRepository::from_pool(ctx.data::<PgPool>()?).await?;
|
||||
let mut repo = ctx.data::<Mutex<BoxRepository>>()?.lock().await;
|
||||
let provider = repo
|
||||
.upstream_oauth_provider()
|
||||
.lookup(self.link.provider_id)
|
||||
@@ -122,7 +121,7 @@ impl UpstreamOAuth2Link {
|
||||
user.clone()
|
||||
} else if let Some(user_id) = &self.link.user_id {
|
||||
// Fetch on-the-fly
|
||||
let mut repo = PgRepository::from_pool(ctx.data::<PgPool>()?).await?;
|
||||
let mut repo = ctx.data::<Mutex<BoxRepository>>()?.lock().await;
|
||||
let user = repo
|
||||
.user()
|
||||
.lookup(*user_id)
|
||||
|
||||
@@ -22,10 +22,9 @@ use mas_storage::{
|
||||
oauth2::OAuth2SessionRepository,
|
||||
upstream_oauth2::UpstreamOAuthLinkRepository,
|
||||
user::{BrowserSessionRepository, UserEmailRepository},
|
||||
Pagination, Repository,
|
||||
BoxRepository, Pagination,
|
||||
};
|
||||
use mas_storage_pg::PgRepository;
|
||||
use sqlx::PgPool;
|
||||
use tokio::sync::Mutex;
|
||||
|
||||
use super::{
|
||||
compat_sessions::CompatSsoLogin, BrowserSession, Cursor, NodeCursor, NodeType, OAuth2Session,
|
||||
@@ -65,10 +64,9 @@ impl User {
|
||||
&self,
|
||||
ctx: &Context<'_>,
|
||||
) -> Result<Option<UserEmail>, async_graphql::Error> {
|
||||
let mut repo = PgRepository::from_pool(ctx.data::<PgPool>()?).await?;
|
||||
let mut repo = ctx.data::<Mutex<BoxRepository>>()?.lock().await;
|
||||
|
||||
let mut user_email_repo = repo.user_email();
|
||||
|
||||
Ok(user_email_repo.get_primary(&self.0).await?.map(UserEmail))
|
||||
}
|
||||
|
||||
@@ -84,7 +82,7 @@ impl User {
|
||||
#[graphql(desc = "Returns the first *n* elements from the list.")] first: Option<i32>,
|
||||
#[graphql(desc = "Returns the last *n* elements from the list.")] last: Option<i32>,
|
||||
) -> Result<Connection<Cursor, CompatSsoLogin>, async_graphql::Error> {
|
||||
let mut repo = PgRepository::from_pool(ctx.data::<PgPool>()?).await?;
|
||||
let mut repo = ctx.data::<Mutex<BoxRepository>>()?.lock().await;
|
||||
|
||||
query(
|
||||
after,
|
||||
@@ -131,7 +129,7 @@ impl User {
|
||||
#[graphql(desc = "Returns the first *n* elements from the list.")] first: Option<i32>,
|
||||
#[graphql(desc = "Returns the last *n* elements from the list.")] last: Option<i32>,
|
||||
) -> Result<Connection<Cursor, BrowserSession>, async_graphql::Error> {
|
||||
let mut repo = PgRepository::from_pool(ctx.data::<PgPool>()?).await?;
|
||||
let mut repo = ctx.data::<Mutex<BoxRepository>>()?.lock().await;
|
||||
|
||||
query(
|
||||
after,
|
||||
@@ -178,7 +176,7 @@ impl User {
|
||||
#[graphql(desc = "Returns the first *n* elements from the list.")] first: Option<i32>,
|
||||
#[graphql(desc = "Returns the last *n* elements from the list.")] last: Option<i32>,
|
||||
) -> Result<Connection<Cursor, UserEmail, UserEmailsPagination>, async_graphql::Error> {
|
||||
let mut repo = PgRepository::from_pool(ctx.data::<PgPool>()?).await?;
|
||||
let mut repo = ctx.data::<Mutex<BoxRepository>>()?.lock().await;
|
||||
|
||||
query(
|
||||
after,
|
||||
@@ -229,7 +227,7 @@ impl User {
|
||||
#[graphql(desc = "Returns the first *n* elements from the list.")] first: Option<i32>,
|
||||
#[graphql(desc = "Returns the last *n* elements from the list.")] last: Option<i32>,
|
||||
) -> Result<Connection<Cursor, OAuth2Session>, async_graphql::Error> {
|
||||
let mut repo = PgRepository::from_pool(ctx.data::<PgPool>()?).await?;
|
||||
let mut repo = ctx.data::<Mutex<BoxRepository>>()?.lock().await;
|
||||
|
||||
query(
|
||||
after,
|
||||
@@ -276,7 +274,7 @@ impl User {
|
||||
#[graphql(desc = "Returns the first *n* elements from the list.")] first: Option<i32>,
|
||||
#[graphql(desc = "Returns the last *n* elements from the list.")] last: Option<i32>,
|
||||
) -> Result<Connection<Cursor, UpstreamOAuth2Link>, async_graphql::Error> {
|
||||
let mut repo = PgRepository::from_pool(ctx.data::<PgPool>()?).await?;
|
||||
let mut repo = ctx.data::<Mutex<BoxRepository>>()?.lock().await;
|
||||
|
||||
query(
|
||||
after,
|
||||
@@ -350,7 +348,7 @@ pub struct UserEmailsPagination(mas_data_model::User);
|
||||
impl UserEmailsPagination {
|
||||
/// Identifies the total count of items in the connection.
|
||||
async fn total_count(&self, ctx: &Context<'_>) -> Result<usize, async_graphql::Error> {
|
||||
let mut repo = PgRepository::from_pool(ctx.data::<PgPool>()?).await?;
|
||||
let mut repo = ctx.data::<Mutex<BoxRepository>>()?.lock().await;
|
||||
let count = repo.user_email().count(&self.0).await?;
|
||||
Ok(count)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user