torrust_index/services/
about.rs

1//! Templates for "about" static pages.
2
3use std::sync::Arc;
4
5use super::authorization::{self, ACTION};
6use crate::errors::ServiceError;
7use crate::models::user::UserId;
8
9pub struct Service {
10    authorization_service: Arc<authorization::Service>,
11}
12
13impl Service {
14    #[must_use]
15    pub fn new(authorization_service: Arc<authorization::Service>) -> Service {
16        Service { authorization_service }
17    }
18
19    /// Returns the html with the about page
20    ///
21    /// # Errors
22    ///
23    /// It returns an error if:
24    ///
25    /// * The user does not have the required permissions.
26    /// * There is an error authorizing the action.
27    pub async fn get_about_page(&self, maybe_user_id: Option<UserId>) -> Result<String, ServiceError> {
28        self.authorization_service
29            .authorize(ACTION::GetAboutPage, maybe_user_id)
30            .await?;
31
32        let html = r#"
33    <html>
34        <head>
35            <title>About</title>
36        </head>
37        <body style="margin-left: auto;margin-right: auto;max-width: 30em;">
38            <h1>Torrust Index</h1>
39
40            <h2>About</h2>
41
42            <p>Hi! This is a running <a href="https://github.com/torrust/torrust-index">torrust-index</a>.</p>
43        </body>
44        <footer style="padding: 1.25em 0;border-top: dotted 1px;">
45            <a href="./about/license">license</a>
46        </footer>
47    </html>
48"#;
49
50        Ok(html.to_string())
51    }
52
53    /// Returns the html with the license page
54    ///
55    /// # Errors
56    ///
57    /// It returns an error if:
58    ///
59    /// * The user does not have the required permissions.
60    /// * There is an error authorizing the action.
61    pub async fn get_license_page(&self, maybe_user_id: Option<UserId>) -> Result<String, ServiceError> {
62        self.authorization_service
63            .authorize(ACTION::GetLicensePage, maybe_user_id)
64            .await?;
65
66        let html = r#"
67        <html>
68            <head>
69                <title>Licensing</title>
70            </head>
71            <body style="margin-left: auto;margin-right: auto;max-width: 30em;">
72                <h1>Torrust Index</h1>
73    
74                <h2>Licensing</h2>
75    
76                <h3>Multiple Licenses</h3>
77    
78                <p>This repository has multiple licenses depending on the content type, the date of contributions or stemming from external component licenses that were not developed by any of Torrust team members or Torrust repository contributors.</p>
79    
80                <p>The two main applicable license to most of its content are:</p>
81    
82                <p>- For Code -- <a href="https://github.com/torrust/torrust-index/blob/main/licensing/agpl-3.0.md">agpl-3.0</a></p>
83    
84                <p>- For Media (Images, etc.) -- <a href="https://github.com/torrust/torrust-index/blob/main/licensing/cc-by-sa.md">cc-by-sa</a></p>
85    
86                <p>If you want to read more about all the licenses and how they apply please refer to the <a href="https://github.com/torrust/torrust-index/blob/develop/licensing/contributor_agreement_v01.md">contributor agreement</a>.</p>
87            </body>
88            <footer style="padding: 1.25em 0;border-top: dotted 1px;">
89                <a href="../about">about</a>
90            </footer>
91        </html>
92    "#;
93
94        Ok(html.to_string())
95    }
96}