From 9eb08f983e1f5283b676916712dc7e3007ce2b2f Mon Sep 17 00:00:00 2001 From: Christopher Ng Date: Mon, 8 Apr 2024 17:04:33 -0700 Subject: [PATCH 1/2] fix: Fix avatar images Signed-off-by: Christopher Ng --- lib/private/Avatar/AvatarManager.php | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/lib/private/Avatar/AvatarManager.php b/lib/private/Avatar/AvatarManager.php index 191a80cb5ccbf..0b1150e5620a8 100644 --- a/lib/private/Avatar/AvatarManager.php +++ b/lib/private/Avatar/AvatarManager.php @@ -102,6 +102,9 @@ public function __construct( /** * return a user specific instance of \OCP\IAvatar + * + * If the user is disabled a guest avatar will be returned + * * @see \OCP\IAvatar * @param string $userId the ownCloud user id * @return \OCP\IAvatar @@ -114,6 +117,10 @@ public function getAvatar(string $userId) : IAvatar { throw new \Exception('user does not exist'); } + if (!$user->isEnabled()) { + return $this->getGuestAvatar($userId); + } + // sanitize userID - fixes casing issue (needed for the filesystem stuff that is done below) $userId = $user->getUID(); From fb429921b8ab88fcb00d04983e4c4e9aa0e6a0b8 Mon Sep 17 00:00:00 2001 From: Christopher Ng Date: Mon, 8 Apr 2024 17:04:33 -0700 Subject: [PATCH 2/2] test: Update tests Signed-off-by: Christopher Ng --- tests/lib/Avatar/AvatarManagerTest.php | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/tests/lib/Avatar/AvatarManagerTest.php b/tests/lib/Avatar/AvatarManagerTest.php index 06ff4086f7233..7d09440155ce2 100644 --- a/tests/lib/Avatar/AvatarManagerTest.php +++ b/tests/lib/Avatar/AvatarManagerTest.php @@ -108,6 +108,11 @@ public function testGetAvatarForSelf() { ->method('getUID') ->willReturn('valid-user'); + $user + ->expects($this->any()) + ->method('isEnabled') + ->willReturn(true); + // requesting user $this->userSession->expects($this->once()) ->method('getUser') @@ -162,6 +167,11 @@ public function testGetAvatarValidUserDifferentCasing() { ->method('getUID') ->willReturn('valid-user'); + $user + ->expects($this->any()) + ->method('isEnabled') + ->willReturn(true); + $this->userSession->expects($this->once()) ->method('getUser') ->willReturn($user); @@ -231,6 +241,12 @@ public function testGetAvatarScopes($avatarScope, $isPublicCall, $isKnownUser, $ ->expects($this->once()) ->method('getUID') ->willReturn('valid-user'); + + $user + ->expects($this->any()) + ->method('isEnabled') + ->willReturn(true); + $this->userManager ->expects($this->once()) ->method('get')