Skip to content

Commit

Permalink
Merge pull request #44738 from nextcloud/backport/stable28/44736
Browse files Browse the repository at this point in the history
[stable28] fix: Fix avatar images
  • Loading branch information
susnux authored Apr 9, 2024
2 parents 17dce74 + eb06392 commit fe643bb
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
7 changes: 7 additions & 0 deletions lib/private/Avatar/AvatarManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,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
* @throws \Exception In case the username is potentially dangerous
Expand All @@ -80,6 +83,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();

Expand Down
16 changes: 16 additions & 0 deletions tests/lib/Avatar/AvatarManagerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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')
Expand Down

0 comments on commit fe643bb

Please sign in to comment.