lemmy/crates/db_views_actor/src/community_person_ban_view.rs
Nutomic 9e099726e6
Cleanup checks for community actions (fixes #2858, fixes #2868) (#4028)
* Cleanup checks for community actions (fixes #2858, fixes #2868)

* allow restoring deleted community

* review changes

* remove unneeded sql

* remove joins

* change mod log check
2023-10-13 09:48:18 -04:00

26 lines
744 B
Rust

use crate::structs::CommunityPersonBanView;
use diesel::{dsl::exists, result::Error, select, ExpressionMethods, QueryDsl};
use diesel_async::RunQueryDsl;
use lemmy_db_schema::{
newtypes::{CommunityId, PersonId},
schema::community_person_ban,
utils::{get_conn, DbPool},
};
impl CommunityPersonBanView {
pub async fn get(
pool: &mut DbPool<'_>,
from_person_id: PersonId,
from_community_id: CommunityId,
) -> Result<bool, Error> {
let conn = &mut get_conn(pool).await?;
select(exists(
community_person_ban::table
.filter(community_person_ban::community_id.eq(from_community_id))
.filter(community_person_ban::person_id.eq(from_person_id)),
))
.get_result::<bool>(conn)
.await
}
}