Improve the clarity of the unban command (#402)

Also fix a years long bug where the Flooding/Media protection wouldn't stop redacting users

Closes #393
Closes #394

* Warn about room level bans when using unban

https://github.com/matrix-org/mjolnir/issues/394

* Clear internal queues within protections when unban happens.

https://github.com/matrix-org/mjolnir/issues/393
This commit is contained in:
Gnuxie 2022-11-07 11:28:59 +00:00 committed by GitHub
parent 2c00ac4372
commit fb52e3dcb2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 14 additions and 1 deletions

View File

@ -129,7 +129,7 @@ export async function execUnbanCommand(roomId: string, event: any, mjolnir: Mjol
await bits.list!.unbanEntity(bits.ruleType!, bits.entity); await bits.list!.unbanEntity(bits.ruleType!, bits.entity);
if (USER_RULE_TYPES.includes(bits.ruleType!) && bits.reason === 'true') { const unbanUserFromRooms = async () => {
const rule = new MatrixGlob(bits.entity); const rule = new MatrixGlob(bits.entity);
await mjolnir.managementRoomOutput.logMessage(LogLevel.INFO, "UnbanBanCommand", "Unbanning users that match glob: " + bits.entity); await mjolnir.managementRoomOutput.logMessage(LogLevel.INFO, "UnbanBanCommand", "Unbanning users that match glob: " + bits.entity);
let unbannedSomeone = false; let unbannedSomeone = false;
@ -157,6 +157,15 @@ export async function execUnbanCommand(roomId: string, event: any, mjolnir: Mjol
await mjolnir.managementRoomOutput.logMessage(LogLevel.DEBUG, "UnbanBanCommand", `Syncing lists to ensure no users were accidentally unbanned`); await mjolnir.managementRoomOutput.logMessage(LogLevel.DEBUG, "UnbanBanCommand", `Syncing lists to ensure no users were accidentally unbanned`);
await mjolnir.protectedRoomsTracker.syncLists(mjolnir.config.verboseLogging); await mjolnir.protectedRoomsTracker.syncLists(mjolnir.config.verboseLogging);
} }
};
if (USER_RULE_TYPES.includes(bits.ruleType!)) {
mjolnir.unlistedUserRedactionHandler.removeUser(bits.entity);
if (bits.reason === 'true') {
await unbanUserFromRooms();
} else {
await mjolnir.managementRoomOutput.logMessage(LogLevel.WARN, "UnbanBanCommand", "Running unban without `unban <list> <user> true` will not override existing room level bans");
}
} }
await mjolnir.client.unstableApis.addReactionToEvent(roomId, event['event_id'], '✅'); await mjolnir.client.unstableApis.addReactionToEvent(roomId, event['event_id'], '✅');

View File

@ -33,6 +33,10 @@ export class UnlistedUserRedactionQueue {
this.usersToRedact.add(userId); this.usersToRedact.add(userId);
} }
public removeUser(userId: string) {
this.usersToRedact.delete(userId);
}
public isUserQueued(userId: string): boolean { public isUserQueued(userId: string): boolean {
return this.usersToRedact.has(userId); return this.usersToRedact.has(userId);
} }