From 547b72fa270b4eaa707866f61f05189328bd7064 Mon Sep 17 00:00:00 2001 From: campbell-m <87438215+campbell-m@users.noreply.github.com> Date: Tue, 11 Jun 2024 09:56:58 +0100 Subject: [PATCH] Check that we have a valid Joomla user. See GitHub Issue #3682. --- web/lib/MRBS/Auth/AuthJoomla.php | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/web/lib/MRBS/Auth/AuthJoomla.php b/web/lib/MRBS/Auth/AuthJoomla.php index c668978341..f46a861107 100644 --- a/web/lib/MRBS/Auth/AuthJoomla.php +++ b/web/lib/MRBS/Auth/AuthJoomla.php @@ -127,8 +127,21 @@ public function getUsernames() : array { $user = Factory::getUser((int)$user_id); } - $result[] = array('username' => $user->username, - 'display_name' => $user->name); + // Check to see that the user has a username. The result of getUser() on a user_id that doesn't exist is, + // strangely, a user object with all properties set to null. In theory (?) all the user_ids returned by + // getUsersByGroup() should exist, but there has been a case where this is not so. See + // https://github.com/meeting-room-booking-system/mrbs-code/issues/3682 . + if (isset($user->username)) + { + $result[] = array( + 'username' => $user->username, + 'display_name' => $user->name + ); + } + else + { + trigger_error("The Joomla user with id $user_id appears in Joomla groups but not in Joomla users.", E_USER_WARNING); + } } // Need to sort the users