You've already forked authentication-service
mirror of
https://github.com/matrix-org/matrix-authentication-service.git
synced 2025-07-29 22:01:14 +03:00
WIP: use sea-query for dynamic paginated queries
This commit is contained in:
@ -12,7 +12,7 @@
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
use async_graphql::{Description, Object, ID};
|
||||
use async_graphql::{Description, Enum, Object, ID};
|
||||
use chrono::{DateTime, Utc};
|
||||
|
||||
use super::{NodeType, User};
|
||||
@ -21,6 +21,16 @@ use super::{NodeType, User};
|
||||
#[derive(Description)]
|
||||
pub struct BrowserSession(pub mas_data_model::BrowserSession);
|
||||
|
||||
/// The state of a browser session.
|
||||
#[derive(Enum, Copy, Clone, Eq, PartialEq)]
|
||||
pub enum BrowserSessionState {
|
||||
/// The session is active.
|
||||
Active,
|
||||
|
||||
/// The session is no longer active.
|
||||
Finished,
|
||||
}
|
||||
|
||||
impl From<mas_data_model::BrowserSession> for BrowserSession {
|
||||
fn from(v: mas_data_model::BrowserSession) -> Self {
|
||||
Self(v)
|
||||
|
@ -21,7 +21,7 @@ use mas_storage::{
|
||||
compat::CompatSsoLoginRepository,
|
||||
oauth2::OAuth2SessionRepository,
|
||||
upstream_oauth2::UpstreamOAuthLinkRepository,
|
||||
user::{BrowserSessionRepository, UserEmailRepository},
|
||||
user::{BrowserSessionFilter, BrowserSessionRepository, UserEmailRepository},
|
||||
Pagination, RepositoryAccess,
|
||||
};
|
||||
|
||||
@ -30,7 +30,7 @@ use super::{
|
||||
UpstreamOAuth2Link,
|
||||
};
|
||||
use crate::{
|
||||
model::{matrix::MatrixUser, CompatSession},
|
||||
model::{browser_sessions::BrowserSessionState, matrix::MatrixUser, CompatSession},
|
||||
state::ContextExt,
|
||||
};
|
||||
|
||||
@ -189,6 +189,9 @@ impl User {
|
||||
&self,
|
||||
ctx: &Context<'_>,
|
||||
|
||||
#[graphql(name = "state", desc = "List only sessions in the given state.")]
|
||||
state_param: Option<BrowserSessionState>,
|
||||
|
||||
#[graphql(desc = "Returns the elements in the list that come after the cursor.")]
|
||||
after: Option<String>,
|
||||
#[graphql(desc = "Returns the elements in the list that come before the cursor.")]
|
||||
@ -213,10 +216,14 @@ impl User {
|
||||
.transpose()?;
|
||||
let pagination = Pagination::try_new(before_id, after_id, first, last)?;
|
||||
|
||||
let page = repo
|
||||
.browser_session()
|
||||
.list_active_paginated(&self.0, pagination)
|
||||
.await?;
|
||||
let filter = BrowserSessionFilter::new().for_user(&self.0);
|
||||
let filter = match state_param {
|
||||
Some(BrowserSessionState::Active) => filter.active_only(),
|
||||
Some(BrowserSessionState::Finished) => filter.finished_only(),
|
||||
None => filter,
|
||||
};
|
||||
|
||||
let page = repo.browser_session().list(filter, pagination).await?;
|
||||
|
||||
repo.cancel().await?;
|
||||
|
||||
|
Reference in New Issue
Block a user