Skip to content

Commit

Permalink
Fix auth rules again for power levels
Browse files Browse the repository at this point in the history
  • Loading branch information
turt2live committed Mar 31, 2023
1 parent cd3cf50 commit 9706eb1
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
8 changes: 6 additions & 2 deletions src/server/models/PowerLevels.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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)) {
Expand Down
2 changes: 1 addition & 1 deletion src/server/room_versions/impl/IDMimiLinearized00.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down

0 comments on commit 9706eb1

Please sign in to comment.