Skip to content
This repository was archived by the owner on Sep 11, 2024. It is now read-only.

Commit fe4d834

Browse files
authored
Disable op/deop commands where user has no permissions (#7161)
1 parent 52e391a commit fe4d834

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

Diff for: src/SlashCommands.tsx

+12
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ limitations under the License.
1919

2020
import * as React from 'react';
2121
import { User } from "matrix-js-sdk/src/models/user";
22+
import { EventType } from "matrix-js-sdk/src/@types/event";
2223

2324
import * as ContentHelpers from 'matrix-js-sdk/src/content-helpers';
2425
import { MatrixClientPeg } from './MatrixClientPeg';
@@ -58,6 +59,7 @@ import SlashCommandHelpDialog from "./components/views/dialogs/SlashCommandHelpD
5859
import { logger } from "matrix-js-sdk/src/logger";
5960
import { shouldShowComponent } from "./customisations/helpers/UIComponents";
6061
import { TimelineRenderingType } from './contexts/RoomContext';
62+
import RoomViewStore from "./stores/RoomViewStore";
6163

6264
// XXX: workaround for https://github.com/microsoft/TypeScript/issues/31816
6365
interface HTMLInputEvent extends Event {
@@ -748,6 +750,11 @@ export const Commands = [
748750
command: 'op',
749751
args: '<user-id> [<power-level>]',
750752
description: _td('Define the power level of a user'),
753+
isEnabled(): boolean {
754+
const cli = MatrixClientPeg.get();
755+
const room = cli.getRoom(RoomViewStore.getRoomId());
756+
return room?.currentState.maySendStateEvent(EventType.RoomPowerLevels, cli.getUserId());
757+
},
751758
runFn: function(roomId, args) {
752759
if (args) {
753760
const matches = args.match(/^(\S+?)( +(-?\d+))?$/);
@@ -779,6 +786,11 @@ export const Commands = [
779786
command: 'deop',
780787
args: '<user-id>',
781788
description: _td('Deops user with given id'),
789+
isEnabled(): boolean {
790+
const cli = MatrixClientPeg.get();
791+
const room = cli.getRoom(RoomViewStore.getRoomId());
792+
return room?.currentState.maySendStateEvent(EventType.RoomPowerLevels, cli.getUserId());
793+
},
782794
runFn: function(roomId, args) {
783795
if (args) {
784796
const matches = args.match(/^(\S+)$/);

0 commit comments

Comments
 (0)