-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge #731: Add CMS content for legal texts to configuration
7d82eb2 feat: [#730] add CMS content to configration (Jose Celano) Pull request description: We need to pass legal texts to the frontent but we don't have a proper CMS. For now, we have just added the texts in the configuration to make it possible for users to overrride them. These are the new values in the config: ```toml [website.demo] warning = "⚠️ 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." [website.terms] [website.terms.upload] content_upload_agreement = """I confirm that the content I am uploading is authorized, and I have read and agree to the terms.""" [website.terms.page] title = "Usage Policies and Content Restrictions" content = """ 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. """ ``` ACKs for top commit: josecelano: ACK 7d82eb2 Tree-SHA512: 708aceea4457df03e5bbcc1f2e6b61d521e68db1ce45b962a78d62be297ff94119614c0c11c21f03915d8db8dbddde1ed530da0176a280ec8152854e268e4b47
- Loading branch information
Showing
4 changed files
with
356 additions
and
75 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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"; | ||
|
@@ -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. | ||
|
@@ -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 = "[email protected]" | ||
reply_to = "[email protected]" | ||
[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] | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.