Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Release Version 3.0.0-rc.1 #734

Merged
merged 15 commits into from
Sep 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
713 changes: 471 additions & 242 deletions Cargo.lock

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ license = "AGPL-3.0-only"
publish = true
repository = "https://github.com/torrust/torrust-tracker"
rust-version = "1.72"
version = "3.0.0-beta"
version = "3.0.0-rc.1"

[profile.dev.package.sqlx-macros]
opt-level = 3
Expand Down Expand Up @@ -89,7 +89,7 @@ text-to-png = "0"
thiserror = "1"
tokio = { version = "1", features = ["fs", "io-util", "macros", "net", "rt-multi-thread", "signal", "sync", "time"] }
toml = "0"
torrust-index-located-error = { version = "3.0.0-beta", path = "packages/located-error" }
torrust-index-located-error = { version = "3.0.0-rc.1", path = "packages/located-error" }
tower = { version = "0.4", features = ["timeout"] }
tower-http = { version = "0", features = ["compression-full", "cors", "propagate-header", "request-id", "trace"] }
trace = "0.1.7"
Expand Down
2 changes: 2 additions & 0 deletions share/default/config/index.development.sqlite3.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ app = "torrust-index"
purpose = "configuration"
schema_version = "2.0.0"

[website.demo]

[logging]
#threshold = "off"
#threshold = "error"
Expand Down
115 changes: 42 additions & 73 deletions src/config/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,11 @@ pub type Logging = v2::logging::Logging;
pub type Threshold = v2::logging::Threshold;

pub type Website = v2::website::Website;
pub type Demo = v2::website::Demo;
pub type Terms = v2::website::Terms;
pub type TermsPage = v2::website::TermsPage;
pub type TermsUpload = v2::website::TermsUpload;
pub type Markdown = v2::website::Markdown;

/// Configuration version
const VERSION_2: &str = "2.0.0";
Expand Down Expand Up @@ -193,6 +198,14 @@ impl Info {
config_toml_path,
})
}

#[must_use]
pub fn from_toml(config_toml: &str) -> Self {
Self {
config_toml: Some(config_toml.to_owned()),
config_toml_path: String::new(),
}
}
}

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

#[cfg(test)]
fn default_config_toml() -> String {
let config = r#"[metadata]
app = "torrust-index"
purpose = "configuration"
schema_version = "2.0.0"

[logging]
threshold = "info"

[website]
name = "Torrust"

[tracker]
api_url = "http://localhost:1212/"
listed = false
private = false
token = "MyAccessToken"
token_valid_seconds = 7257600
url = "udp://localhost:6969"

[net]
bind_address = "0.0.0.0:3001"

[auth]
user_claim_token_pepper = "MaxVerstappenWC2021"

[auth.password_constraints]
max_password_length = 64
min_password_length = 6

[database]
connect_url = "sqlite://data.db?mode=rwc"

[mail]
from = "example@email.com"
reply_to = "noreply@email.com"

[mail.smtp]
port = 25
server = ""

[mail.smtp.credentials]
password = ""
username = ""

[image_cache]
capacity = 128000000
entry_size_limit = 4000000
max_request_timeout_ms = 1000
user_quota_bytes = 64000000
user_quota_period_seconds = 3600

[api]
default_torrent_page_size = 10
max_torrent_page_size = 30

[tracker_statistics_importer]
port = 3002
torrent_info_update_interval = 3600
"#
.lines()
.map(str::trim_start)
.collect::<Vec<&str>>()
.join("\n");
use std::fs;
use std::path::PathBuf;

// Get the path to the current Cargo.toml directory
let manifest_dir = std::env::var("CARGO_MANIFEST_DIR").expect("CARGO_MANIFEST_DIR environment variable not set");

// Construct the path to the default configuration file relative to the Cargo.toml directory
let mut path = PathBuf::from(manifest_dir);
path.push("tests/fixtures/default_configuration.toml");

let config = fs::read_to_string(path)
.expect("Could not read default configuration TOML file: tests/fixtures/default_configuration.toml");

config.lines().map(str::trim_start).collect::<Vec<&str>>().join("\n");

config
}

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

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

