Skip to content

Commit 7ebf95c

Browse files
committed
Merge #734: Release Version 3.0.0-rc.1
867a1f5 release: version 3.0.0-rc.1 (Jose Celano) cdf2fe3 fix: chedck error (Jose Celano) 5e0226d chore(deps): update dependencies (Jose Celano) 7d82eb2 feat: [#730] add CMS content to configration (Jose Celano) 0f3d122 chore(deps): update dependencies (Jose Celano) 69a463a chore(deps): udpate dependencies (Jose Celano) 8246f07 feat: min and max password length should be also valid (Jose Celano) 2e67cc1 fix: [#613] wrong error message for password too long error (Jose Celano) bc28ac7 develop: bump to version 3.0.0-rc.1-develop (Jose Celano) Pull request description: Release Version 3.0.0-rc.1 ACKs for top commit: josecelano: ACK 867a1f5 Tree-SHA512: f304ae58451017faf56b285562bb445894637a43fb64bf6ec8f61cbd9fb34e28faa59b9023f4e0cff0d38c373383e0fb6222a534ac02fecda81c54f72560f383
2 parents f092feb + 867a1f5 commit 7ebf95c

File tree

10 files changed

+838
-322
lines changed

10 files changed

+838
-322
lines changed

Cargo.lock

+471-242
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

+2-2
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ license = "AGPL-3.0-only"
2727
publish = true
2828
repository = "https://github.com/torrust/torrust-tracker"
2929
rust-version = "1.72"
30-
version = "3.0.0-beta"
30+
version = "3.0.0-rc.1"
3131

3232
[profile.dev.package.sqlx-macros]
3333
opt-level = 3
@@ -89,7 +89,7 @@ text-to-png = "0"
8989
thiserror = "1"
9090
tokio = { version = "1", features = ["fs", "io-util", "macros", "net", "rt-multi-thread", "signal", "sync", "time"] }
9191
toml = "0"
92-
torrust-index-located-error = { version = "3.0.0-beta", path = "packages/located-error" }
92+
torrust-index-located-error = { version = "3.0.0-rc.1", path = "packages/located-error" }
9393
tower = { version = "0.4", features = ["timeout"] }
9494
tower-http = { version = "0", features = ["compression-full", "cors", "propagate-header", "request-id", "trace"] }
9595
trace = "0.1.7"

share/default/config/index.development.sqlite3.toml

+2
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ app = "torrust-index"
33
purpose = "configuration"
44
schema_version = "2.0.0"
55

6+
[website.demo]
7+
68
[logging]
79
#threshold = "off"
810
#threshold = "error"

src/config/mod.rs

+42-73
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,11 @@ pub type Logging = v2::logging::Logging;
4747
pub type Threshold = v2::logging::Threshold;
4848

4949
pub type Website = v2::website::Website;
50+
pub type Demo = v2::website::Demo;
51+
pub type Terms = v2::website::Terms;
52+
pub type TermsPage = v2::website::TermsPage;
53+
pub type TermsUpload = v2::website::TermsUpload;
54+
pub type Markdown = v2::website::Markdown;
5055

5156
/// Configuration version
5257
const VERSION_2: &str = "2.0.0";
@@ -193,6 +198,14 @@ impl Info {
193198
config_toml_path,
194199
})
195200
}
201+
202+
#[must_use]
203+
pub fn from_toml(config_toml: &str) -> Self {
204+
Self {
205+
config_toml: Some(config_toml.to_owned()),
206+
config_toml_path: String::new(),
207+
}
208+
}
196209
}
197210

