From 9706eb1e19fa82e08a7429a7cfa0514402f9911d Mon Sep 17 00:00:00 2001 From: Travis Ralston Date: Fri, 31 Mar 2023 09:41:45 -0600 Subject: [PATCH] Fix auth rules again for power levels See https://github.com/matrix-org/matrix-spec/pull/1479 --- src/server/models/PowerLevels.ts | 8 ++++++-- src/server/room_versions/impl/IDMimiLinearized00.ts | 2 +- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/src/server/models/PowerLevels.ts b/src/server/models/PowerLevels.ts index 0acd29c..258c374 100644 --- a/src/server/models/PowerLevels.ts +++ b/src/server/models/PowerLevels.ts @@ -3,9 +3,13 @@ import {MatrixEvent} from "./event"; type PowerAction = "invite" | "kick" | "ban" | "redact" | "notifications.room"; export class PowerLevels { - public constructor(private event: MatrixEvent | undefined) {} + public constructor(private event: MatrixEvent | undefined, private createEvent: MatrixEvent) {} public getUserLevel(userId: string): number { + if (this.event === undefined) { + return userId === this.createEvent.sender ? 100 : 0; + } + const explicitLevel = this.event?.content["users"]?.[userId]; if (Number.isInteger(explicitLevel)) { return explicitLevel; @@ -42,7 +46,7 @@ export class PowerLevels { } public canUserSend(userId: string, eventType: string, isState: boolean): boolean { - let requiredLevel = isState ? (this.event ? 50 : 0) : 0; + let requiredLevel = isState ? 50 : 0; const defaultLevel = isState ? this.event?.content["state_default"] : this.event?.content["events_default"]; if (Number.isInteger(defaultLevel)) { diff --git a/src/server/room_versions/impl/IDMimiLinearized00.ts b/src/server/room_versions/impl/IDMimiLinearized00.ts index a568a4e..32a91a9 100644 --- a/src/server/room_versions/impl/IDMimiLinearized00.ts +++ b/src/server/room_versions/impl/IDMimiLinearized00.ts @@ -280,7 +280,7 @@ export class IDMimiLinearized00 implements RoomVersion { const joinRule = joinRulesEv?.content["join_rule"] ?? "invite"; const powerLevelsEv = currentState.get("m.room.power_levels", ""); - const powerLevels = new PowerLevels(powerLevelsEv); + const powerLevels = new PowerLevels(powerLevelsEv, createEvent); const senderMembershipEv = currentState.get("m.room.member", event.sender); const senderMembership = senderMembershipEv?.content["membership"] ?? "leave";