Skip to content
This repository has been archived by the owner on Sep 10, 2024. It is now read-only.

Replace Jotai with @tanstack/router #2359

Merged
merged 5 commits into from
Feb 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
70 changes: 65 additions & 5 deletions crates/graphql/src/query/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,10 @@
use mas_storage::user::UserRepository;

use crate::{
model::{Anonymous, BrowserSession, Node, NodeType, OAuth2Client, User, UserEmail},
model::{
Anonymous, BrowserSession, CompatSession, Node, NodeType, OAuth2Client, OAuth2Session,
User, UserEmail,
},
state::ContextExt,
UserId,
};
Expand Down Expand Up @@ -149,6 +152,56 @@
Ok(Some(BrowserSession(browser_session)))
}

/// Fetch a compatible session by its ID.
async fn compat_session(
&self,
ctx: &Context<'_>,
id: ID,
) -> Result<Option<CompatSession>, async_graphql::Error> {
let state = ctx.state();
let id = NodeType::CompatSession.extract_ulid(&id)?;
let requester = ctx.requester();

Check warning on line 163 in crates/graphql/src/query/mod.rs

View check run for this annotation

Codecov / codecov/patch

crates/graphql/src/query/mod.rs#L156-L163

Added lines #L156 - L163 were not covered by tests

let mut repo = state.repository().await?;
let compat_session = repo.compat_session().lookup(id).await?;
repo.cancel().await?;

Check warning on line 167 in crates/graphql/src/query/mod.rs

View check run for this annotation

Codecov / codecov/patch

crates/graphql/src/query/mod.rs#L165-L167

Added lines #L165 - L167 were not covered by tests

let Some(compat_session) = compat_session else {
return Ok(None);

Check warning on line 170 in crates/graphql/src/query/mod.rs

View check run for this annotation

Codecov / codecov/patch

crates/graphql/src/query/mod.rs#L169-L170

Added lines #L169 - L170 were not covered by tests
};

if !requester.is_owner_or_admin(&compat_session) {
return Ok(None);
}

Ok(Some(CompatSession::new(compat_session)))
}

Check warning on line 178 in crates/graphql/src/query/mod.rs

View check run for this annotation

Codecov / codecov/patch

crates/graphql/src/query/mod.rs#L173-L178

Added lines #L173 - L178 were not covered by tests

/// Fetch an OAuth 2.0 session by its ID.
async fn oauth2_session(
&self,
ctx: &Context<'_>,
id: ID,
) -> Result<Option<OAuth2Session>, async_graphql::Error> {
let state = ctx.state();
let id = NodeType::OAuth2Session.extract_ulid(&id)?;
let requester = ctx.requester();

Check warning on line 188 in crates/graphql/src/query/mod.rs

View check run for this annotation

Codecov / codecov/patch

crates/graphql/src/query/mod.rs#L181-L188

Added lines #L181 - L188 were not covered by tests

let mut repo = state.repository().await?;
let oauth2_session = repo.oauth2_session().lookup(id).await?;
repo.cancel().await?;

Check warning on line 192 in crates/graphql/src/query/mod.rs

View check run for this annotation

Codecov / codecov/patch

crates/graphql/src/query/mod.rs#L190-L192

Added lines #L190 - L192 were not covered by tests

let Some(oauth2_session) = oauth2_session else {
return Ok(None);

Check warning on line 195 in crates/graphql/src/query/mod.rs

View check run for this annotation

Codecov / codecov/patch

crates/graphql/src/query/mod.rs#L194-L195

Added lines #L194 - L195 were not covered by tests
};

if !requester.is_owner_or_admin(&oauth2_session) {
return Ok(None);
}

Ok(Some(OAuth2Session(oauth2_session)))
}

Check warning on line 203 in crates/graphql/src/query/mod.rs

View check run for this annotation

Codecov / codecov/patch

crates/graphql/src/query/mod.rs#L198-L203

Added lines #L198 - L203 were not covered by tests

/// Fetch a user email by its ID.
async fn user_email(
&self,
Expand Down Expand Up @@ -185,10 +238,7 @@

let ret = match node_type {
// TODO
NodeType::Authentication
| NodeType::CompatSession
| NodeType::CompatSsoLogin
| NodeType::OAuth2Session => None,
NodeType::Authentication | NodeType::CompatSsoLogin => None,

Check warning on line 241 in crates/graphql/src/query/mod.rs

View check run for this annotation

Codecov / codecov/patch

crates/graphql/src/query/mod.rs#L241

Added line #L241 was not covered by tests

NodeType::UpstreamOAuth2Provider => UpstreamOAuthQuery
.upstream_oauth2_provider(ctx, id)
Expand All @@ -210,6 +260,16 @@
.await?
.map(|e| Node::UserEmail(Box::new(e))),

NodeType::CompatSession => self
.compat_session(ctx, id)
.await?
.map(|s| Node::CompatSession(Box::new(s))),

Check warning on line 266 in crates/graphql/src/query/mod.rs

View check run for this annotation

Codecov / codecov/patch

crates/graphql/src/query/mod.rs#L263-L266

Added lines #L263 - L266 were not covered by tests

NodeType::OAuth2Session => self
.oauth2_session(ctx, id)
.await?
.map(|s| Node::OAuth2Session(Box::new(s))),

Check warning on line 271 in crates/graphql/src/query/mod.rs

View check run for this annotation

Codecov / codecov/patch

crates/graphql/src/query/mod.rs#L268-L271

Added lines #L268 - L271 were not covered by tests

NodeType::BrowserSession => self
.browser_session(ctx, id)
.await?
Expand Down
2 changes: 1 addition & 1 deletion crates/handlers/src/oauth2/discovery.rs
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ pub(crate) async fn get(
graphql_endpoint: url_builder.graphql_endpoint(),
account_management_uri: url_builder.account_management_uri(),
// This needs to be kept in sync with what is supported in the frontend,
// see frontend/src/routing/actions.ts
// see frontend/src/routes/__root.tsx
account_management_actions_supported: vec![
"org.matrix.profile".to_owned(),
"org.matrix.sessions_list".to_owned(),
Expand Down
14 changes: 7 additions & 7 deletions frontend/locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,12 @@
"confirmation_modal_title": "Are you sure you want to end this session?",
"text": "End session"
},
"error_boundary_title": "Something went wrong",
"error": {
"hideDetails": "Hide details",
"showDetails": "Show details",
"subtitle": "An unexpected error occurred. Please try again.",
"title": "Something went wrong"
},
"last_active": {
"active_date": "Active {{relativeDate}}",
"active_now": "Active now",
Expand Down Expand Up @@ -132,7 +137,6 @@
"title": "Cannot find session: {{deviceId}}"
}
},
"unknown_route": "Unknown route {{route}}",
"unverified_email_alert": {
"button": "Review and verify",
"text:one": "You have {{count}} unverified email address.",
Expand All @@ -154,9 +158,6 @@
"heading": "Emails",
"no_primary_email_alert": "No primary email address"
},
"user_greeting": {
"error": "Failed to load user"
},
"user_name": {
"display_name_field_label": "Display Name"
},
Expand All @@ -177,8 +178,7 @@
"description": "Check the code sent to your email and update the fields below to continue.",
"title": "You entered the wrong code"
},
"resend_code": "Resend code",
"unknown_email": "Unknown email"
"resend_code": "Resend code"
}
}
}
Loading
Loading