Dont allow blocking admin (#2340)

revert-2326-Nutomic-patch-6
Nutomic 2022-07-05 23:02:54 +00:00 committed by GitHub
parent ddc9763050
commit 3ef812660c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 10 additions and 6 deletions

View File

@ -39,6 +39,15 @@ impl Perform for BlockPerson {
target_id, 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 { if data.block {
let block = move |conn: &'_ _| PersonBlock::block(conn, &person_block_form); let block = move |conn: &'_ _| PersonBlock::block(conn, &person_block_form);
blocking(context.pool(), block) blocking(context.pool(), block)
@ -51,13 +60,8 @@ impl Perform for BlockPerson {
.map_err(|e| LemmyError::from_error_message(e, "person_block_already_exists"))?; .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 { let res = BlockPersonResponse {
person_view, person_view: target_person_view,
blocked: data.block, blocked: data.block,
}; };