1
0
mirror of https://github.com/matrix-org/matrix-react-sdk.git synced 2025-11-04 11:51:45 +03:00

Disable op/deop commands where user has no permissions (#7161)

This commit is contained in:
Michael Telatynski
2021-11-19 10:49:34 +00:00
committed by GitHub
parent 52e391a92a
commit fe4d834c72

View File

@@ -19,6 +19,7 @@ limitations under the License.
import * as React from 'react'; import * as React from 'react';
import { User } from "matrix-js-sdk/src/models/user"; import { User } from "matrix-js-sdk/src/models/user";
import { EventType } from "matrix-js-sdk/src/@types/event";
import * as ContentHelpers from 'matrix-js-sdk/src/content-helpers'; import * as ContentHelpers from 'matrix-js-sdk/src/content-helpers';
import { MatrixClientPeg } from './MatrixClientPeg'; import { MatrixClientPeg } from './MatrixClientPeg';
@@ -58,6 +59,7 @@ import SlashCommandHelpDialog from "./components/views/dialogs/SlashCommandHelpD
import { logger } from "matrix-js-sdk/src/logger"; import { logger } from "matrix-js-sdk/src/logger";
import { shouldShowComponent } from "./customisations/helpers/UIComponents"; import { shouldShowComponent } from "./customisations/helpers/UIComponents";
import { TimelineRenderingType } from './contexts/RoomContext'; import { TimelineRenderingType } from './contexts/RoomContext';
import RoomViewStore from "./stores/RoomViewStore";
// XXX: workaround for https://github.com/microsoft/TypeScript/issues/31816 // XXX: workaround for https://github.com/microsoft/TypeScript/issues/31816
interface HTMLInputEvent extends Event { interface HTMLInputEvent extends Event {
@@ -748,6 +750,11 @@ export const Commands = [
command: 'op', command: 'op',
args: '<user-id> [<power-level>]', args: '<user-id> [<power-level>]',
description: _td('Define the power level of a user'), description: _td('Define the power level of a user'),
isEnabled(): boolean {
const cli = MatrixClientPeg.get();
const room = cli.getRoom(RoomViewStore.getRoomId());
return room?.currentState.maySendStateEvent(EventType.RoomPowerLevels, cli.getUserId());
},
runFn: function(roomId, args) { runFn: function(roomId, args) {
if (args) { if (args) {
const matches = args.match(/^(\S+?)( +(-?\d+))?$/); const matches = args.match(/^(\S+?)( +(-?\d+))?$/);
@@ -779,6 +786,11 @@ export const Commands = [
command: 'deop', command: 'deop',
args: '<user-id>', args: '<user-id>',
description: _td('Deops user with given id'), description: _td('Deops user with given id'),
isEnabled(): boolean {
const cli = MatrixClientPeg.get();
const room = cli.getRoom(RoomViewStore.getRoomId());
return room?.currentState.maySendStateEvent(EventType.RoomPowerLevels, cli.getUserId());
},
runFn: function(roomId, args) { runFn: function(roomId, args) {
if (args) { if (args) {
const matches = args.match(/^(\S+)$/); const matches = args.match(/^(\S+)$/);