Skip to content

Commit aa8767c

Browse files
committed
add column mod_ban.instance_id
1 parent 900eb1d commit aa8767c

File tree

7 files changed

+24
-11
lines changed

7 files changed

+24
-11
lines changed

crates/api/src/local_user/ban_person.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ pub async fn ban_from_site(
8181
reason: data.reason.clone(),
8282
banned: Some(data.ban),
8383
expires,
84+
instance_id: local_user_view.person.instance_id,
8485
};
8586

8687
ModBan::create(&mut context.pool(), &form).await?;

crates/apub/src/activities/block/block_user.rs

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -159,26 +159,27 @@ impl ActivityHandler for BlockUser {
159159
..Default::default()
160160
};
161161
Person::update(&mut context.pool(), blocked_person.id, &form).await?;
162+
163+
if self.remove_data.unwrap_or(false) {
164+
// TODO: only remove content in communities belonging to that instance
165+
remove_or_restore_user_data(mod_person.id, blocked_person.id, true, &reason, context)
166+
.await?;
167+
}
162168
} else {
163169
// user banned from remote instance, write to instance actions table and remove content
164170
// only in communities from that instance
165171
let form = InstanceBanForm::new(blocked_person.id, site.instance_id, expires);
166172
InstanceActions::ban(&mut context.pool(), &form).await?;
167173
}
168174

169-
if self.remove_data.unwrap_or(false) {
170-
// TODO: only remove content in communities belonging to that instance
171-
remove_or_restore_user_data(mod_person.id, blocked_person.id, true, &reason, context)
172-
.await?;
173-
}
174-
175175
// write mod log
176176
let form = ModBanForm {
177177
mod_person_id: mod_person.id,
178178
other_person_id: blocked_person.id,
179179
reason,
180180
banned: Some(true),
181181
expires,
182+
instance_id: site.instance_id,
182183
};
183184
ModBan::create(&mut context.pool(), &form).await?;
184185
}

crates/apub/src/activities/block/undo_block_user.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,10 @@ impl ActivityHandler for UndoBlockUser {
104104
SiteOrCommunity::Site(site) => {
105105
verify_is_public(&self.to, &self.cc)?;
106106
if blocked_person.instance_id == site.instance_id {
107+
if self.restore_data.unwrap_or(false) {
108+
remove_or_restore_user_data(mod_person.id, blocked_person.id, false, &None, context)
109+
.await?;
110+
}
107111
// user unbanned from home instance, write directly to person table
108112
let form = PersonUpdateForm {
109113
banned: Some(true),
@@ -117,18 +121,14 @@ impl ActivityHandler for UndoBlockUser {
117121
InstanceActions::unban(&mut context.pool(), &form).await?;
118122
}
119123

120-
if self.restore_data.unwrap_or(false) {
121-
remove_or_restore_user_data(mod_person.id, blocked_person.id, false, &None, context)
122-
.await?;
123-
}
124-
125124
// write mod log
126125
let form = ModBanForm {
127126
mod_person_id: mod_person.id,
128127
other_person_id: blocked_person.id,
129128
reason: self.object.summary,
130129
banned: Some(false),
131130
expires,
131+
instance_id: site.instance_id,
132132
};
133133
ModBan::create(&mut context.pool(), &form).await?;
134134
}

crates/db_schema/src/schema.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -574,6 +574,7 @@ diesel::table! {
574574
banned -> Bool,
575575
expires -> Nullable<Timestamptz>,
576576
published -> Timestamptz,
577+
instance_id -> Int4,
577578
}
578579
}
579580

crates/db_schema/src/source/mod_log/moderator.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ use crate::{
1616
newtypes::{
1717
CommentId,
1818
CommunityId,
19+
InstanceId,
1920
ModAddCommunityId,
2021
ModAddId,
2122
ModBanFromCommunityId,
@@ -210,6 +211,7 @@ pub struct ModBan {
210211
#[cfg_attr(feature = "full", ts(optional))]
211212
pub expires: Option<DateTime<Utc>>,
212213
pub published: DateTime<Utc>,
214+
pub instance_id: InstanceId,
213215
}
214216

215217
#[cfg_attr(feature = "full", derive(Insertable, AsChangeset))]
@@ -245,6 +247,7 @@ pub struct ModBanForm {
245247
pub reason: Option<String>,
246248
pub banned: Option<bool>,
247249
pub expires: Option<DateTime<Utc>>,
250+
pub instance_id: InstanceId,
248251
}
249252

250253
#[derive(Clone, PartialEq, Eq, Debug, Serialize, Deserialize)]

migrations/2025-03-17-110023_site_person_ban/down.sql

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,6 @@ ALTER TABLE instance_actions
44
ALTER TABLE instance_actions
55
DROP COLUMN ban_expires;
66

7+
ALTER TABLE mod_ban
8+
DROP COLUMN instance_id;
9+

migrations/2025-03-17-110023_site_person_ban/up.sql

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,7 @@ ALTER TABLE instance_actions
44
ALTER TABLE instance_actions
55
ADD COLUMN ban_expires timestamptz;
66

7+
-- TODO: could be not null
8+
ALTER TABLE mod_ban
9+
ADD COLUMN instance_id int NOT NULL REFERENCES instance ON UPDATE CASCADE ON DELETE CASCADE;
10+

0 commit comments

Comments
 (0)