This repository has been archived by the owner on Sep 11, 2024. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 831
Offer to unban user during invite if inviter has sufficient permissions #11256
Merged
Merged
Changes from 3 commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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,32 @@ export default class MultiInviter { | |
errcode: USER_ALREADY_INVITED, | ||
error: "Member already invited", | ||
}); | ||
} else if (member?.membership === "ban") { | ||
let proceed = false; | ||
const ourMember = room.getMember(this.matrixClient.getSafeUserId()); | ||
t3chguy marked this conversation as resolved.
Show resolved
Hide resolved
|
||
if ( | ||
!!ourMember && | ||
member.powerLevel < ourMember.powerLevel && | ||
room.currentState.hasSufficientPowerLevelFor("ban", ourMember.powerLevel) && | ||
room.currentState.hasSufficientPowerLevelFor("kick", ourMember.powerLevel) | ||
) { | ||
Comment on lines
+180
to
+185
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. it might have been nice to pull this out to a There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ideally it'd have been a util in the js-sdk but 🤷 |
||
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 +296,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": | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
slight concern with checking before attempting the invite is it is vulnerable to Element's state drifting out of sync with the server. We could refuse to invite someone who isn't actually banned, etc. It might have been nicer to prompt to unban if the initial attempt to invite fails.
But I guess we already have this problem with the other checks here, so 🤷♂️