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

Commit

Permalink
Add a button to MemberInfo to deactivate a user
Browse files Browse the repository at this point in the history
  • Loading branch information
turt2live committed Sep 2, 2019
1 parent 6cc29b2 commit cfff576
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 6 deletions.
50 changes: 44 additions & 6 deletions src/components/views/rooms/MemberInfo.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ import MultiInviter from "../../../utils/MultiInviter";
import SettingsStore from "../../../settings/SettingsStore";
import E2EIcon from "./E2EIcon";
import AutoHideScrollbar from "../../structures/AutoHideScrollbar";
import MatrixClientPeg from "../../../MatrixClientPeg";

module.exports = React.createClass({
displayName: 'MemberInfo',
Expand All @@ -61,6 +62,7 @@ module.exports = React.createClass({
ban: false,
mute: false,
modifyLevel: false,
synapseDeactivate: false,
},
muted: false,
isTargetMod: false,
Expand Down Expand Up @@ -215,8 +217,8 @@ module.exports = React.createClass({
}
},

_updateStateForNewMember: function(member) {
const newState = this._calculateOpsPermissions(member);
_updateStateForNewMember: async function(member) {
const newState = await this._calculateOpsPermissions(member);
newState.devicesLoading = true;
newState.devices = null;
this.setState(newState);
Expand Down Expand Up @@ -464,6 +466,25 @@ module.exports = React.createClass({
});
},

onSynapseDeactivate: function() {
const QuestionDialog = sdk.getComponent('views.dialogs.QuestionDialog');
Modal.createTrackedDialog('Synapse User Deactivation', '', QuestionDialog, {
title: _t("Deactivate user?"),
description:
<div>{ _t(
"Deactivating this user will log them out and prevent them from logging back in. Additionally, " +
"they will leave all the rooms they are in. This action cannot be reversed. Are you sure you want to " +
"deactivate this user?"
) }</div>,
button: _t("Deactivate user"),
danger: true,
onFinished: (accepted) => {
if (!accepted) return;
this.context.matrixClient.deactivateSynapseUser(this.props.member.userId);
},
});
},

_applyPowerChange: function(roomId, target, powerLevel, powerLevelEvent) {
this.setState({ updating: this.state.updating + 1 });
this.context.matrixClient.setPowerLevel(roomId, target, parseInt(powerLevel), powerLevelEvent).then(
Expand Down Expand Up @@ -548,7 +569,7 @@ module.exports = React.createClass({
});
},

_calculateOpsPermissions: function(member) {
_calculateOpsPermissions: async function(member) {
const defaultPerms = {
can: {},
muted: false,
Expand All @@ -564,15 +585,15 @@ module.exports = React.createClass({

const them = member;
return {
can: this._calculateCanPermissions(
can: await this._calculateCanPermissions(
me, them, powerLevels.getContent(),
),
muted: this._isMuted(them, powerLevels.getContent()),
isTargetMod: them.powerLevel > powerLevels.getContent().users_default,
};
},

_calculateCanPermissions: function(me, them, powerLevels) {
_calculateCanPermissions: async function(me, them, powerLevels) {
const isMe = me.userId === them.userId;
const can = {
kick: false,
Expand All @@ -581,6 +602,10 @@ module.exports = React.createClass({
modifyLevel: false,
modifyLevelMax: 0,
};

// Calculate permissions for Synapse before doing the PL checks
can.synapseDeactivate = await this.context.matrixClient.isSynapseAdministrator();

const canAffectUser = them.powerLevel < me.powerLevel || isMe;
if (!canAffectUser) {
//console.log("Cannot affect user: %s >= %s", them.powerLevel, me.powerLevel);
Expand Down Expand Up @@ -786,6 +811,7 @@ module.exports = React.createClass({
let banButton;
let muteButton;
let giveModButton;
let synapseDeactivateButton;
let spinner;

if (this.props.member.userId !== this.context.matrixClient.credentials.userId) {
Expand Down Expand Up @@ -893,8 +919,19 @@ module.exports = React.createClass({
</AccessibleButton>;
}

// We don't need a perfect check here, just something to pass as "probably not our homeserver". If
// someone does figure out how to bypass this check the worst that happens is an error.
const sameHomeserver = this.props.member.userId.endsWith(`:${MatrixClientPeg.getHomeserverName()}`);
if (this.state.can.synapseDeactivate && sameHomeserver) {
synapseDeactivateButton = (
<AccessibleButton onClick={this.onSynapseDeactivate} className="mx_MemberInfo_field">
{_t("Deactivate user")}
</AccessibleButton>
);
}

let adminTools;
if (kickButton || banButton || muteButton || giveModButton) {
if (kickButton || banButton || muteButton || giveModButton || synapseDeactivateButton) {
adminTools =
<div>
<h3>{ _t("Admin Tools") }</h3>
Expand All @@ -904,6 +941,7 @@ module.exports = React.createClass({
{ kickButton }
{ banButton }
{ giveModButton }
{ synapseDeactivateButton }
</div>
</div>;
}
Expand Down
3 changes: 3 additions & 0 deletions src/i18n/strings/en_EN.json
Original file line number Diff line number Diff line change
Expand Up @@ -788,6 +788,9 @@
"Demote": "Demote",
"Failed to mute user": "Failed to mute user",
"Failed to toggle moderator status": "Failed to toggle moderator status",
"Deactivate user?": "Deactivate user?",
"Deactivating this user will log them out and prevent them from logging back in. Additionally, they will leave all the rooms they are in. This action cannot be reversed. Are you sure you want to deactivate this user?": "Deactivating this user will log them out and prevent them from logging back in. Additionally, they will leave all the rooms they are in. This action cannot be reversed. Are you sure you want to deactivate this user?",
"Deactivate user": "Deactivate user",
"Failed to change power level": "Failed to change power level",
"You will not be able to undo this change as you are promoting the user to have the same power level as yourself.": "You will not be able to undo this change as you are promoting the user to have the same power level as yourself.",
"Are you sure?": "Are you sure?",
Expand Down

0 comments on commit cfff576

Please sign in to comment.