mirror of https://github.com/LemmyNet/lemmy
Receive & store remote site bans
parent
95069d7648
commit
6592fcfaa3
@ -0,0 +1,25 @@
|
||||
use crate::structs::SitePersonBanView;
|
||||
use diesel::{dsl::exists, result::Error, select, ExpressionMethods, QueryDsl};
|
||||
use diesel_async::RunQueryDsl;
|
||||
use lemmy_db_schema::{
|
||||
newtypes::{PersonId, SiteId},
|
||||
schema::site_person_ban,
|
||||
utils::{get_conn, DbPool},
|
||||
};
|
||||
|
||||
impl SitePersonBanView {
|
||||
pub async fn get(
|
||||
pool: &mut DbPool<'_>,
|
||||
from_person_id: PersonId,
|
||||
from_site_id: SiteId,
|
||||
) -> Result<bool, Error> {
|
||||
let conn = &mut get_conn(pool).await?;
|
||||
select(exists(
|
||||
site_person_ban::table
|
||||
.filter(site_person_ban::site_id.eq(from_site_id))
|
||||
.filter(site_person_ban::person_id.eq(from_person_id)),
|
||||
))
|
||||
.get_result::<bool>(conn)
|
||||
.await
|
||||
}
|
||||
}
|
@ -0,0 +1 @@
|
||||
DROP TABLE site_person_ban;
|
@ -0,0 +1,13 @@
|
||||
CREATE TABLE site_person_ban
|
||||
(
|
||||
site_id INTEGER NOT NULL
|
||||
REFERENCES site
|
||||
ON UPDATE CASCADE ON DELETE CASCADE,
|
||||
person_id INTEGER NOT NULL
|
||||
REFERENCES person
|
||||
ON UPDATE CASCADE ON DELETE CASCADE,
|
||||
published TIMESTAMP WITH TIME ZONE DEFAULT NOW() NOT NULL,
|
||||
expires TIMESTAMP WITH TIME ZONE,
|
||||
PRIMARY KEY (person_id, site_id)
|
||||
);
|
||||
|
Loading…
Reference in New Issue