mirror of
https://github.com/LemmyNet/lemmy.git
synced 2024-11-26 14:21:19 +00:00
Merge branch 'main' into clear_deleted_posts_comments
This commit is contained in:
commit
0d576a8f23
8 changed files with 85 additions and 49 deletions
22
Cargo.lock
generated
22
Cargo.lock
generated
|
@ -2583,7 +2583,7 @@ checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "lemmy_api"
|
name = "lemmy_api"
|
||||||
version = "0.18.0-rc.4"
|
version = "0.18.0-rc.5"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"actix-web",
|
"actix-web",
|
||||||
"anyhow",
|
"anyhow",
|
||||||
|
@ -2606,7 +2606,7 @@ dependencies = [
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "lemmy_api_common"
|
name = "lemmy_api_common"
|
||||||
version = "0.18.0-rc.4"
|
version = "0.18.0-rc.5"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"actix-rt",
|
"actix-rt",
|
||||||
"actix-web",
|
"actix-web",
|
||||||
|
@ -2635,7 +2635,7 @@ dependencies = [
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "lemmy_api_crud"
|
name = "lemmy_api_crud"
|
||||||
version = "0.18.0-rc.4"
|
version = "0.18.0-rc.5"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"activitypub_federation",
|
"activitypub_federation",
|
||||||
"actix-web",
|
"actix-web",
|
||||||
|
@ -2654,7 +2654,7 @@ dependencies = [
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "lemmy_apub"
|
name = "lemmy_apub"
|
||||||
version = "0.18.0-rc.4"
|
version = "0.18.0-rc.5"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"activitypub_federation",
|
"activitypub_federation",
|
||||||
"actix-rt",
|
"actix-rt",
|
||||||
|
@ -2692,7 +2692,7 @@ dependencies = [
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "lemmy_db_schema"
|
name = "lemmy_db_schema"
|
||||||
version = "0.18.0-rc.4"
|
version = "0.18.0-rc.5"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"activitypub_federation",
|
"activitypub_federation",
|
||||||
"async-trait",
|
"async-trait",
|
||||||
|
@ -2724,7 +2724,7 @@ dependencies = [
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "lemmy_db_views"
|
name = "lemmy_db_views"
|
||||||
version = "0.18.0-rc.4"
|
version = "0.18.0-rc.5"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"diesel",
|
"diesel",
|
||||||
"diesel-async",
|
"diesel-async",
|
||||||
|
@ -2741,7 +2741,7 @@ dependencies = [
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "lemmy_db_views_actor"
|
name = "lemmy_db_views_actor"
|
||||||
version = "0.18.0-rc.4"
|
version = "0.18.0-rc.5"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"diesel",
|
"diesel",
|
||||||
"diesel-async",
|
"diesel-async",
|
||||||
|
@ -2754,7 +2754,7 @@ dependencies = [
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "lemmy_db_views_moderator"
|
name = "lemmy_db_views_moderator"
|
||||||
version = "0.18.0-rc.4"
|
version = "0.18.0-rc.5"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"diesel",
|
"diesel",
|
||||||
"diesel-async",
|
"diesel-async",
|
||||||
|
@ -2766,7 +2766,7 @@ dependencies = [
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "lemmy_routes"
|
name = "lemmy_routes"
|
||||||
version = "0.18.0-rc.4"
|
version = "0.18.0-rc.5"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"activitypub_federation",
|
"activitypub_federation",
|
||||||
"actix-web",
|
"actix-web",
|
||||||
|
@ -2791,7 +2791,7 @@ dependencies = [
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "lemmy_server"
|
name = "lemmy_server"
|
||||||
version = "0.18.0-rc.4"
|
version = "0.18.0-rc.5"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"activitypub_federation",
|
"activitypub_federation",
|
||||||
"actix-cors",
|
"actix-cors",
|
||||||
|
@ -2828,7 +2828,7 @@ dependencies = [
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "lemmy_utils"
|
name = "lemmy_utils"
|
||||||
version = "0.18.0-rc.4"
|
version = "0.18.0-rc.5"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"actix-web",
|
"actix-web",
|
||||||
"anyhow",
|
"anyhow",
|
||||||
|
|
22
Cargo.toml
22
Cargo.toml
|
@ -1,5 +1,5 @@
|
||||||
[workspace.package]
|
[workspace.package]
|
||||||
version = "0.18.0-rc.4"
|
version = "0.18.0-rc.5"
|
||||||
edition = "2021"
|
edition = "2021"
|
||||||
description = "A link aggregator for the fediverse"
|
description = "A link aggregator for the fediverse"
|
||||||
license = "AGPL-3.0"
|
license = "AGPL-3.0"
|
||||||
|
@ -49,16 +49,16 @@ members = [
|
||||||
]
|
]
|
||||||
|
|
||||||
[workspace.dependencies]
|
[workspace.dependencies]
|
||||||
lemmy_api = { version = "=0.18.0-rc.4", path = "./crates/api" }
|
lemmy_api = { version = "=0.18.0-rc.5", path = "./crates/api" }
|
||||||
lemmy_api_crud = { version = "=0.18.0-rc.4", path = "./crates/api_crud" }
|
lemmy_api_crud = { version = "=0.18.0-rc.5", path = "./crates/api_crud" }
|
||||||
lemmy_apub = { version = "=0.18.0-rc.4", path = "./crates/apub" }
|
lemmy_apub = { version = "=0.18.0-rc.5", path = "./crates/apub" }
|
||||||
lemmy_utils = { version = "=0.18.0-rc.4", path = "./crates/utils" }
|
lemmy_utils = { version = "=0.18.0-rc.5", path = "./crates/utils" }
|
||||||
lemmy_db_schema = { version = "=0.18.0-rc.4", path = "./crates/db_schema" }
|
lemmy_db_schema = { version = "=0.18.0-rc.5", path = "./crates/db_schema" }
|
||||||
lemmy_api_common = { version = "=0.18.0-rc.4", path = "./crates/api_common" }
|
lemmy_api_common = { version = "=0.18.0-rc.5", path = "./crates/api_common" }
|
||||||
lemmy_routes = { version = "=0.18.0-rc.4", path = "./crates/routes" }
|
lemmy_routes = { version = "=0.18.0-rc.5", path = "./crates/routes" }
|
||||||
lemmy_db_views = { version = "=0.18.0-rc.4", path = "./crates/db_views" }
|
lemmy_db_views = { version = "=0.18.0-rc.5", path = "./crates/db_views" }
|
||||||
lemmy_db_views_actor = { version = "=0.18.0-rc.4", path = "./crates/db_views_actor" }
|
lemmy_db_views_actor = { version = "=0.18.0-rc.5", path = "./crates/db_views_actor" }
|
||||||
lemmy_db_views_moderator = { version = "=0.18.0-rc.4", path = "./crates/db_views_moderator" }
|
lemmy_db_views_moderator = { version = "=0.18.0-rc.5", path = "./crates/db_views_moderator" }
|
||||||
activitypub_federation = { version = "0.4.1", default-features = false, features = ["actix-web"] }
|
activitypub_federation = { version = "0.4.1", default-features = false, features = ["actix-web"] }
|
||||||
diesel = "2.1.0"
|
diesel = "2.1.0"
|
||||||
diesel_migrations = "2.1.0"
|
diesel_migrations = "2.1.0"
|
||||||
|
|
|
@ -122,6 +122,7 @@ Each Lemmy server can set its own moderation policy; appointing site-wide admins
|
||||||
- [lemmyBB - A Lemmy forum UI based on phpBB](https://github.com/LemmyNet/lemmyBB)
|
- [lemmyBB - A Lemmy forum UI based on phpBB](https://github.com/LemmyNet/lemmyBB)
|
||||||
- [Jerboa - A native Android app made by Lemmy's developers](https://github.com/dessalines/jerboa)
|
- [Jerboa - A native Android app made by Lemmy's developers](https://github.com/dessalines/jerboa)
|
||||||
- [Mlem - A Lemmy client for iOS](https://github.com/buresdv/Mlem)
|
- [Mlem - A Lemmy client for iOS](https://github.com/buresdv/Mlem)
|
||||||
|
- [Lemoa - A Gtk client for Lemmy on Linux](https://github.com/lemmy-gtk/lemoa)
|
||||||
|
|
||||||
### Libraries
|
### Libraries
|
||||||
|
|
||||||
|
|
|
@ -29,7 +29,7 @@ use lemmy_utils::{
|
||||||
error::LemmyError,
|
error::LemmyError,
|
||||||
utils::{
|
utils::{
|
||||||
slurs::{check_slurs, check_slurs_opt},
|
slurs::{check_slurs, check_slurs_opt},
|
||||||
validation::is_valid_body_field,
|
validation::{check_site_visibility_valid, is_valid_body_field},
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
use url::Url;
|
use url::Url;
|
||||||
|
@ -50,6 +50,16 @@ impl PerformCrud for CreateSite {
|
||||||
|
|
||||||
let local_user_view = local_user_view_from_jwt(&data.auth, context).await?;
|
let local_user_view = local_user_view_from_jwt(&data.auth, context).await?;
|
||||||
|
|
||||||
|
// Make sure user is an admin
|
||||||
|
is_admin(&local_user_view)?;
|
||||||
|
|
||||||
|
check_site_visibility_valid(
|
||||||
|
local_site.private_instance,
|
||||||
|
local_site.federation_enabled,
|
||||||
|
&data.private_instance,
|
||||||
|
&data.federation_enabled,
|
||||||
|
)?;
|
||||||
|
|
||||||
let sidebar = diesel_option_overwrite(&data.sidebar);
|
let sidebar = diesel_option_overwrite(&data.sidebar);
|
||||||
let description = diesel_option_overwrite(&data.description);
|
let description = diesel_option_overwrite(&data.description);
|
||||||
let icon = diesel_option_overwrite_to_url(&data.icon)?;
|
let icon = diesel_option_overwrite_to_url(&data.icon)?;
|
||||||
|
@ -59,9 +69,6 @@ impl PerformCrud for CreateSite {
|
||||||
check_slurs(&data.name, &slur_regex)?;
|
check_slurs(&data.name, &slur_regex)?;
|
||||||
check_slurs_opt(&data.description, &slur_regex)?;
|
check_slurs_opt(&data.description, &slur_regex)?;
|
||||||
|
|
||||||
// Make sure user is an admin
|
|
||||||
is_admin(&local_user_view)?;
|
|
||||||
|
|
||||||
if let Some(Some(desc)) = &description {
|
if let Some(Some(desc)) = &description {
|
||||||
site_description_length_check(desc)?;
|
site_description_length_check(desc)?;
|
||||||
}
|
}
|
||||||
|
|
|
@ -30,7 +30,10 @@ use lemmy_db_schema::{
|
||||||
use lemmy_db_views::structs::SiteView;
|
use lemmy_db_views::structs::SiteView;
|
||||||
use lemmy_utils::{
|
use lemmy_utils::{
|
||||||
error::LemmyError,
|
error::LemmyError,
|
||||||
utils::{slurs::check_slurs_opt, validation::is_valid_body_field},
|
utils::{
|
||||||
|
slurs::check_slurs_opt,
|
||||||
|
validation::{check_site_visibility_valid, is_valid_body_field},
|
||||||
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
#[async_trait::async_trait(?Send)]
|
#[async_trait::async_trait(?Send)]
|
||||||
|
@ -48,6 +51,13 @@ impl PerformCrud for EditSite {
|
||||||
// Make sure user is an admin
|
// Make sure user is an admin
|
||||||
is_admin(&local_user_view)?;
|
is_admin(&local_user_view)?;
|
||||||
|
|
||||||
|
check_site_visibility_valid(
|
||||||
|
local_site.private_instance,
|
||||||
|
local_site.federation_enabled,
|
||||||
|
&data.private_instance,
|
||||||
|
&data.federation_enabled,
|
||||||
|
)?;
|
||||||
|
|
||||||
let slur_regex = local_site_to_slur_regex(&local_site);
|
let slur_regex = local_site_to_slur_regex(&local_site);
|
||||||
|
|
||||||
check_slurs_opt(&data.name, &slur_regex)?;
|
check_slurs_opt(&data.name, &slur_regex)?;
|
||||||
|
@ -76,19 +86,6 @@ impl PerformCrud for EditSite {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
let enabled_private_instance_with_federation = data.private_instance == Some(true)
|
|
||||||
&& data
|
|
||||||
.federation_enabled
|
|
||||||
.unwrap_or(local_site.federation_enabled);
|
|
||||||
let enabled_federation_with_private_instance = data.federation_enabled == Some(true)
|
|
||||||
&& data.private_instance.unwrap_or(local_site.private_instance);
|
|
||||||
|
|
||||||
if enabled_private_instance_with_federation || enabled_federation_with_private_instance {
|
|
||||||
return Err(LemmyError::from_message(
|
|
||||||
"cant_enable_private_instance_and_federation_together",
|
|
||||||
));
|
|
||||||
}
|
|
||||||
|
|
||||||
if let Some(discussion_languages) = data.discussion_languages.clone() {
|
if let Some(discussion_languages) = data.discussion_languages.clone() {
|
||||||
SiteLanguage::update(context.pool(), discussion_languages.clone(), &site).await?;
|
SiteLanguage::update(context.pool(), discussion_languages.clone(), &site).await?;
|
||||||
}
|
}
|
||||||
|
|
|
@ -149,10 +149,29 @@ pub fn build_totp_2fa(site_name: &str, username: &str, secret: &str) -> Result<T
|
||||||
.map_err(|e| LemmyError::from_error_message(e, "Couldnt generate TOTP"))
|
.map_err(|e| LemmyError::from_error_message(e, "Couldnt generate TOTP"))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn check_site_visibility_valid(
|
||||||
|
current_private_instance: bool,
|
||||||
|
current_federation_enabled: bool,
|
||||||
|
new_private_instance: &Option<bool>,
|
||||||
|
new_federation_enabled: &Option<bool>,
|
||||||
|
) -> LemmyResult<()> {
|
||||||
|
let private_instance = new_private_instance.unwrap_or(current_private_instance);
|
||||||
|
let federation_enabled = new_federation_enabled.unwrap_or(current_federation_enabled);
|
||||||
|
|
||||||
|
if private_instance && federation_enabled {
|
||||||
|
return Err(LemmyError::from_message(
|
||||||
|
"cant_enable_private_instance_and_federation_together",
|
||||||
|
));
|
||||||
|
}
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use super::build_totp_2fa;
|
use super::build_totp_2fa;
|
||||||
use crate::utils::validation::{
|
use crate::utils::validation::{
|
||||||
|
check_site_visibility_valid,
|
||||||
clean_url_params,
|
clean_url_params,
|
||||||
generate_totp_2fa_secret,
|
generate_totp_2fa_secret,
|
||||||
is_valid_actor_name,
|
is_valid_actor_name,
|
||||||
|
@ -226,4 +245,16 @@ mod tests {
|
||||||
let totp = build_totp_2fa("lemmy", "my_name", &generated_secret);
|
let totp = build_totp_2fa("lemmy", "my_name", &generated_secret);
|
||||||
assert!(totp.is_ok());
|
assert!(totp.is_ok());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_check_site_visibility_valid() {
|
||||||
|
assert!(check_site_visibility_valid(true, true, &None, &None).is_err());
|
||||||
|
assert!(check_site_visibility_valid(true, false, &None, &Some(true)).is_err());
|
||||||
|
assert!(check_site_visibility_valid(false, true, &Some(true), &None).is_err());
|
||||||
|
assert!(check_site_visibility_valid(false, false, &Some(true), &Some(true)).is_err());
|
||||||
|
assert!(check_site_visibility_valid(true, false, &None, &None).is_ok());
|
||||||
|
assert!(check_site_visibility_valid(false, true, &None, &None).is_ok());
|
||||||
|
assert!(check_site_visibility_valid(false, false, &Some(true), &None).is_ok());
|
||||||
|
assert!(check_site_visibility_valid(false, false, &None, &Some(true)).is_ok());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -20,7 +20,8 @@ RUN --mount=type=cache,target=/app/target \
|
||||||
# Release mode build
|
# Release mode build
|
||||||
RUN \
|
RUN \
|
||||||
if [ "$RUST_RELEASE_MODE" = "release" ] ; then \
|
if [ "$RUST_RELEASE_MODE" = "release" ] ; then \
|
||||||
cargo build --target ${CARGO_BUILD_TARGET} --release \
|
echo "pub const VERSION: &str = \"$(git describe --tag)\";" > "crates/utils/src/version.rs" \
|
||||||
|
&& cargo build --target ${CARGO_BUILD_TARGET} --release \
|
||||||
&& cp ./target/$CARGO_BUILD_TARGET/$RUST_RELEASE_MODE/lemmy_server /app/lemmy_server; \
|
&& cp ./target/$CARGO_BUILD_TARGET/$RUST_RELEASE_MODE/lemmy_server /app/lemmy_server; \
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
|
|
@ -335,16 +335,15 @@ pub fn config(cfg: &mut web::ServiceConfig, rate_limit: &RateLimitCell) {
|
||||||
.route(
|
.route(
|
||||||
"/registration_application/approve",
|
"/registration_application/approve",
|
||||||
web::put().to(route_post::<ApproveRegistrationApplication>),
|
web::put().to(route_post::<ApproveRegistrationApplication>),
|
||||||
|
)
|
||||||
|
.service(
|
||||||
|
web::scope("/purge")
|
||||||
|
.route("/person", web::post().to(route_post::<PurgePerson>))
|
||||||
|
.route("/community", web::post().to(route_post::<PurgeCommunity>))
|
||||||
|
.route("/post", web::post().to(route_post::<PurgePost>))
|
||||||
|
.route("/comment", web::post().to(route_post::<PurgeComment>)),
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
.service(
|
|
||||||
web::scope("/admin/purge")
|
|
||||||
.wrap(rate_limit.message())
|
|
||||||
.route("/person", web::post().to(route_post::<PurgePerson>))
|
|
||||||
.route("/community", web::post().to(route_post::<PurgeCommunity>))
|
|
||||||
.route("/post", web::post().to(route_post::<PurgePost>))
|
|
||||||
.route("/comment", web::post().to(route_post::<PurgeComment>)),
|
|
||||||
)
|
|
||||||
.service(
|
.service(
|
||||||
web::scope("/custom_emoji")
|
web::scope("/custom_emoji")
|
||||||
.wrap(rate_limit.message())
|
.wrap(rate_limit.message())
|
||||||
|
|
Loading…
Reference in a new issue