Skip to main content

mas_storage/user/
terms.rs

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