Skip to content

Commit 52518e0

Browse files
committed
fix(sdk): Use RoomPowerLevels::user_can_kick_user in filter_any_sync_state_event.
This patch replaces `user_can_kick` by `user_can_kick`: it performs an extra check to make sure the acting user has at least the same power level as the target user.
1 parent b8b5424 commit 52518e0

File tree

1 file changed

+20
-2
lines changed

1 file changed

+20
-2
lines changed

crates/matrix-sdk/src/latest_events/latest_event.rs

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1001,7 +1001,8 @@ fn filter_any_sync_state_event(
10011001
let can_accept_or_decline_knocks = match (own_user_id, power_levels) {
10021002
(Some(own_user_id), Some(room_power_levels)) => {
10031003
room_power_levels.user_can_invite(own_user_id)
1004-
|| room_power_levels.user_can_kick(own_user_id)
1004+
|| room_power_levels
1005+
.user_can_kick_user(own_user_id, member.state_key())
10051006
}
10061007
_ => false,
10071008
};
@@ -1246,7 +1247,8 @@ mod tests_latest_event_content {
12461247

12471248
let mut room_power_levels =
12481249
RoomPowerLevels::new(RoomPowerLevelsSource::None, &AuthorizationRules::V1, []);
1249-
room_power_levels.users_default = 5.into();
1250+
room_power_levels.users.insert(user_id.to_owned(), 5.into());
1251+
room_power_levels.users.insert(other_user_id.to_owned(), 4.into());
12501252

12511253
// Cannot accept. Cannot decline.
12521254
{
@@ -1287,6 +1289,22 @@ mod tests_latest_event_content {
12871289
"can accept, can decline",
12881290
);
12891291
}
1292+
1293+
// Cannot accept. Can decline. But with an other user ID with at least the same
1294+
// levels, i.e. the current user cannot kick another user with the same
1295+
// or higher levels.
1296+
{
1297+
room_power_levels.users.insert(user_id.to_owned(), 5.into());
1298+
room_power_levels.users.insert(other_user_id.to_owned(), 5.into());
1299+
1300+
room_power_levels.invite = 10.into();
1301+
room_power_levels.kick = 0.into();
1302+
1303+
assert!(
1304+
filter_timeline_event(&event, Some(user_id), Some(&room_power_levels)).not(),
1305+
"cannot accept, can decline, at least same user levels",
1306+
);
1307+
}
12901308
}
12911309

12921310
#[test]

0 commit comments

Comments
 (0)