From 3ef812660cb835adeb1671bd853241a6cbf88340 Mon Sep 17 00:00:00 2001 From: Nutomic Date: Tue, 5 Jul 2022 23:02:54 +0000 Subject: [PATCH] Dont allow blocking admin (#2340) --- crates/api/src/local_user/block.rs | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/crates/api/src/local_user/block.rs b/crates/api/src/local_user/block.rs index 4878cb02..da21dcdd 100644 --- a/crates/api/src/local_user/block.rs +++ b/crates/api/src/local_user/block.rs @@ -39,6 +39,15 @@ impl Perform for BlockPerson { target_id, }; + let target_person_view = blocking(context.pool(), move |conn| { + PersonViewSafe::read(conn, target_id) + }) + .await??; + + if target_person_view.person.admin { + return Err(LemmyError::from_message("cant_block_admin")); + } + if data.block { let block = move |conn: &'_ _| PersonBlock::block(conn, &person_block_form); blocking(context.pool(), block) @@ -51,13 +60,8 @@ impl Perform for BlockPerson { .map_err(|e| LemmyError::from_error_message(e, "person_block_already_exists"))?; } - let person_view = blocking(context.pool(), move |conn| { - PersonViewSafe::read(conn, target_id) - }) - .await??; - let res = BlockPersonResponse { - person_view, + person_view: target_person_view, blocked: data.block, }; -- 2.44.1