mirror of
https://github.com/LemmyNet/lemmy.git
synced 2024-11-25 22:01:19 +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 activitypub_federation::config::Data;
|
||||||
use actix_web::web::Json;
|
use actix_web::web::Json;
|
||||||
use lemmy_api_common::{
|
use lemmy_api_common::{context::LemmyContext, site::UserBlockInstanceParams, SuccessResponse};
|
||||||
context::LemmyContext,
|
|
||||||
site::{BlockInstance, BlockInstanceResponse},
|
|
||||||
};
|
|
||||||
use lemmy_db_schema::{
|
use lemmy_db_schema::{
|
||||||
source::instance_block::{InstanceBlock, InstanceBlockForm},
|
source::instance_block::{InstanceBlock, InstanceBlockForm},
|
||||||
traits::Blockable,
|
traits::Blockable,
|
||||||
|
@ -13,10 +10,10 @@ use lemmy_utils::error::{LemmyErrorExt, LemmyErrorType, LemmyResult};
|
||||||
|
|
||||||
#[tracing::instrument(skip(context))]
|
#[tracing::instrument(skip(context))]
|
||||||
pub async fn user_block_instance(
|
pub async fn user_block_instance(
|
||||||
data: Json<BlockInstance>,
|
data: Json<UserBlockInstanceParams>,
|
||||||
local_user_view: LocalUserView,
|
local_user_view: LocalUserView,
|
||||||
context: Data<LemmyContext>,
|
context: Data<LemmyContext>,
|
||||||
) -> LemmyResult<Json<BlockInstanceResponse>> {
|
) -> LemmyResult<Json<SuccessResponse>> {
|
||||||
let instance_id = data.instance_id;
|
let instance_id = data.instance_id;
|
||||||
let person_id = local_user_view.person.id;
|
let person_id = local_user_view.person.id;
|
||||||
if local_user_view.person.instance_id == instance_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)?;
|
.with_lemmy_type(LemmyErrorType::InstanceBlockAlreadyExists)?;
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(Json(BlockInstanceResponse {
|
Ok(Json(SuccessResponse::default()))
|
||||||
blocked: data.block,
|
|
||||||
}))
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -652,19 +652,11 @@ pub struct GetUnreadRegistrationApplicationCountResponse {
|
||||||
#[cfg_attr(feature = "full", derive(TS))]
|
#[cfg_attr(feature = "full", derive(TS))]
|
||||||
#[cfg_attr(feature = "full", ts(export))]
|
#[cfg_attr(feature = "full", ts(export))]
|
||||||
/// Block an instance as user
|
/// Block an instance as user
|
||||||
pub struct BlockInstance {
|
pub struct UserBlockInstanceParams {
|
||||||
pub instance_id: InstanceId,
|
pub instance_id: InstanceId,
|
||||||
pub block: bool,
|
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)]
|
#[derive(Debug, Serialize, Deserialize, Clone, Default, PartialEq, Eq, Hash)]
|
||||||
#[cfg_attr(feature = "full", derive(TS))]
|
#[cfg_attr(feature = "full", derive(TS))]
|
||||||
#[cfg_attr(feature = "full", ts(export))]
|
#[cfg_attr(feature = "full", ts(export))]
|
||||||
|
|
|
@ -36,11 +36,10 @@ impl AdminAllowInstance {
|
||||||
})
|
})
|
||||||
.await
|
.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?;
|
let conn = &mut get_conn(pool).await?;
|
||||||
delete(
|
delete(federation_allowlist::table.filter(instance_id.eq(instance_id_)))
|
||||||
federation_allowlist::table.filter(federation_allowlist::dsl::instance_id.eq(instance_id)),
|
|
||||||
)
|
|
||||||
.execute(conn)
|
.execute(conn)
|
||||||
.await?;
|
.await?;
|
||||||
Ok(())
|
Ok(())
|
||||||
|
|
|
@ -26,7 +26,7 @@ impl AdminBlockInstance {
|
||||||
let form2 = FederationBlockListForm {
|
let form2 = FederationBlockListForm {
|
||||||
instance_id: form.instance_id,
|
instance_id: form.instance_id,
|
||||||
updated: None,
|
updated: None,
|
||||||
block_expires: form.expires,
|
expires: form.expires,
|
||||||
};
|
};
|
||||||
insert_into(federation_blocklist::table)
|
insert_into(federation_blocklist::table)
|
||||||
.values(form2)
|
.values(form2)
|
||||||
|
|
|
@ -303,7 +303,7 @@ diesel::table! {
|
||||||
instance_id -> Int4,
|
instance_id -> Int4,
|
||||||
published -> Timestamptz,
|
published -> Timestamptz,
|
||||||
updated -> Nullable<Timestamptz>,
|
updated -> Nullable<Timestamptz>,
|
||||||
block_expires -> Nullable<Timestamptz>,
|
expires -> Nullable<Timestamptz>,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -27,7 +27,7 @@ pub struct FederationBlockList {
|
||||||
#[cfg_attr(feature = "full", ts(optional))]
|
#[cfg_attr(feature = "full", ts(optional))]
|
||||||
pub updated: Option<DateTime<Utc>>,
|
pub updated: Option<DateTime<Utc>>,
|
||||||
#[cfg_attr(feature = "full", ts(optional))]
|
#[cfg_attr(feature = "full", ts(optional))]
|
||||||
pub block_expires: Option<DateTime<Utc>>,
|
pub expires: Option<DateTime<Utc>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone, Default)]
|
#[derive(Clone, Default)]
|
||||||
|
@ -36,7 +36,7 @@ pub struct FederationBlockList {
|
||||||
pub(crate) struct FederationBlockListForm {
|
pub(crate) struct FederationBlockListForm {
|
||||||
pub instance_id: InstanceId,
|
pub instance_id: InstanceId,
|
||||||
pub updated: Option<DateTime<Utc>>,
|
pub updated: Option<DateTime<Utc>>,
|
||||||
pub block_expires: Option<DateTime<Utc>>,
|
pub expires: Option<DateTime<Utc>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone, PartialEq, Eq, Debug, Serialize, Deserialize)]
|
#[derive(Clone, PartialEq, Eq, Debug, Serialize, Deserialize)]
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
ALTER TABLE federation_blocklist
|
ALTER TABLE federation_blocklist
|
||||||
DROP block_expires;
|
DROP expires;
|
||||||
|
|
||||||
DROP TABLE admin_block_instance;
|
DROP TABLE admin_block_instance;
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
ALTER TABLE federation_blocklist
|
ALTER TABLE federation_blocklist
|
||||||
ADD COLUMN block_expires timestamptz;
|
ADD COLUMN expires timestamptz;
|
||||||
|
|
||||||
CREATE TABLE admin_block_instance (
|
CREATE TABLE admin_block_instance (
|
||||||
id serial PRIMARY KEY,
|
id serial PRIMARY KEY,
|
||||||
|
|
|
@ -443,7 +443,7 @@ async fn update_banned_when_expired(pool: &mut DbPool<'_>) {
|
||||||
|
|
||||||
diesel::delete(
|
diesel::delete(
|
||||||
federation_blocklist::table
|
federation_blocklist::table
|
||||||
.filter(federation_blocklist::block_expires.lt(now().nullable())),
|
.filter(federation_blocklist::expires.lt(now().nullable())),
|
||||||
)
|
)
|
||||||
.execute(&mut conn)
|
.execute(&mut conn)
|
||||||
.await
|
.await
|
||||||
|
|
Loading…
Reference in a new issue