Skip to content

Commit

Permalink
Remove handleTimelineEvent from MemberBanSynchronisationProtection.
Browse files Browse the repository at this point in the history
  • Loading branch information
Gnuxie committed Apr 22, 2024
1 parent 101e1ec commit e253ede
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 93 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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<UserConsequences>();
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([]);
Expand Down
34 changes: 0 additions & 34 deletions src/Protection/StandardProtections/MemberBanSynchronisation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ import {
describeProtection,
} from '../Protection';
import {
Membership,
MembershipChange,
MembershipChangeType,
} from '../../Membership/MembershipChange';
Expand All @@ -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.
Expand Down Expand Up @@ -105,34 +99,6 @@ export class MemberBanSynchronisationProtection
return Ok(undefined);
}
}
public async handleTimelineEvent(
room: MatrixRoomID,
event: RoomEvent
): Promise<ActionResult<void>> {
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
Expand Down

0 comments on commit e253ede

Please sign in to comment.