From 6eee39c153f4f303c775866f42bd0366c194077a Mon Sep 17 00:00:00 2001 From: Michael Telatynski <7t3chguy@gmail.com> Date: Mon, 18 May 2020 12:04:13 +0100 Subject: [PATCH 1/3] Fix /op Slash Command Signed-off-by: Michael Telatynski <7t3chguy@gmail.com> --- src/SlashCommands.tsx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/SlashCommands.tsx b/src/SlashCommands.tsx index fbb9e2eb0e..6fbf56a518 100644 --- a/src/SlashCommands.tsx +++ b/src/SlashCommands.tsx @@ -729,9 +729,9 @@ export const Commands = [ const cli = MatrixClientPeg.get(); const room = cli.getRoom(roomId); if (!room) return reject(_t("Command failed")); - + const member = room.getMember(args); + if (!member) return reject(_t("Could not find user in room")); const powerLevelEvent = room.currentState.getStateEvents('m.room.power_levels', ''); - if (!powerLevelEvent.getContent().users[args]) return reject(_t("Could not find user in room")); return success(cli.setPowerLevel(roomId, userId, powerLevel, powerLevelEvent)); } } From b4e2e54dc1bc096759ea00156b868ac922ef18cc Mon Sep 17 00:00:00 2001 From: Michael Telatynski <7t3chguy@gmail.com> Date: Mon, 18 May 2020 12:06:20 +0100 Subject: [PATCH 2/3] make test more specific Signed-off-by: Michael Telatynski <7t3chguy@gmail.com> --- src/SlashCommands.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/SlashCommands.tsx b/src/SlashCommands.tsx index 6fbf56a518..cea780e361 100644 --- a/src/SlashCommands.tsx +++ b/src/SlashCommands.tsx @@ -730,7 +730,7 @@ export const Commands = [ const room = cli.getRoom(roomId); if (!room) return reject(_t("Command failed")); const member = room.getMember(args); - if (!member) return reject(_t("Could not find user in room")); + if (!member || member.membership !== "join") return reject(_t("Could not find user in room")); const powerLevelEvent = room.currentState.getStateEvents('m.room.power_levels', ''); return success(cli.setPowerLevel(roomId, userId, powerLevel, powerLevelEvent)); } From 030586275ffea1a67e909765bf8f6d5f74e160b9 Mon Sep 17 00:00:00 2001 From: Michael Telatynski <7t3chguy@gmail.com> Date: Tue, 14 Jul 2020 10:59:06 +0100 Subject: [PATCH 3/3] Fix /op command to accept only joined/invited users Signed-off-by: Michael Telatynski <7t3chguy@gmail.com> --- src/SlashCommands.tsx | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/SlashCommands.tsx b/src/SlashCommands.tsx index c593d3786f..ed69dd2204 100644 --- a/src/SlashCommands.tsx +++ b/src/SlashCommands.tsx @@ -43,6 +43,7 @@ import SdkConfig from "./SdkConfig"; import { ensureDMExists } from "./createRoom"; import { ViewUserPayload } from "./dispatcher/payloads/ViewUserPayload"; import { Action } from "./dispatcher/actions"; +import { EffectiveMembership, getEffectiveMembership } from "./utils/membership"; // XXX: workaround for https://github.com/microsoft/TypeScript/issues/31816 interface HTMLInputEvent extends Event { @@ -731,7 +732,9 @@ export const Commands = [ const room = cli.getRoom(roomId); if (!room) return reject(_t("Command failed")); const member = room.getMember(args); - if (!member || member.membership !== "join") return reject(_t("Could not find user in room")); + if (!member || getEffectiveMembership(member.membership) === EffectiveMembership.Leave) { + return reject(_t("Could not find user in room")); + } const powerLevelEvent = room.currentState.getStateEvents('m.room.power_levels', ''); return success(cli.setPowerLevel(roomId, userId, powerLevel, powerLevelEvent)); }