assert_eq!(toml, default_config_toml());
settings
}

#[tokio::test]
async fn configuration_should_return_all_settings() {
let configuration = Configuration::default().get_all().await;

let toml = toml::to_string(&configuration).expect("Could not encode TOML value for configuration");
async fn configuration_should_have_a_default_constructor() {
let settings = Configuration::default().get_all().await;

assert_eq!(toml, default_config_toml());
assert_eq!(settings, default_settings());
}

#[tokio::test]
Expand Down
142 changes: 142 additions & 0 deletions src/config/v2/website.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,22 @@ pub struct Website {
/// The name of the website.
#[serde(default = "Website::default_name")]
pub name: String,

/// The demo settings when the app runs in `demo` mode.
#[serde(default = "Website::default_demo")]
pub demo: Option<Demo>,

/// The legal information.
#[serde(default = "Website::default_terms")]
pub terms: Terms,
}

impl Default for Website {
fn default() -> Self {
Self {
name: Self::default_name(),
demo: Self::default_demo(),
terms: Self::default_terms(),
}
}
}
Expand All @@ -20,4 +30,136 @@ impl Website {
fn default_name() -> String {
"Torrust".to_string()
}

fn default_demo() -> Option<Demo> {
None
}

fn default_terms() -> Terms {
Terms::default()
}
}

#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
pub struct Demo {
/// The fixed message to show when the index is running in demo mode.
#[serde(default = "Demo::default_warning")]
pub warning: String,
}

impl Demo {
fn default_warning() -> String {
"⚠️ 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()
}
}

#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
pub struct Terms {
/// The terms page info.
#[serde(default = "Terms::default_page")]
pub page: TermsPage,

/// The upload agreement info.
#[serde(default = "Terms::default_upload")]
pub upload: TermsUpload,
}

impl Terms {
fn default_page() -> TermsPage {
TermsPage::default()
}

fn default_upload() -> TermsUpload {
TermsUpload::default()
}
}

impl Default for Terms {
fn default() -> Self {
Self {
page: Self::default_page(),
upload: Self::default_upload(),
}
}
}

#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
pub struct TermsPage {
/// The terms page title.
#[serde(default = "TermsPage::default_title")]
pub title: String,

/// The terms page content.
#[serde(default = "TermsPage::default_content")]
pub content: Markdown,
}

impl TermsPage {
fn default_title() -> String {
"Usage Policies and Content Restrictions".to_string()
}

fn default_content() -> Markdown {
Markdown::new(
r"
# Usage Policies and Content Restrictions

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:

- **Open-Source Licenses:** Content licensed under recognized open-source licenses, allowing for free distribution and modification.
- **Creative Commons Licenses:** Content released under Creative Commons licenses that permit sharing and distribution.
- **Public Domain:** Content that is free of copyright restrictions and available for public use.

**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.

**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.

",
)
}
}

impl Default for TermsPage {
fn default() -> Self {
Self {
title: Self::default_title(),
content: Self::default_content(),
}
}
}

#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
pub struct TermsUpload {
/// The terms page content.
#[serde(default = "TermsUpload::default_content_upload_agreement")]
pub content_upload_agreement: Markdown,
}

impl TermsUpload {
fn default_content_upload_agreement() -> Markdown {
Markdown::new("I confirm that the content I am uploading is authorized, and I have read and agree to the terms.")
}
}

impl Default for TermsUpload {
fn default() -> Self {
Self {
content_upload_agreement: Self::default_content_upload_agreement(),
}
}
}

#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
pub struct Markdown(String);

impl Markdown {
#[must_use]
pub fn new(content: &str) -> Self {
Self(content.to_owned())
}

#[must_use]
pub fn source(&self) -> String {
self.0.clone()
}
}
2 changes: 1 addition & 1 deletion src/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ pub enum ServiceError {

#[display(fmt = "Password too short")]
PasswordTooShort,
#[display(fmt = "Username too long")]
#[display(fmt = "Password too long")]
PasswordTooLong,
#[display(fmt = "Passwords don't match")]
PasswordsDontMatch,
Expand Down
Loading
Loading