-
-
Notifications
You must be signed in to change notification settings - Fork 885
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Receive & store remote site bans #4571
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -35,7 +35,7 @@ use lemmy_db_schema::{ | |
CommunityPersonBanForm, | ||
}, | ||
moderator::{ModBan, ModBanForm, ModBanFromCommunity, ModBanFromCommunityForm}, | ||
person::{Person, PersonUpdateForm}, | ||
site::{SitePersonBan, SitePersonBanForm}, | ||
}, | ||
traits::{Bannable, Crud, Followable}, | ||
}; | ||
|
@@ -155,19 +155,26 @@ impl ActivityHandler for BlockUser { | |
let blocked_person = self.object.dereference(context).await?; | ||
let target = self.target.dereference(context).await?; | ||
match target { | ||
SiteOrCommunity::Site(_site) => { | ||
let blocked_person = Person::update( | ||
&mut context.pool(), | ||
blocked_person.id, | ||
&PersonUpdateForm { | ||
banned: Some(true), | ||
ban_expires: Some(expires), | ||
..Default::default() | ||
}, | ||
) | ||
.await?; | ||
SiteOrCommunity::Site(site) => { | ||
let site_user_ban_form = SitePersonBanForm { | ||
site_id: site.id, | ||
person_id: blocked_person.id, | ||
expires: Some(expires), | ||
}; | ||
SitePersonBan::ban(&mut context.pool(), &site_user_ban_form).await?; | ||
if self.remove_data.unwrap_or(false) { | ||
remove_user_data(blocked_person.id, context).await?; | ||
let user_banned_on_home_instance = verify_domains_match(&site.id(), self.actor.inner())? | ||
&& verify_domains_match(&site.id(), self.object.inner())?; | ||
if user_banned_on_home_instance { | ||
remove_user_data(blocked_person.id, context).await?; | ||
} else { | ||
// Currently, remote site bans federate data removal through corresponding community | ||
// bans, because remote site bans were not even stored unless they came from the user's | ||
// home instance. We can continue to use community bans to federate data removal for | ||
// backwards compatibility, initially but at some point, when most instances have been | ||
// upgraded to have the logic of storing remote site bans, we can start doing data | ||
// removal here & remove the logic of federating community bans on remote site bans. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I agree with this, I'd love to remove my weird logic for banning them from local communities. |
||
} | ||
} | ||
|
||
// write mod log | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
use crate::newtypes::{DbUrl, InstanceId, SiteId}; | ||
use crate::newtypes::{CommunityId, DbUrl, InstanceId, PersonId, SiteId}; | ||
#[cfg(feature = "full")] | ||
use crate::schema::site; | ||
use chrono::{DateTime, Utc}; | ||
|
@@ -84,3 +84,28 @@ pub struct SiteUpdateForm { | |
pub public_key: Option<String>, | ||
pub content_warning: Option<Option<String>>, | ||
} | ||
|
||
#[derive(PartialEq, Eq, Debug)] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Add |
||
#[cfg_attr( | ||
feature = "full", | ||
derive(Identifiable, Queryable, Selectable, Associations) | ||
)] | ||
#[cfg_attr(feature = "full", diesel(belongs_to(crate::source::site::Site)))] | ||
#[cfg_attr(feature = "full", diesel(table_name = site_person_ban))] | ||
#[cfg_attr(feature = "full", diesel(primary_key(person_id, site_id)))] | ||
#[cfg_attr(feature = "full", diesel(check_for_backend(diesel::pg::Pg)))] | ||
pub struct SitePersonBan { | ||
pub site_id: SiteId, | ||
pub person_id: PersonId, | ||
pub published: DateTime<Utc>, | ||
pub expires: Option<DateTime<Utc>>, | ||
} | ||
|
||
#[derive(Clone)] | ||
#[cfg_attr(feature = "full", derive(Insertable, AsChangeset))] | ||
#[cfg_attr(feature = "full", diesel(table_name = site_person_ban))] | ||
pub struct SitePersonBanForm { | ||
pub site_id: SiteId, | ||
pub person_id: PersonId, | ||
pub expires: Option<Option<DateTime<Utc>>>, | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -149,3 +149,12 @@ pub struct PersonView { | |
pub counts: PersonAggregates, | ||
pub is_admin: bool, | ||
} | ||
|
||
#[derive(Debug, Serialize, Deserialize, Clone)] | ||
#[cfg_attr(feature = "full", derive(Queryable))] | ||
#[cfg_attr(feature = "full", diesel(check_for_backend(diesel::pg::Pg)))] | ||
/// A site person ban. | ||
pub struct SitePersonBanView { | ||
pub site: Site, | ||
pub person: Person, | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The view might not be necessary, since we're not returning this view specifically, but only fields joined from Same for |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
DROP TABLE site_person_ban; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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) | ||
); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Looks good. |
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thoughts on adding a separate error here, like
BannedFromSiteHostingCommunity
or something?