You've already forked authentication-service
mirror of
https://github.com/matrix-org/matrix-authentication-service.git
synced 2025-08-07 17:03:01 +03:00
storage: add a filter by last active time on OAuth 2.0 sessions
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
// Copyright 2022, 2023 The Matrix.org Foundation C.I.C.
|
||||
// Copyright 2022-2024 The Matrix.org Foundation C.I.C.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
@@ -133,6 +133,14 @@ impl Filter for OAuth2SessionFilter<'_> {
|
||||
let scope: Vec<String> = scope.iter().map(|s| s.as_str().to_owned()).collect();
|
||||
Expr::col((OAuth2Sessions::Table, OAuth2Sessions::ScopeList)).contains(scope)
|
||||
}))
|
||||
.add_option(self.last_active_after().map(|last_active_after| {
|
||||
Expr::col((OAuth2Sessions::Table, OAuth2Sessions::LastActiveAt))
|
||||
.gt(last_active_after)
|
||||
}))
|
||||
.add_option(self.last_active_before().map(|last_active_before| {
|
||||
Expr::col((OAuth2Sessions::Table, OAuth2Sessions::LastActiveAt))
|
||||
.lt(last_active_before)
|
||||
}))
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -48,6 +48,8 @@ pub struct OAuth2SessionFilter<'a> {
|
||||
client: Option<&'a Client>,
|
||||
state: Option<OAuth2SessionState>,
|
||||
scope: Option<&'a Scope>,
|
||||
last_active_before: Option<DateTime<Utc>>,
|
||||
last_active_after: Option<DateTime<Utc>>,
|
||||
}
|
||||
|
||||
impl<'a> OAuth2SessionFilter<'a> {
|
||||
@@ -102,6 +104,36 @@ impl<'a> OAuth2SessionFilter<'a> {
|
||||
self.client
|
||||
}
|
||||
|
||||
/// Only return sessions with a last active time before the given time
|
||||
#[must_use]
|
||||
pub fn with_last_active_before(mut self, last_active_before: DateTime<Utc>) -> Self {
|
||||
self.last_active_before = Some(last_active_before);
|
||||
self
|
||||
}
|
||||
|
||||
/// Only return sessions with a last active time after the given time
|
||||
#[must_use]
|
||||
pub fn with_last_active_after(mut self, last_active_after: DateTime<Utc>) -> Self {
|
||||
self.last_active_after = Some(last_active_after);
|
||||
self
|
||||
}
|
||||
|
||||
/// Get the last active before filter
|
||||
///
|
||||
/// Returns [`None`] if no client filter was set
|
||||
#[must_use]
|
||||
pub fn last_active_before(&self) -> Option<DateTime<Utc>> {
|
||||
self.last_active_before
|
||||
}
|
||||
|
||||
/// Get the last active after filter
|
||||
///
|
||||
/// Returns [`None`] if no client filter was set
|
||||
#[must_use]
|
||||
pub fn last_active_after(&self) -> Option<DateTime<Utc>> {
|
||||
self.last_active_after
|
||||
}
|
||||
|
||||
/// Only return active sessions
|
||||
#[must_use]
|
||||
pub fn active_only(mut self) -> Self {
|
||||
|
Reference in New Issue
Block a user