Offer to unban user during invite if inviter has sufficient permissions (#11256)
* Offer to unban user during invite if inviter has sufficient permissions * Improve unban check in MultiInviter * Improve coverage * Update src/utils/MultiInviter.ts Co-authored-by: Richard van der Hoff <1389908+richvdh@users.noreply.github.com> --------- Co-authored-by: Richard van der Hoff <1389908+richvdh@users.noreply.github.com>
This commit is contained in:
parent
86d3ec8154
commit
63bdd84c94
3 changed files with 67 additions and 2 deletions
|
@ -735,6 +735,8 @@
|
|||
"Not a valid %(brand)s keyfile": "Not a valid %(brand)s keyfile",
|
||||
"Authentication check failed: incorrect password?": "Authentication check failed: incorrect password?",
|
||||
"Unrecognised address": "Unrecognised address",
|
||||
"Unban": "Unban",
|
||||
"User cannot be invited until they are unbanned": "User cannot be invited until they are unbanned",
|
||||
"You do not have permission to invite people to this space.": "You do not have permission to invite people to this space.",
|
||||
"You do not have permission to invite people to this room.": "You do not have permission to invite people to this room.",
|
||||
"User is already invited to the space": "User is already invited to the space",
|
||||
|
@ -1706,7 +1708,6 @@
|
|||
"Upload custom sound": "Upload custom sound",
|
||||
"Browse": "Browse",
|
||||
"Failed to unban": "Failed to unban",
|
||||
"Unban": "Unban",
|
||||
"Banned by %(displayName)s": "Banned by %(displayName)s",
|
||||
"Reason": "Reason",
|
||||
"Error changing power level requirement": "Error changing power level requirement",
|
||||
|
|
|
@ -26,6 +26,7 @@ import { _t } from "../languageHandler";
|
|||
import Modal from "../Modal";
|
||||
import SettingsStore from "../settings/SettingsStore";
|
||||
import AskInviteAnywayDialog from "../components/views/dialogs/AskInviteAnywayDialog";
|
||||
import ConfirmUserActionDialog from "../components/views/dialogs/ConfirmUserActionDialog";
|
||||
|
||||
export enum InviteState {
|
||||
Invited = "invited",
|
||||
|
@ -48,6 +49,7 @@ export type CompletionStates = Record<string, InviteState>;
|
|||
|
||||
const USER_ALREADY_JOINED = "IO.ELEMENT.ALREADY_JOINED";
|
||||
const USER_ALREADY_INVITED = "IO.ELEMENT.ALREADY_INVITED";
|
||||
const USER_BANNED = "IO.ELEMENT.BANNED";
|
||||
|
||||
/**
|
||||
* Invites multiple addresses to a room, handling rate limiting from the server
|
||||
|
@ -170,6 +172,34 @@ export default class MultiInviter {
|
|||
errcode: USER_ALREADY_INVITED,
|
||||
error: "Member already invited",
|
||||
});
|
||||
} else if (member?.membership === "ban") {
|
||||
let proceed = false;
|
||||
// Check if we can unban the invitee.
|
||||
// See https://spec.matrix.org/v1.7/rooms/v10/#authorization-rules, particularly 4.5.3 and 4.5.4.
|
||||
const ourMember = room.getMember(this.matrixClient.getSafeUserId());
|
||||
if (
|
||||
!!ourMember &&
|
||||
member.powerLevel < ourMember.powerLevel &&
|
||||
room.currentState.hasSufficientPowerLevelFor("ban", ourMember.powerLevel) &&
|
||||
room.currentState.hasSufficientPowerLevelFor("kick", ourMember.powerLevel)
|
||||
) {
|
||||
const { finished } = Modal.createDialog(ConfirmUserActionDialog, {
|
||||
member,
|
||||
action: _t("Unban"),
|
||||
title: _t("User cannot be invited until they are unbanned"),
|
||||
});
|
||||
[proceed = false] = await finished;
|
||||
if (proceed) {
|
||||
await this.matrixClient.unban(roomId, member.userId);
|
||||
}
|
||||
}
|
||||
|
||||
if (!proceed) {
|
||||
throw new MatrixError({
|
||||
errcode: USER_BANNED,
|
||||
error: "Member is banned",
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
if (!ignoreProfile && SettingsStore.getValue("promptBeforeInviteUnknownUsers", this.roomId)) {
|
||||
|
@ -268,6 +298,7 @@ export default class MultiInviter {
|
|||
}
|
||||
break;
|
||||
case "M_BAD_STATE":
|
||||
case USER_BANNED:
|
||||
errorText = _t("The user must be unbanned before they can be invited.");
|
||||
break;
|
||||
case "M_UNSUPPORTED_ROOM_VERSION":
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue