diff --git a/crates/api/src/site/user_block_instance.rs b/crates/api/src/site/user_block_instance.rs index 00722d460..940538833 100644 --- a/crates/api/src/site/user_block_instance.rs +++ b/crates/api/src/site/user_block_instance.rs @@ -1,9 +1,6 @@ use activitypub_federation::config::Data; use actix_web::web::Json; -use lemmy_api_common::{ - context::LemmyContext, - site::{BlockInstance, BlockInstanceResponse}, -}; +use lemmy_api_common::{context::LemmyContext, site::UserBlockInstanceParams, SuccessResponse}; use lemmy_db_schema::{ source::instance_block::{InstanceBlock, InstanceBlockForm}, traits::Blockable, @@ -13,10 +10,10 @@ use lemmy_utils::error::{LemmyErrorExt, LemmyErrorType, LemmyResult}; #[tracing::instrument(skip(context))] pub async fn user_block_instance( - data: Json, + data: Json, local_user_view: LocalUserView, context: Data, -) -> LemmyResult> { +) -> LemmyResult> { let instance_id = data.instance_id; let person_id = local_user_view.person.id; if local_user_view.person.instance_id == instance_id { @@ -38,7 +35,5 @@ pub async fn user_block_instance( .with_lemmy_type(LemmyErrorType::InstanceBlockAlreadyExists)?; } - Ok(Json(BlockInstanceResponse { - blocked: data.block, - })) + Ok(Json(SuccessResponse::default())) } diff --git a/crates/api_common/src/site.rs b/crates/api_common/src/site.rs index 9a0425048..f40be2bdf 100644 --- a/crates/api_common/src/site.rs +++ b/crates/api_common/src/site.rs @@ -652,19 +652,11 @@ pub struct GetUnreadRegistrationApplicationCountResponse { #[cfg_attr(feature = "full", derive(TS))] #[cfg_attr(feature = "full", ts(export))] /// Block an instance as user -pub struct BlockInstance { +pub struct UserBlockInstanceParams { pub instance_id: InstanceId, pub block: bool, } -#[skip_serializing_none] -#[derive(Debug, Serialize, Deserialize, Clone)] -#[cfg_attr(feature = "full", derive(TS))] -#[cfg_attr(feature = "full", ts(export))] -pub struct BlockInstanceResponse { - pub blocked: bool, -} - #[derive(Debug, Serialize, Deserialize, Clone, Default, PartialEq, Eq, Hash)] #[cfg_attr(feature = "full", derive(TS))] #[cfg_attr(feature = "full", ts(export))] diff --git a/crates/db_schema/src/impls/federation_allowlist.rs b/crates/db_schema/src/impls/federation_allowlist.rs index e2852f166..1c3c98264 100644 --- a/crates/db_schema/src/impls/federation_allowlist.rs +++ b/crates/db_schema/src/impls/federation_allowlist.rs @@ -36,13 +36,12 @@ impl AdminAllowInstance { }) .await } - pub async fn unallow(pool: &mut DbPool<'_>, instance_id: InstanceId) -> Result<(), Error> { + pub async fn unallow(pool: &mut DbPool<'_>, instance_id_: InstanceId) -> Result<(), Error> { + use federation_allowlist::dsl::instance_id; let conn = &mut get_conn(pool).await?; - delete( - federation_allowlist::table.filter(federation_allowlist::dsl::instance_id.eq(instance_id)), - ) - .execute(conn) - .await?; + delete(federation_allowlist::table.filter(instance_id.eq(instance_id_))) + .execute(conn) + .await?; Ok(()) } } diff --git a/crates/db_schema/src/impls/federation_blocklist.rs b/crates/db_schema/src/impls/federation_blocklist.rs index 3751c19c5..f05639d9c 100644 --- a/crates/db_schema/src/impls/federation_blocklist.rs +++ b/crates/db_schema/src/impls/federation_blocklist.rs @@ -26,7 +26,7 @@ impl AdminBlockInstance { let form2 = FederationBlockListForm { instance_id: form.instance_id, updated: None, - block_expires: form.expires, + expires: form.expires, }; insert_into(federation_blocklist::table) .values(form2) diff --git a/crates/db_schema/src/schema.rs b/crates/db_schema/src/schema.rs index e714bf1aa..1ed8e3075 100644 --- a/crates/db_schema/src/schema.rs +++ b/crates/db_schema/src/schema.rs @@ -303,7 +303,7 @@ diesel::table! { instance_id -> Int4, published -> Timestamptz, updated -> Nullable, - block_expires -> Nullable, + expires -> Nullable, } } diff --git a/crates/db_schema/src/source/federation_blocklist.rs b/crates/db_schema/src/source/federation_blocklist.rs index 52e8773b2..79567662f 100644 --- a/crates/db_schema/src/source/federation_blocklist.rs +++ b/crates/db_schema/src/source/federation_blocklist.rs @@ -27,7 +27,7 @@ pub struct FederationBlockList { #[cfg_attr(feature = "full", ts(optional))] pub updated: Option>, #[cfg_attr(feature = "full", ts(optional))] - pub block_expires: Option>, + pub expires: Option>, } #[derive(Clone, Default)] @@ -36,7 +36,7 @@ pub struct FederationBlockList { pub(crate) struct FederationBlockListForm { pub instance_id: InstanceId, pub updated: Option>, - pub block_expires: Option>, + pub expires: Option>, } #[derive(Clone, PartialEq, Eq, Debug, Serialize, Deserialize)] diff --git a/migrations/2024-11-19-142005_instance-block-mod-log/down.sql b/migrations/2024-11-19-142005_instance-block-mod-log/down.sql index c67409c89..7936cfe7c 100644 --- a/migrations/2024-11-19-142005_instance-block-mod-log/down.sql +++ b/migrations/2024-11-19-142005_instance-block-mod-log/down.sql @@ -1,5 +1,5 @@ ALTER TABLE federation_blocklist - DROP block_expires; + DROP expires; DROP TABLE admin_block_instance; diff --git a/migrations/2024-11-19-142005_instance-block-mod-log/up.sql b/migrations/2024-11-19-142005_instance-block-mod-log/up.sql index 53f91195f..e02312547 100644 --- a/migrations/2024-11-19-142005_instance-block-mod-log/up.sql +++ b/migrations/2024-11-19-142005_instance-block-mod-log/up.sql @@ -1,5 +1,5 @@ ALTER TABLE federation_blocklist - ADD COLUMN block_expires timestamptz; + ADD COLUMN expires timestamptz; CREATE TABLE admin_block_instance ( id serial PRIMARY KEY, diff --git a/src/scheduled_tasks.rs b/src/scheduled_tasks.rs index 05dc99b15..75570752e 100644 --- a/src/scheduled_tasks.rs +++ b/src/scheduled_tasks.rs @@ -443,7 +443,7 @@ async fn update_banned_when_expired(pool: &mut DbPool<'_>) { diesel::delete( federation_blocklist::table - .filter(federation_blocklist::block_expires.lt(now().nullable())), + .filter(federation_blocklist::expires.lt(now().nullable())), ) .execute(&mut conn) .await