Fix federation of unban action (fixes #5454) (#5456)

* Fix federation of unban action (fixes #5454)

* remove log
This commit is contained in:
Nutomic 2025-02-28 13:09:19 +00:00 committed by GitHub
parent 6e3355f941
commit a3a988655d
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 19 additions and 14 deletions

View file

@ -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";
@ -651,8 +652,13 @@ 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 =>
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();

View file

@ -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";
@ -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));

View file

@ -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;
@ -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(