Skip to content

Commit

Permalink
Fix federation of unban action (fixes #5454)
Browse files Browse the repository at this point in the history
  • Loading branch information
Nutomic committed Feb 26, 2025
1 parent 493734d commit 284df5b
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 14 deletions.
14 changes: 12 additions & 2 deletions api_tests/src/post.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ import {
listReports,
getMyUser,
listInbox,
getModlog,
} from "./shared";
import { PostView } from "lemmy-js-client/dist/types/PostView";
import { AdminBlockInstanceParams } from "lemmy-js-client/dist/types/AdminBlockInstanceParams";
Expand Down Expand Up @@ -651,8 +652,17 @@ test("Enforce community ban for federated user", async () => {
);
expect(unBanAlpha.banned).toBe(false);

// Need to re-follow the community
await followBeta(alpha);
// Check that unban was federated to alpha
await waitUntil(
() => getModlog(alpha),
m => {
console.log(JSON.stringify(m.modlog[0], null, 4));
return (
m.modlog[0].type_ == "ModBanFromCommunity" &&
m.modlog[0].mod_ban_from_community.banned == false
);
},
);

let postRes3 = await createPost(alpha, betaCommunity.community.id);
expect(postRes3.post_view.post).toBeDefined();
Expand Down
6 changes: 6 additions & 0 deletions api_tests/src/shared.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ import {
ListInboxResponse,
ListInbox,
InboxDataType,
GetModlogResponse,
GetModlog,
} from "lemmy-js-client";
import { CreatePost } from "lemmy-js-client/dist/types/CreatePost";
import { DeletePost } from "lemmy-js-client/dist/types/DeletePost";
Expand Down Expand Up @@ -901,6 +903,10 @@ export function approveCommunityPendingFollow(
};
return api.approveCommunityPendingFollow(form);
}
export function getModlog(api: LemmyHttp): Promise<GetModlogResponse> {
let form: GetModlog = {};
return api.getModlog(form);
}

export function delay(millis = 500) {
return new Promise(resolve => setTimeout(resolve, millis));
Expand Down
17 changes: 5 additions & 12 deletions crates/apub/src/activities/block/block_user.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,16 +30,11 @@ use lemmy_api_common::{
use lemmy_db_schema::{
source::{
activity::ActivitySendTargets,
community::{
CommunityFollower,
CommunityFollowerForm,
CommunityPersonBan,
CommunityPersonBanForm,
},
community::{CommunityPersonBan, CommunityPersonBanForm},
mod_log::moderator::{ModBan, ModBanForm, ModBanFromCommunity, ModBanFromCommunityForm},
person::{Person, PersonUpdateForm},
},
traits::{Bannable, Crud, Followable},
traits::{Bannable, Crud},
};
use lemmy_utils::error::{FederationError, LemmyError, LemmyResult};
use url::Url;
Expand Down Expand Up @@ -188,11 +183,9 @@ impl ActivityHandler for BlockUser {
};
CommunityPersonBan::ban(&mut context.pool(), &community_user_ban_form).await?;

// Also unsubscribe them from the community, if they are subscribed
let community_follower_form = CommunityFollowerForm::new(community.id, blocked_person.id);
CommunityFollower::unfollow(&mut context.pool(), &community_follower_form)
.await
.ok();
// Dont unsubscribe the user so that we can receive a potential unban activity.
// If we unfollowed the community here, activities from the community would be rejected
// in [[can_accept_activity_in_community]] in case are no other local followers.

if self.remove_data.unwrap_or(false) {
remove_or_restore_user_data_in_community(
Expand Down

0 comments on commit 284df5b

Please sign in to comment.