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
Setup a repository to track user terms agreements
This commit is contained in:
@ -30,7 +30,10 @@ use crate::{
|
||||
UpstreamOAuthLinkRepository, UpstreamOAuthProviderRepository,
|
||||
UpstreamOAuthSessionRepository,
|
||||
},
|
||||
user::{BrowserSessionRepository, UserEmailRepository, UserPasswordRepository, UserRepository},
|
||||
user::{
|
||||
BrowserSessionRepository, UserEmailRepository, UserPasswordRepository, UserRepository,
|
||||
UserTermsRepository,
|
||||
},
|
||||
MapErr,
|
||||
};
|
||||
|
||||
@ -146,6 +149,9 @@ pub trait RepositoryAccess: Send {
|
||||
fn user_password<'c>(&'c mut self)
|
||||
-> Box<dyn UserPasswordRepository<Error = Self::Error> + 'c>;
|
||||
|
||||
/// Get an [`UserTermsRepository`]
|
||||
fn user_terms<'c>(&'c mut self) -> Box<dyn UserTermsRepository<Error = Self::Error> + 'c>;
|
||||
|
||||
/// Get a [`BrowserSessionRepository`]
|
||||
fn browser_session<'c>(
|
||||
&'c mut self,
|
||||
@ -231,6 +237,7 @@ mod impls {
|
||||
},
|
||||
user::{
|
||||
BrowserSessionRepository, UserEmailRepository, UserPasswordRepository, UserRepository,
|
||||
UserTermsRepository,
|
||||
},
|
||||
MapErr, Repository, RepositoryTransaction,
|
||||
};
|
||||
@ -315,6 +322,10 @@ mod impls {
|
||||
Box::new(MapErr::new(self.inner.user_password(), &mut self.mapper))
|
||||
}
|
||||
|
||||
fn user_terms<'c>(&'c mut self) -> Box<dyn UserTermsRepository<Error = Self::Error> + 'c> {
|
||||
Box::new(MapErr::new(self.inner.user_terms(), &mut self.mapper))
|
||||
}
|
||||
|
||||
fn browser_session<'c>(
|
||||
&'c mut self,
|
||||
) -> Box<dyn BrowserSessionRepository<Error = Self::Error> + 'c> {
|
||||
@ -445,6 +456,10 @@ mod impls {
|
||||
(**self).user_password()
|
||||
}
|
||||
|
||||
fn user_terms<'c>(&'c mut self) -> Box<dyn UserTermsRepository<Error = Self::Error> + 'c> {
|
||||
(**self).user_terms()
|
||||
}
|
||||
|
||||
fn browser_session<'c>(
|
||||
&'c mut self,
|
||||
) -> Box<dyn BrowserSessionRepository<Error = Self::Error> + 'c> {
|
||||
|
@ -24,11 +24,13 @@ use crate::{repository_impl, Clock};
|
||||
mod email;
|
||||
mod password;
|
||||
mod session;
|
||||
mod terms;
|
||||
|
||||
pub use self::{
|
||||
email::{UserEmailFilter, UserEmailRepository},
|
||||
password::UserPasswordRepository,
|
||||
session::{BrowserSessionFilter, BrowserSessionRepository},
|
||||
terms::UserTermsRepository,
|
||||
};
|
||||
|
||||
/// A [`UserRepository`] helps interacting with [`User`] saved in the storage
|
||||
|
57
crates/storage/src/user/terms.rs
Normal file
57
crates/storage/src/user/terms.rs
Normal file
@ -0,0 +1,57 @@
|
||||
// Copyright 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.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
use async_trait::async_trait;
|
||||
use mas_data_model::User;
|
||||
use rand_core::RngCore;
|
||||
use url::Url;
|
||||
|
||||
use crate::{repository_impl, Clock};
|
||||
|
||||
/// A [`UserTermsRepository`] helps interacting with the terms of service agreed by a [`User`]
|
||||
#[async_trait]
|
||||
pub trait UserTermsRepository: Send + Sync {
|
||||
/// The error type returned by the repository
|
||||
type Error;
|
||||
|
||||
/// Accept the terms of service by a [`User`]
|
||||
///
|
||||
/// # Parameters
|
||||
///
|
||||
/// * `rng`: A random number generator used to generate IDs
|
||||
/// * `clock`: The clock used to generate timestamps
|
||||
/// * `user`: The [`User`] accepting the terms
|
||||
/// * `terms_url`: The URL of the terms of service the user is accepting
|
||||
///
|
||||
/// # Errors
|
||||
///
|
||||
/// Returns [`Self::Error`] if the underlying repository fails
|
||||
async fn accept_terms(
|
||||
&mut self,
|
||||
rng: &mut (dyn RngCore + Send),
|
||||
clock: &dyn Clock,
|
||||
user: &User,
|
||||
terms_url: Url,
|
||||
) -> Result<(), Self::Error>;
|
||||
}
|
||||
|
||||
repository_impl!(UserTermsRepository:
|
||||
async fn accept_terms(
|
||||
&mut self,
|
||||
rng: &mut (dyn RngCore + Send),
|
||||
clock: &dyn Clock,
|
||||
user: &User,
|
||||
terms_url: Url,
|
||||
) -> Result<(), Self::Error>;
|
||||
);
|
Reference in New Issue
Block a user