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, listReports,
getMyUser, getMyUser,
listInbox, listInbox,
getModlog,
} from "./shared"; } from "./shared";
import { PostView } from "lemmy-js-client/dist/types/PostView"; import { PostView } from "lemmy-js-client/dist/types/PostView";
import { AdminBlockInstanceParams } from "lemmy-js-client/dist/types/AdminBlockInstanceParams"; 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); expect(unBanAlpha.banned).toBe(false);
// Need to re-follow the community // Check that unban was federated to alpha
await followBeta(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); let postRes3 = await createPost(alpha, betaCommunity.community.id);
expect(postRes3.post_view.post).toBeDefined(); expect(postRes3.post_view.post).toBeDefined();

View file

@ -27,6 +27,8 @@ import {
ListInboxResponse, ListInboxResponse,
ListInbox, ListInbox,
InboxDataType, InboxDataType,
GetModlogResponse,
GetModlog,
} from "lemmy-js-client"; } from "lemmy-js-client";
import { CreatePost } from "lemmy-js-client/dist/types/CreatePost"; import { CreatePost } from "lemmy-js-client/dist/types/CreatePost";
import { DeletePost } from "lemmy-js-client/dist/types/DeletePost"; import { DeletePost } from "lemmy-js-client/dist/types/DeletePost";
@ -901,6 +903,10 @@ export function approveCommunityPendingFollow(
}; };
return api.approveCommunityPendingFollow(form); return api.approveCommunityPendingFollow(form);
} }
export function getModlog(api: LemmyHttp): Promise<GetModlogResponse> {
let form: GetModlog = {};
return api.getModlog(form);
}
export function delay(millis = 500) { export function delay(millis = 500) {
return new Promise(resolve => setTimeout(resolve, millis)); return new Promise(resolve => setTimeout(resolve, millis));

View file

@ -30,16 +30,11 @@ use lemmy_api_common::{
use lemmy_db_schema::{ use lemmy_db_schema::{
source::{ source::{
activity::ActivitySendTargets, activity::ActivitySendTargets,
community::{ community::{CommunityPersonBan, CommunityPersonBanForm},
CommunityFollower,
CommunityFollowerForm,
CommunityPersonBan,
CommunityPersonBanForm,
},
mod_log::moderator::{ModBan, ModBanForm, ModBanFromCommunity, ModBanFromCommunityForm}, mod_log::moderator::{ModBan, ModBanForm, ModBanFromCommunity, ModBanFromCommunityForm},
person::{Person, PersonUpdateForm}, person::{Person, PersonUpdateForm},
}, },
traits::{Bannable, Crud, Followable}, traits::{Bannable, Crud},
}; };
use lemmy_utils::error::{FederationError, LemmyError, LemmyResult}; use lemmy_utils::error::{FederationError, LemmyError, LemmyResult};
use url::Url; use url::Url;
@ -188,11 +183,9 @@ impl ActivityHandler for BlockUser {
}; };
CommunityPersonBan::ban(&mut context.pool(), &community_user_ban_form).await?; CommunityPersonBan::ban(&mut context.pool(), &community_user_ban_form).await?;
// Also unsubscribe them from the community, if they are subscribed // Dont unsubscribe the user so that we can receive a potential unban activity.
let community_follower_form = CommunityFollowerForm::new(community.id, blocked_person.id); // If we unfollowed the community here, activities from the community would be rejected
CommunityFollower::unfollow(&mut context.pool(), &community_follower_form) // in [[can_accept_activity_in_community]] in case are no other local followers.
.await
.ok();
if self.remove_data.unwrap_or(false) { if self.remove_data.unwrap_or(false) {
remove_or_restore_user_data_in_community( remove_or_restore_user_data_in_community(