mirror of
https://github.com/LemmyNet/lemmy.git
synced 2024-11-22 09:21:01 +00:00
more changes
This commit is contained in:
parent
34d1d906a1
commit
0670552adb
9 changed files with 17 additions and 31 deletions
|
@ -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<BlockInstance>,
|
||||
data: Json<UserBlockInstanceParams>,
|
||||
local_user_view: LocalUserView,
|
||||
context: Data<LemmyContext>,
|
||||
) -> LemmyResult<Json<BlockInstanceResponse>> {
|
||||
) -> LemmyResult<Json<SuccessResponse>> {
|
||||
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()))
|
||||
}
|
||||
|
|
|
@ -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))]
|
||||
|
|
|
@ -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(())
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -303,7 +303,7 @@ diesel::table! {
|
|||
instance_id -> Int4,
|
||||
published -> Timestamptz,
|
||||
updated -> Nullable<Timestamptz>,
|
||||
block_expires -> Nullable<Timestamptz>,
|
||||
expires -> Nullable<Timestamptz>,
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -27,7 +27,7 @@ pub struct FederationBlockList {
|
|||
#[cfg_attr(feature = "full", ts(optional))]
|
||||
pub updated: Option<DateTime<Utc>>,
|
||||
#[cfg_attr(feature = "full", ts(optional))]
|
||||
pub block_expires: Option<DateTime<Utc>>,
|
||||
pub expires: Option<DateTime<Utc>>,
|
||||
}
|
||||
|
||||
#[derive(Clone, Default)]
|
||||
|
@ -36,7 +36,7 @@ pub struct FederationBlockList {
|
|||
pub(crate) struct FederationBlockListForm {
|
||||
pub instance_id: InstanceId,
|
||||
pub updated: Option<DateTime<Utc>>,
|
||||
pub block_expires: Option<DateTime<Utc>>,
|
||||
pub expires: Option<DateTime<Utc>>,
|
||||
}
|
||||
|
||||
#[derive(Clone, PartialEq, Eq, Debug, Serialize, Deserialize)]
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
ALTER TABLE federation_blocklist
|
||||
DROP block_expires;
|
||||
DROP expires;
|
||||
|
||||
DROP TABLE admin_block_instance;
|
||||
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue