Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a test for mode changes correctly applying to users. #1732

Merged
merged 22 commits into from
Jun 8, 2023
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions changelog.d/1732.bugfix
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fixes cases where powerlevel changes may not be correctly applied upon mode change.
1 change: 0 additions & 1 deletion changelog.d/1732.misc

This file was deleted.

2 changes: 1 addition & 1 deletion src/bridge/IrcHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -906,7 +906,7 @@ export class IrcHandler {
* @return {Promise} which is resolved/rejected when the request finishes.
*/
public async onMode(req: BridgeRequest, server: IrcServer, channel: string, by: string,
mode: string, enabled: boolean, arg: string|null): Promise<BridgeRequestErr|void> {
mode: string, enabled: boolean, arg: string|null): Promise<BridgeRequestErr|undefined> {
this.incrementMetric("mode");
req.log.info(
"onMode(%s) in %s by %s (arg=%s)",
Expand Down
12 changes: 7 additions & 5 deletions src/bridge/RoomAccessSyncer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ export class RoomAccessSyncer {

// Bridge usermodes to power levels
const modeToPower = server.getModePowerMap();
if (typeof modeToPower[mode] !== "number") {
if (mode in modeToPower === false) {
Half-Shot marked this conversation as resolved.
Show resolved Hide resolved
req.log.debug(`Mode '${mode}' is not known`);
// Not an operator power mode
return;
Expand Down Expand Up @@ -289,7 +289,7 @@ export class RoomAccessSyncer {
`${enabled ? level : 0} to ${userId}`
);

let didFail = false;
let failureCause: Error|undefined;
for (const room of matrixRooms) {
const roomId = room.getId();
const powerLevelMap = await (this.getCurrentPowerlevels(roomId)) || {};
Expand Down Expand Up @@ -324,11 +324,13 @@ export class RoomAccessSyncer {
}
catch (ex) {
req.log.warn(`Failed to grant PL in ${roomId}`, ex);
didFail = true;
failureCause = ex;
}
}
if (didFail) {
throw new Error('Failed to update PL in soime rooms');
if (failureCause) {
// There *can* be multiple failures, but just use the first one.
// We still log all failures above.
throw new Error('Failed to update PL in some rooms', { cause: failureCause });
}
}
/**
Expand Down