From: Nutomic Date: Tue, 5 Jul 2022 23:02:54 +0000 (+0000) Subject: Dont allow blocking admin (#2340) X-Git-Url: http://these/git/%22https:/nerdica.net/photo/contact/80/%24%7BappleTouchIcon%7D?a=commitdiff_plain;h=3ef812660cb835adeb1671bd853241a6cbf88340;p=lemmy.git Dont allow blocking admin (#2340) --- 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, };