]> Untitled Git - lemmy.git/commitdiff
Dont allow blocking admin (#2340)
authorNutomic <me@nutomic.com>
Tue, 5 Jul 2022 23:02:54 +0000 (23:02 +0000)
committerGitHub <noreply@github.com>
Tue, 5 Jul 2022 23:02:54 +0000 (23:02 +0000)
crates/api/src/local_user/block.rs

index 4878cb02045d1ae49bcf292379fa3ac5b6ef791d..da21dcdd8872042f3a9d75ad3bf31457e8f52546 100644 (file)
@@ -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,
     };