From 74668f7e170794cd3d0a245fc9a38dbb8f6be918 Mon Sep 17 00:00:00 2001 From: Felix Ableitner Date: Thu, 28 Nov 2024 11:26:02 +0100 Subject: [PATCH] address comments --- api_tests/src/post.spec.ts | 1 - api_tests/src/shared.ts | 1 - crates/api/src/site/admin_block_instance.rs | 2 +- crates/db_schema/src/schema.rs | 4 ++-- crates/db_schema/src/source/mod_log/admin.rs | 6 +++--- .../src/admin_allow_instance.rs | 2 +- .../src/admin_block_instance.rs | 2 +- .../down.sql | 0 .../up.sql | 4 ++-- src/scheduled_tasks.rs | 15 +++++++++++++++ 10 files changed, 25 insertions(+), 12 deletions(-) rename migrations/{2024-11-19-142005_instance-block-mod-log => 2024-11-28-142005_instance-block-mod-log}/down.sql (100%) rename migrations/{2024-11-19-142005_instance-block-mod-log => 2024-11-28-142005_instance-block-mod-log}/up.sql (87%) diff --git a/api_tests/src/post.spec.ts b/api_tests/src/post.spec.ts index 1acf6c63a..a6063e0a2 100644 --- a/api_tests/src/post.spec.ts +++ b/api_tests/src/post.spec.ts @@ -92,7 +92,6 @@ test("Create a post", async () => { var block_instance_params: AdminBlockInstanceParams = { instance: "lemmy-alpha", block: true, - reason: undefined, }; await epsilon.adminBlockInstance(block_instance_params); diff --git a/api_tests/src/shared.ts b/api_tests/src/shared.ts index a6a7db5e5..9b0662959 100644 --- a/api_tests/src/shared.ts +++ b/api_tests/src/shared.ts @@ -205,7 +205,6 @@ async function allowInstance(api: LemmyHttp, instance: string) { const params: AdminAllowInstanceParams = { instance, allow: true, - reason: undefined, }; // Ignore errors from duplicate allows (because setup gets called for each test file) try { diff --git a/crates/api/src/site/admin_block_instance.rs b/crates/api/src/site/admin_block_instance.rs index ec6fd2f9c..54962ccf3 100644 --- a/crates/api/src/site/admin_block_instance.rs +++ b/crates/api/src/site/admin_block_instance.rs @@ -48,7 +48,7 @@ pub async fn admin_block_instance( admin_person_id: local_user_view.person.id, blocked: data.block, reason: data.reason.clone(), - expires: data.expires, + when_: data.expires, }; AdminBlockInstance::insert(&mut context.pool(), &mod_log_form).await?; diff --git a/crates/db_schema/src/schema.rs b/crates/db_schema/src/schema.rs index 151e7fd65..0bc046ece 100644 --- a/crates/db_schema/src/schema.rs +++ b/crates/db_schema/src/schema.rs @@ -49,7 +49,7 @@ diesel::table! { admin_person_id -> Int4, allowed -> Bool, reason -> Nullable, - published -> Timestamptz, + when_ -> Timestamptz, } } @@ -61,7 +61,7 @@ diesel::table! { blocked -> Bool, reason -> Nullable, expires -> Nullable, - published -> Timestamptz, + when_ -> Timestamptz, } } diff --git a/crates/db_schema/src/source/mod_log/admin.rs b/crates/db_schema/src/source/mod_log/admin.rs index 3fd397441..d6e48b8ee 100644 --- a/crates/db_schema/src/source/mod_log/admin.rs +++ b/crates/db_schema/src/source/mod_log/admin.rs @@ -126,7 +126,7 @@ pub struct AdminAllowInstance { pub allowed: bool, #[cfg_attr(feature = "full", ts(optional))] pub reason: Option, - pub published: DateTime, + pub when_: DateTime, } #[derive(Clone, Default)] @@ -161,7 +161,7 @@ pub struct AdminBlockInstance { pub reason: Option, #[cfg_attr(feature = "full", ts(optional))] pub expires: Option>, - pub published: DateTime, + pub when_: DateTime, } #[derive(Clone, Default)] @@ -172,5 +172,5 @@ pub struct AdminBlockInstanceForm { pub admin_person_id: PersonId, pub blocked: bool, pub reason: Option, - pub expires: Option>, + pub when_: Option>, } diff --git a/crates/db_views_moderator/src/admin_allow_instance.rs b/crates/db_views_moderator/src/admin_allow_instance.rs index 9489e194b..2a0aaad14 100644 --- a/crates/db_views_moderator/src/admin_allow_instance.rs +++ b/crates/db_views_moderator/src/admin_allow_instance.rs @@ -45,7 +45,7 @@ impl AdminAllowInstanceView { query .limit(limit) .offset(offset) - .order_by(admin_allow_instance::published.desc()) + .order_by(admin_allow_instance::when_.desc()) .load::(conn) .await } diff --git a/crates/db_views_moderator/src/admin_block_instance.rs b/crates/db_views_moderator/src/admin_block_instance.rs index 3b267bd63..e9d7c8b0d 100644 --- a/crates/db_views_moderator/src/admin_block_instance.rs +++ b/crates/db_views_moderator/src/admin_block_instance.rs @@ -45,7 +45,7 @@ impl AdminBlockInstanceView { query .limit(limit) .offset(offset) - .order_by(admin_block_instance::published.desc()) + .order_by(admin_block_instance::when_.desc()) .load::(conn) .await } diff --git a/migrations/2024-11-19-142005_instance-block-mod-log/down.sql b/migrations/2024-11-28-142005_instance-block-mod-log/down.sql similarity index 100% rename from migrations/2024-11-19-142005_instance-block-mod-log/down.sql rename to migrations/2024-11-28-142005_instance-block-mod-log/down.sql diff --git a/migrations/2024-11-19-142005_instance-block-mod-log/up.sql b/migrations/2024-11-28-142005_instance-block-mod-log/up.sql similarity index 87% rename from migrations/2024-11-19-142005_instance-block-mod-log/up.sql rename to migrations/2024-11-28-142005_instance-block-mod-log/up.sql index fbe0af66c..f537f5d32 100644 --- a/migrations/2024-11-19-142005_instance-block-mod-log/up.sql +++ b/migrations/2024-11-28-142005_instance-block-mod-log/up.sql @@ -8,7 +8,7 @@ CREATE TABLE admin_block_instance ( blocked bool NOT NULL, reason text, expires timestamptz, - published timestamptz NOT NULL DEFAULT now() + when_ timestamptz NOT NULL DEFAULT now() ); CREATE TABLE admin_allow_instance ( @@ -17,6 +17,6 @@ CREATE TABLE admin_allow_instance ( admin_person_id int NOT NULL REFERENCES person (id) ON UPDATE CASCADE ON DELETE CASCADE, allowed bool NOT NULL, reason text, - published timestamptz NOT NULL DEFAULT now() + when_ timestamptz NOT NULL DEFAULT now() ); diff --git a/src/scheduled_tasks.rs b/src/scheduled_tasks.rs index d52290a97..52962877f 100644 --- a/src/scheduled_tasks.rs +++ b/src/scheduled_tasks.rs @@ -59,6 +59,7 @@ pub async fn setup(context: Data) -> LemmyResult<()> { async move { active_counts(&mut context.pool()).await; update_banned_when_expired(&mut context.pool()).await; + delete_instance_block_when_expired(&mut context.pool()).await; } }); @@ -114,6 +115,7 @@ async fn startup_jobs(pool: &mut DbPool<'_>) { active_counts(pool).await; update_hot_ranks(pool).await; update_banned_when_expired(pool).await; + delete_instance_block_when_expired(pool).await; clear_old_activities(pool).await; overwrite_deleted_posts_and_comments(pool).await; delete_old_denied_users(pool).await; @@ -440,7 +442,20 @@ async fn update_banned_when_expired(pool: &mut DbPool<'_>) { .await .inspect_err(|e| error!("Failed to remove community_ban expired rows: {e}")) .ok(); + } + Err(e) => { + error!("Failed to get connection from pool: {e}"); + } + } +} +/// Set banned to false after ban expires +async fn delete_instance_block_when_expired(pool: &mut DbPool<'_>) { + info!("Delete instance blocks when expired ..."); + let conn = get_conn(pool).await; + + match conn { + Ok(mut conn) => { diesel::delete( federation_blocklist::table.filter(federation_blocklist::expires.lt(now().nullable())), )