diff --git a/.changeset/famous-aliens-smash.md b/.changeset/famous-aliens-smash.md new file mode 100644 index 00000000..53af7aaf --- /dev/null +++ b/.changeset/famous-aliens-smash.md @@ -0,0 +1,8 @@ +--- +"@the-draupnir-project/matrix-protection-suite": patch +"draupnir": patch +--- + +Fixed a bug where User policies of any recommendation would result in the +MemberBanSynchronisationProtection banning users. This is was a particularly +important issue for compatibility with Meowlnir. diff --git a/packages/matrix-protection-suite/src/Protection/StandardProtections/MemberBanSynchronisation/MemberBanSynchronisation.ts b/packages/matrix-protection-suite/src/Protection/StandardProtections/MemberBanSynchronisation/MemberBanSynchronisation.ts index 43ad19f1..464f4db3 100644 --- a/packages/matrix-protection-suite/src/Protection/StandardProtections/MemberBanSynchronisation/MemberBanSynchronisation.ts +++ b/packages/matrix-protection-suite/src/Protection/StandardProtections/MemberBanSynchronisation/MemberBanSynchronisation.ts @@ -27,7 +27,7 @@ import { import { RoomMembershipRevision } from "../../../Membership/MembershipRevision"; import { ProtectedRoomsSet } from "../../ProtectedRoomsSet"; import { PolicyRuleType } from "../../../MatrixTypes/PolicyEvents"; -import { Recommendation } from "../../../PolicyList/PolicyRule"; +import { PolicyRule, Recommendation } from "../../../PolicyList/PolicyRule"; import { MultipleErrors } from "../../../Interface/MultipleErrors"; import { UserConsequences } from "../../Capability/StandardCapability/UserConsequences"; import "../../Capability/StandardCapability/UserConsequences"; // need this to load the interface. @@ -45,14 +45,26 @@ import { StandardMemberBanIntentProjection, } from "./MemberBanIntentProjection"; -function revisionMatchesWithUserRules( +function isRecommendationWorthBanning(policyRule: PolicyRule) { + return ( + policyRule.recommendation === Recommendation.Ban || + policyRule.recommendation === Recommendation.Takedown + ); +} + +function revisionMatchesWithUserBans( revision: SetMembershipPolicyRevision ): MemberPolicyMatches[] { - return revision - .allMembersWithRules() - .filter((match) => - match.policies.some((policy) => policy.kind === PolicyRuleType.User) - ); + return revision.allMembersWithRules().filter((match) => + match.policies.some( + (policy) => + // We only ban for user policies and not server ones at the time being, + // As this keeps ACL non-disruptive when it is necessary to temporarily + // ban a server. + policy.kind === PolicyRuleType.User && + isRecommendationWorthBanning(policy) + ) + ); } export type MemberBanSynchronisationProtectionDescription = @@ -148,7 +160,7 @@ export class MemberBanSynchronisationProtection revision: SetMembershipPolicyRevision ): Promise> { const result = await this.userConsequences.consequenceForUsersInRoomSet( - revisionMatchesWithUserRules(revision) + revisionMatchesWithUserBans(revision) ); if (isError(result)) { return result; @@ -162,7 +174,7 @@ export class MemberBanSynchronisationProtection (async () => { await this.userConsequences.consequenceForUsersInRoom( room.toRoomIDOrAlias(), - revisionMatchesWithUserRules( + revisionMatchesWithUserBans( this.protectedRoomsSet.setPoliciesMatchingMembership.currentRevision ) );