198211
/// Errors that can occur when loading the configuration.
@@ -385,88 +398,44 @@ mod tests {
385398

386399
#[cfg(test)]
387400
fn default_config_toml() -> String {
388-
let config = r#"[metadata]
389-
app = "torrust-index"
390-
purpose = "configuration"
391-
schema_version = "2.0.0"
392-
393-
[logging]
394-
threshold = "info"
395-
396-
[website]
397-
name = "Torrust"
398-
399-
[tracker]
400-
api_url = "http://localhost:1212/"
401-
listed = false
402-
private = false
403-
token = "MyAccessToken"
404-
token_valid_seconds = 7257600
405-
url = "udp://localhost:6969"
406-
407-
[net]
408-
bind_address = "0.0.0.0:3001"
409-
410-
[auth]
411-
user_claim_token_pepper = "MaxVerstappenWC2021"
412-
413-
[auth.password_constraints]
414-
max_password_length = 64
415-
min_password_length = 6
416-
417-
[database]
418-
connect_url = "sqlite://data.db?mode=rwc"
419-
420-
[mail]
421-
from = "example@email.com"
422-
reply_to = "noreply@email.com"
423-
424-
[mail.smtp]
425-
port = 25
426-
server = ""
427-
428-
[mail.smtp.credentials]
429-
password = ""
430-
username = ""
431-
432-
[image_cache]
433-
capacity = 128000000
434-
entry_size_limit = 4000000
435-
max_request_timeout_ms = 1000
436-
user_quota_bytes = 64000000
437-
user_quota_period_seconds = 3600
438-
439-
[api]
440-
default_torrent_page_size = 10
441-
max_torrent_page_size = 30
442-
443-
[tracker_statistics_importer]
444-
port = 3002
445-
torrent_info_update_interval = 3600
446-
"#
447-
.lines()
448-
.map(str::trim_start)
449-
.collect::<Vec<&str>>()
450-
.join("\n");
401+
use std::fs;
402+
use std::path::PathBuf;
403+
404+
// Get the path to the current Cargo.toml directory
405+
let manifest_dir = std::env::var("CARGO_MANIFEST_DIR").expect("CARGO_MANIFEST_DIR environment variable not set");
406+
407+
// Construct the path to the default configuration file relative to the Cargo.toml directory
408+
let mut path = PathBuf::from(manifest_dir);
409+
path.push("tests/fixtures/default_configuration.toml");
410+
411+
let config = fs::read_to_string(path)
412+
.expect("Could not read default configuration TOML file: tests/fixtures/default_configuration.toml");
413+
414+
config.lines().map(str::trim_start).collect::<Vec<&str>>().join("\n");
415+
451416
config
452417
}
453418

454-
#[tokio::test]
455-
async fn configuration_should_build_settings_with_default_values() {
456-
let configuration = Configuration::default().get_all().await;
419+
/// Build settings from default configuration fixture in TOML.
420+
///
421+
/// We just want to load that file without overriding with env var or other
422+
/// configuration loading behavior.
423+
#[cfg(test)]
424+
fn default_settings() -> Settings {
425+
use figment::providers::{Format, Toml};
426+
use figment::Figment;
457427

458-
let toml = toml::to_string(&configuration).expect("Could not encode TOML value for configuration");
428+
let figment = Figment::from(Toml::string(&default_config_toml()));
429+
let settings: Settings = figment.extract().expect("Invalid configuration");
459430

460-
assert_eq!(toml, default_config_toml());
431+
settings
461432
}
462433

463434
#[tokio::test]
464-
async fn configuration_should_return_all_settings() {
465-
let configuration = Configuration::default().get_all().await;
466-
467-
let toml = toml::to_string(&configuration).expect("Could not encode TOML value for configuration");
435+
async fn configuration_should_have_a_default_constructor() {
436+
let settings = Configuration::default().get_all().await;
468437

469-
assert_eq!(toml, default_config_toml());
438+
assert_eq!(settings, default_settings());
470439
}
471440

472441
#[tokio::test]

src/config/v2/website.rs

+142
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,22 @@ pub struct Website {
66
/// The name of the website.
77
#[serde(default = "Website::default_name")]
88
pub name: String,
9+
10+
/// The demo settings when the app runs in `demo` mode.
11+
#[serde(default = "Website::default_demo")]
12+
pub demo: Option<Demo>,
13+
14+
/// The legal information.
15+
#[serde(default = "Website::default_terms")]
16+
pub terms: Terms,
917
}
1018

1119
impl Default for Website {
1220
fn default() -> Self {
1321
Self {
1422
name: Self::default_name(),
23+
demo: Self::default_demo(),
24+
terms: Self::default_terms(),
1525
}
1626
}
1727
}
@@ -20,4 +30,136 @@ impl Website {
2030
fn default_name() -> String {
2131
"Torrust".to_string()
2232
}
33+
34+
fn default_demo() -> Option<Demo> {
35+
None
36+
}
37+
38+
fn default_terms() -> Terms {
39+
Terms::default()
40+
}
41+
}
42+
43+
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
44+
pub struct Demo {
45+
/// The fixed message to show when the index is running in demo mode.
46+
#[serde(default = "Demo::default_warning")]
47+
pub warning: String,
48+
}
49+
50+
impl Demo {
51+
fn default_warning() -> String {
52+
"⚠️ Please be aware: This demo resets all data weekly. Torrents not complying with our Usage Policies will be removed immediately without notice. We encourage the responsible use of this software in compliance with all legal requirements.".to_string()
53+
}
54+
}
55+
56+
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
57+
pub struct Terms {
58+
/// The terms page info.
59+
#[serde(default = "Terms::default_page")]
60+
pub page: TermsPage,
61+
62+
/// The upload agreement info.
63+
#[serde(default = "Terms::default_upload")]
64+
pub upload: TermsUpload,
65+
}
66+
67+
impl Terms {
68+
fn default_page() -> TermsPage {
69+
TermsPage::default()
70+
}
71+
72+
fn default_upload() -> TermsUpload {
73+
TermsUpload::default()
74+
}
75+
}
76+
77+
impl Default for Terms {
78+
fn default() -> Self {
79+
Self {
80+
page: Self::default_page(),
81+
upload: Self::default_upload(),
82+
}
83+
}
84+
}
85+
86+
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
87+
pub struct TermsPage {
88+
/// The terms page title.
89+
#[serde(default = "TermsPage::default_title")]
90+
pub title: String,
91+
92+
/// The terms page content.
93+
#[serde(default = "TermsPage::default_content")]
94+
pub content: Markdown,
95+
}
96+
97+
impl TermsPage {
98+
fn default_title() -> String {
99+
"Usage Policies and Content Restrictions".to_string()
100+
}
101+
102+
fn default_content() -> Markdown {
103+
Markdown::new(
104+
r"
105+
# Usage Policies and Content Restrictions
106+
107+
Our software is designed to support the distribution of legal, authorized content only. Users may only upload or share files that fall under the following categories:
108+
109+
- **Open-Source Licenses:** Content licensed under recognized open-source licenses, allowing for free distribution and modification.
110+
- **Creative Commons Licenses:** Content released under Creative Commons licenses that permit sharing and distribution.
111+
- **Public Domain:** Content that is free of copyright restrictions and available for public use.
112+
113+
**Prohibited Content:** Any content that infringes copyright, is subject to copyright protection, or is illegal under applicable laws is strictly prohibited. This includes but is not limited to copyrighted movies, music, software, books, and any other media.
114+
115+
**Enforcement:** We reserve the right to remove any content that does not comply with these policies without notice. We may also take additional steps, including reporting violations to the relevant authorities, if necessary.
116+
117+
",
118+
)
119+
}
120+
}
121+
122+
impl Default for TermsPage {
123+
fn default() -> Self {
124+
Self {
125+
title: Self::default_title(),
126+
content: Self::default_content(),
127+
}
128+
}
129+
}
130+
131+
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
132+
pub struct TermsUpload {
133+
/// The terms page content.
134+
#[serde(default = "TermsUpload::default_content_upload_agreement")]
135+
pub content_upload_agreement: Markdown,
136+
}
137+
138+
impl TermsUpload {
139+
fn default_content_upload_agreement() -> Markdown {
140+
Markdown::new("I confirm that the content I am uploading is authorized, and I have read and agree to the terms.")
141+
}
142+
}
143+
144+
impl Default for TermsUpload {
145+
fn default() -> Self {
146+
Self {
147+
content_upload_agreement: Self::default_content_upload_agreement(),
148+
}
149+
}
150+
}
151+
152+
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
153+
pub struct Markdown(String);
154+
155+
impl Markdown {
156+
#[must_use]
157+
pub fn new(content: &str) -> Self {
158+
Self(content.to_owned())
159+
}
160+
161+
#[must_use]
162+
pub fn source(&self) -> String {
163+
self.0.clone()
164+
}
23165
}

src/errors.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ pub enum ServiceError {
5555

5656
#[display(fmt = "Password too short")]
5757
PasswordTooShort,
58-
#[display(fmt = "Username too long")]
58+
#[display(fmt = "Password too long")]
5959
PasswordTooLong,
6060
#[display(fmt = "Passwords don't match")]
6161
PasswordsDontMatch,

0 commit comments

Comments
 (0)