address comments

This commit is contained in:
Felix Ableitner 2024-11-28 11:26:02 +01:00
parent 809095f1fc
commit 74668f7e17
10 changed files with 25 additions and 12 deletions

View file

@ -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);

View file

@ -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 {

View file

@ -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?;

View file

@ -49,7 +49,7 @@ diesel::table! {
admin_person_id -> Int4,
allowed -> Bool,
reason -> Nullable<Text>,
published -> Timestamptz,
when_ -> Timestamptz,
}
}
@ -61,7 +61,7 @@ diesel::table! {
blocked -> Bool,
reason -> Nullable<Text>,
expires -> Nullable<Timestamptz>,
published -> Timestamptz,
when_ -> Timestamptz,
}
}

View file

@ -126,7 +126,7 @@ pub struct AdminAllowInstance {
pub allowed: bool,
#[cfg_attr(feature = "full", ts(optional))]
pub reason: Option<String>,
pub published: DateTime<Utc>,
pub when_: DateTime<Utc>,
}
#[derive(Clone, Default)]
@ -161,7 +161,7 @@ pub struct AdminBlockInstance {
pub reason: Option<String>,
#[cfg_attr(feature = "full", ts(optional))]
pub expires: Option<DateTime<Utc>>,
pub published: DateTime<Utc>,
pub when_: DateTime<Utc>,
}
#[derive(Clone, Default)]
@ -172,5 +172,5 @@ pub struct AdminBlockInstanceForm {
pub admin_person_id: PersonId,
pub blocked: bool,
pub reason: Option<String>,
pub expires: Option<DateTime<Utc>>,
pub when_: Option<DateTime<Utc>>,
}

View file

@ -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::<Self>(conn)
.await
}

View file

@ -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::<Self>(conn)
.await
}

View file

@ -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()
);

View file

@ -59,6 +59,7 @@ pub async fn setup(context: Data<LemmyContext>) -> 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())),
)