mas_storage/user/terms.rs
1// Copyright 2024 New Vector Ltd.
2// Copyright 2024 The Matrix.org Foundation C.I.C.
3//
4// SPDX-License-Identifier: AGPL-3.0-only
5// Please see LICENSE in the repository root for full details.
6
7use async_trait::async_trait;
8use mas_data_model::User;
9use rand_core::RngCore;
10use url::Url;
11
12use crate::{Clock, repository_impl};
13
14/// A [`UserTermsRepository`] helps interacting with the terms of service agreed
15/// by a [`User`]
16#[async_trait]
17pub trait UserTermsRepository: Send + Sync {
18 /// The error type returned by the repository
19 type Error;
20
21 /// Accept the terms of service by a [`User`]
22 ///
23 /// # Parameters
24 ///
25 /// * `rng`: A random number generator used to generate IDs
26 /// * `clock`: The clock used to generate timestamps
27 /// * `user`: The [`User`] accepting the terms
28 /// * `terms_url`: The URL of the terms of service the user is accepting
29 ///
30 /// # Errors
31 ///
32 /// Returns [`Self::Error`] if the underlying repository fails
33 async fn accept_terms(
34 &mut self,
35 rng: &mut (dyn RngCore + Send),
36 clock: &dyn Clock,
37 user: &User,
38 terms_url: Url,
39 ) -> Result<(), Self::Error>;
40}
41
42repository_impl!(UserTermsRepository:
43 async fn accept_terms(
44 &mut self,
45 rng: &mut (dyn RngCore + Send),
46 clock: &dyn Clock,
47 user: &User,
48 terms_url: Url,
49 ) -> Result<(), Self::Error>;
50);