MDL-80403 communication_matrix: Fixed convert power levels to array

The curent patch revealed a bug inside set_matrix_power_levels
where returned user power levels contained an array of objects.
Other methods were failing and giving incorrect responses
as they were expecting arrays.
This commit is contained in:
David Woloszyn
2023-12-19 13:36:26 +11:00
parent 0f4b02411e
commit cdb365b9f4
@@ -598,6 +598,12 @@ class communication_feature implements
$currentpowerlevels = $this->get_current_powerlevel_data();
$currentuserpowerlevels = (array) $currentpowerlevels->users ?? [];
// Ensure each user entry is an array.
$currentuserpowerlevels = array_map(
fn ($user) => (array) $user,
$currentuserpowerlevels,
);
// Get all the current users who need to be in the room.
$userlist = $this->processor->get_all_userids_for_instance();
@@ -656,7 +662,10 @@ class communication_feature implements
private function get_users_with_custom_power_level(array $users): array {
return array_filter(
$users,
function ($level): bool {
function ($user): bool {
// Isolate the level value.
$level = array_values($user);
$level = reset($level);
switch ($level) {
case matrix_constants::POWER_LEVEL_DEFAULT:
case matrix_constants::POWER_LEVEL_MOODLE_SITE_ADMIN: