From e253ede263b030706b73d8d621862c643ff3f95e Mon Sep 17 00:00:00 2001 From: gnuxie Date: Mon, 22 Apr 2024 15:38:52 +0100 Subject: [PATCH] Remove `handleTimelineEvent` from `MemberBanSynchronisationProtection`. https://github.com/the-draupnir-project/Draupnir/issues/361. --- .../MemberBanSynchronisation.test.ts | 60 +------------------ .../MemberBanSynchronisation.ts | 34 ----------- 2 files changed, 1 insertion(+), 93 deletions(-) diff --git a/src/Protection/StandardProtections/MemberBanSynchronisation.test.ts b/src/Protection/StandardProtections/MemberBanSynchronisation.test.ts index 5e16523..cbf19de 100644 --- a/src/Protection/StandardProtections/MemberBanSynchronisation.test.ts +++ b/src/Protection/StandardProtections/MemberBanSynchronisation.test.ts @@ -11,10 +11,7 @@ import { randomUserID, } from '../../TestUtilities/EventGeneration'; import { StringUserID } from '../../MatrixTypes/StringlyTypedMatrix'; -import { - describeProtectedRoomsSet, - describeRoomMember, -} from '../../StateTracking/DeclareRoomState'; +import { describeProtectedRoomsSet } from '../../StateTracking/DeclareRoomState'; import { Membership, MembershipChangeType, @@ -55,61 +52,6 @@ function createMemberBanSynchronisationProtection( return protectionResult.ok as unknown as MemberBanSynchronisationProtection; } -// handleTimelineEvent -test('A membership event recieved from the timeline that matches an existing policy should be acted upon, later this can be made a setting but it should be on by default.', async function () { - const spammerToBanUserID = `@spam:example.com` as StringUserID; - const policyRoom = randomRoomID([]); - const protectedRoom = randomRoomID([]); - const { protectedRoomsSet } = await describeProtectedRoomsSet({ - rooms: [ - { - room: protectedRoom, - }, - ], - lists: [ - { - room: policyRoom, - policyDescriptions: [ - { - entity: spammerToBanUserID, - type: PolicyRuleType.User, - reason: 'spam', - }, - ], - }, - ], - }); - - const userConsequences = createMock(); - const consequenceSpy = jest.spyOn( - userConsequences, - 'consequenceForUserInRoom' - ); - - const protection = createMemberBanSynchronisationProtection( - { userConsequences }, - protectedRoomsSet - ); - - if (protection.handleTimelineEvent === undefined) { - throw new TypeError( - `Protection should have the method to handle a timeline event defined, is this test out of date?` - ); - } - const protectionHandlerResult = await protection.handleTimelineEvent.call( - protection, - protectedRoom, - describeRoomMember({ - sender: spammerToBanUserID, - target: spammerToBanUserID, - room_id: protectedRoom.toRoomIDOrAlias(), - membership: Membership.Join, - }) - ); - expect(isOk(protectionHandlerResult)).toBeTruthy(); - expect(consequenceSpy).toBeCalled(); -}); - // handleMembershipChange test('Membership changes that should result in a ban when matching an existing policy', async function () { const policyRoom = randomRoomID([]); diff --git a/src/Protection/StandardProtections/MemberBanSynchronisation.ts b/src/Protection/StandardProtections/MemberBanSynchronisation.ts index e0f95c4..aa0a98f 100644 --- a/src/Protection/StandardProtections/MemberBanSynchronisation.ts +++ b/src/Protection/StandardProtections/MemberBanSynchronisation.ts @@ -18,7 +18,6 @@ import { describeProtection, } from '../Protection'; import { - Membership, MembershipChange, MembershipChangeType, } from '../../Membership/MembershipChange'; @@ -27,11 +26,6 @@ import { ProtectedRoomsSet } from '../ProtectedRoomsSet'; import { PolicyRuleType } from '../../MatrixTypes/PolicyEvents'; import { Recommendation } from '../../PolicyList/PolicyRule'; import { MultipleErrors } from '../../Interface/MultipleErrors'; -import { StringUserID } from '../../MatrixTypes/StringlyTypedMatrix'; -import { MatrixRoomID } from '../../MatrixTypes/MatrixRoomReference'; -import { RoomEvent } from '../../MatrixTypes/Events'; -import { Value } from '../../Interface/Value'; -import { MembershipEvent } from '../../MatrixTypes/MembershipEvent'; import { UserConsequences } from '../Capability/StandardCapability/UserConsequences'; import { UnknownSettings } from '../ProtectionSettings/ProtectionSetting'; import '../Capability/StandardCapability/UserConsequences'; // need this to load the interface. @@ -105,34 +99,6 @@ export class MemberBanSynchronisationProtection return Ok(undefined); } } - public async handleTimelineEvent( - room: MatrixRoomID, - event: RoomEvent - ): Promise> { - if (event.type === 'm.room.member' && Value.Check(MembershipEvent, event)) { - switch (event.content.membership) { - case Membership.Ban: - case Membership.Leave: - return Ok(undefined); - } - const directIssuer = - this.protectedRoomsSet.issuerManager.policyListRevisionIssuer; - const applicableRule = - directIssuer.currentRevision.findRuleMatchingEntity( - event.state_key, - PolicyRuleType.User, - Recommendation.Ban - ); - if (applicableRule !== undefined) { - return await this.userConsequences.consequenceForUserInRoom( - room.toRoomIDOrAlias(), - event.state_key as StringUserID, - applicableRule.reason - ); - } - } - return Ok(undefined); - } public async synchroniseWithRevision( revision: PolicyListRevision