From 2d231b7af112d667f8f595e71d7e9499c5cad9eb Mon Sep 17 00:00:00 2001 From: miruka Date: Sun, 19 Apr 2020 16:50:19 -0400 Subject: [PATCH] Properly check power levels before allowing kick --- src/backend/matrix_client.py | 14 ++++++++++++++ src/gui/Pages/Chat/RoomPane/MemberDelegate.qml | 9 ++++++++- 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/src/backend/matrix_client.py b/src/backend/matrix_client.py index 9e401948..55d7bef9 100644 --- a/src/backend/matrix_client.py +++ b/src/backend/matrix_client.py @@ -306,6 +306,20 @@ class MatrixClient(nio.AsyncClient): return (await self.content_repository_config()).upload_size + async def can_kick(self, room_id: str, target_user_id: str) -> bool: + """Return whether we can kick a certain user in a room.""" + + levels = self.all_rooms[room_id].power_levels + return levels.can_user_kick(self.user_id, target_user_id) + + + async def can_ban(self, room_id: str, target_user_id: str) -> bool: + """Return whether we can ban/unbun a certain user in a room.""" + + levels = self.all_rooms[room_id].power_levels + return levels.can_user_ban(self.user_id, target_user_id) + + @property def all_rooms(self) -> Dict[str, nio.MatrixRoom]: """Return dict containing both our joined and invited rooms.""" diff --git a/src/gui/Pages/Chat/RoomPane/MemberDelegate.qml b/src/gui/Pages/Chat/RoomPane/MemberDelegate.qml index b573e3ae..8ac1e5b8 100644 --- a/src/gui/Pages/Chat/RoomPane/MemberDelegate.qml +++ b/src/gui/Pages/Chat/RoomPane/MemberDelegate.qml @@ -57,7 +57,7 @@ HTileDelegate { icon.name: "room-kick" icon.color: theme.colors.negativeBackground text: model.invited ? qsTr("Disinvite") : qsTr("Kick") - enabled: chat.roomInfo.can_kick + enabled: false popup: "Popups/KickPopup.qml" popupParent: chat @@ -68,6 +68,13 @@ HTileDelegate { targetDisplayName: model.display_name, targetIsInvited: model.invited, }) + + Component.onCompleted: py.callClientCoro( + chat.userId, + "can_kick", + [chat.roomId, model.id], + can => { enabled = can }, + ) } }