You've already forked authentication-service
mirror of
https://github.com/matrix-org/matrix-authentication-service.git
synced 2025-07-31 09:24:31 +03:00
data-model: simplify users and sessions
This commit is contained in:
@ -114,7 +114,7 @@ impl RootQuery {
|
||||
let Some(session) = session else { return Ok(None) };
|
||||
let current_user = session.user;
|
||||
|
||||
if current_user.data == id {
|
||||
if current_user.id == id {
|
||||
Ok(Some(User(current_user)))
|
||||
} else {
|
||||
Ok(None)
|
||||
@ -141,7 +141,7 @@ impl RootQuery {
|
||||
.to_option()?;
|
||||
|
||||
let ret = browser_session.and_then(|browser_session| {
|
||||
if browser_session.user.data == current_user.data {
|
||||
if browser_session.user.id == current_user.id {
|
||||
Some(BrowserSession(browser_session))
|
||||
} else {
|
||||
None
|
||||
@ -193,7 +193,7 @@ impl RootQuery {
|
||||
.to_option()?;
|
||||
|
||||
// Ensure that the link belongs to the current user
|
||||
let link = link.filter(|link| link.user_id == Some(current_user.data));
|
||||
let link = link.filter(|link| link.user_id == Some(current_user.id));
|
||||
|
||||
Ok(link.map(UpstreamOAuth2Link::new))
|
||||
}
|
||||
|
@ -14,16 +14,15 @@
|
||||
|
||||
use async_graphql::{Description, Object, ID};
|
||||
use chrono::{DateTime, Utc};
|
||||
use mas_storage::PostgresqlBackend;
|
||||
|
||||
use super::{NodeType, User};
|
||||
|
||||
/// A browser session represents a logged in user in a browser.
|
||||
#[derive(Description)]
|
||||
pub struct BrowserSession(pub mas_data_model::BrowserSession<PostgresqlBackend>);
|
||||
pub struct BrowserSession(pub mas_data_model::BrowserSession);
|
||||
|
||||
impl From<mas_data_model::BrowserSession<PostgresqlBackend>> for BrowserSession {
|
||||
fn from(v: mas_data_model::BrowserSession<PostgresqlBackend>) -> Self {
|
||||
impl From<mas_data_model::BrowserSession> for BrowserSession {
|
||||
fn from(v: mas_data_model::BrowserSession) -> Self {
|
||||
Self(v)
|
||||
}
|
||||
}
|
||||
@ -32,7 +31,7 @@ impl From<mas_data_model::BrowserSession<PostgresqlBackend>> for BrowserSession
|
||||
impl BrowserSession {
|
||||
/// ID of the object.
|
||||
pub async fn id(&self) -> ID {
|
||||
NodeType::BrowserSession.id(self.0.data)
|
||||
NodeType::BrowserSession.id(self.0.id)
|
||||
}
|
||||
|
||||
/// The user logged in this session.
|
||||
@ -54,13 +53,13 @@ impl BrowserSession {
|
||||
/// An authentication records when a user enter their credential in a browser
|
||||
/// session.
|
||||
#[derive(Description)]
|
||||
pub struct Authentication(pub mas_data_model::Authentication<PostgresqlBackend>);
|
||||
pub struct Authentication(pub mas_data_model::Authentication);
|
||||
|
||||
#[Object(use_type_description)]
|
||||
impl Authentication {
|
||||
/// ID of the object.
|
||||
pub async fn id(&self) -> ID {
|
||||
NodeType::Authentication.id(self.0.data)
|
||||
NodeType::Authentication.id(self.0.id)
|
||||
}
|
||||
|
||||
/// When the object was created.
|
||||
|
@ -14,7 +14,6 @@
|
||||
|
||||
use async_graphql::{Context, Object, ID};
|
||||
use chrono::{DateTime, Utc};
|
||||
use mas_storage::PostgresqlBackend;
|
||||
use sqlx::PgPool;
|
||||
|
||||
use super::{NodeType, User};
|
||||
@ -69,7 +68,7 @@ impl UpstreamOAuth2Link {
|
||||
pub struct UpstreamOAuth2Link {
|
||||
link: mas_data_model::UpstreamOAuthLink,
|
||||
provider: Option<mas_data_model::UpstreamOAuthProvider>,
|
||||
user: Option<mas_data_model::User<PostgresqlBackend>>,
|
||||
user: Option<mas_data_model::User>,
|
||||
}
|
||||
|
||||
#[Object]
|
||||
|
@ -17,7 +17,6 @@ use async_graphql::{
|
||||
Context, Description, Object, ID,
|
||||
};
|
||||
use chrono::{DateTime, Utc};
|
||||
use mas_storage::PostgresqlBackend;
|
||||
use sqlx::PgPool;
|
||||
|
||||
use super::{
|
||||
@ -27,16 +26,16 @@ use super::{
|
||||
|
||||
#[derive(Description)]
|
||||
/// A user is an individual's account.
|
||||
pub struct User(pub mas_data_model::User<PostgresqlBackend>);
|
||||
pub struct User(pub mas_data_model::User);
|
||||
|
||||
impl From<mas_data_model::User<PostgresqlBackend>> for User {
|
||||
fn from(v: mas_data_model::User<PostgresqlBackend>) -> Self {
|
||||
impl From<mas_data_model::User> for User {
|
||||
fn from(v: mas_data_model::User) -> Self {
|
||||
Self(v)
|
||||
}
|
||||
}
|
||||
|
||||
impl From<mas_data_model::BrowserSession<PostgresqlBackend>> for User {
|
||||
fn from(v: mas_data_model::BrowserSession<PostgresqlBackend>) -> Self {
|
||||
impl From<mas_data_model::BrowserSession> for User {
|
||||
fn from(v: mas_data_model::BrowserSession) -> Self {
|
||||
Self(v.user)
|
||||
}
|
||||
}
|
||||
@ -45,7 +44,7 @@ impl From<mas_data_model::BrowserSession<PostgresqlBackend>> for User {
|
||||
impl User {
|
||||
/// ID of the object.
|
||||
pub async fn id(&self) -> ID {
|
||||
NodeType::User.id(self.0.data)
|
||||
NodeType::User.id(self.0.id)
|
||||
}
|
||||
|
||||
/// Username chosen by the user.
|
||||
@ -143,7 +142,7 @@ impl User {
|
||||
let mut connection = Connection::new(has_previous_page, has_next_page);
|
||||
connection.edges.extend(edges.into_iter().map(|u| {
|
||||
Edge::new(
|
||||
OpaqueCursor(NodeCursor(NodeType::BrowserSession, u.data)),
|
||||
OpaqueCursor(NodeCursor(NodeType::BrowserSession, u.id)),
|
||||
BrowserSession(u),
|
||||
)
|
||||
}));
|
||||
@ -195,7 +194,7 @@ impl User {
|
||||
);
|
||||
connection.edges.extend(edges.into_iter().map(|u| {
|
||||
Edge::new(
|
||||
OpaqueCursor(NodeCursor(NodeType::UserEmail, u.data)),
|
||||
OpaqueCursor(NodeCursor(NodeType::UserEmail, u.id)),
|
||||
UserEmail(u),
|
||||
)
|
||||
}));
|
||||
@ -309,13 +308,13 @@ impl User {
|
||||
|
||||
/// A user email address
|
||||
#[derive(Description)]
|
||||
pub struct UserEmail(pub mas_data_model::UserEmail<PostgresqlBackend>);
|
||||
pub struct UserEmail(pub mas_data_model::UserEmail);
|
||||
|
||||
#[Object(use_type_description)]
|
||||
impl UserEmail {
|
||||
/// ID of the object.
|
||||
pub async fn id(&self) -> ID {
|
||||
NodeType::UserEmail.id(self.0.data)
|
||||
NodeType::UserEmail.id(self.0.id)
|
||||
}
|
||||
|
||||
/// Email address
|
||||
@ -335,7 +334,7 @@ impl UserEmail {
|
||||
}
|
||||
}
|
||||
|
||||
pub struct UserEmailsPagination(mas_data_model::User<PostgresqlBackend>);
|
||||
pub struct UserEmailsPagination(mas_data_model::User);
|
||||
|
||||
#[Object]
|
||||
impl UserEmailsPagination {
|
||||
|
Reference in New Issue
Block a user