Browse Source

Merge pull request #44741 from nextcloud/backport/stable25/44736

[stable25] fix: Fix avatar images
Joas Schilling 2 months ago
parent
commit
4f6ba659fe
2 changed files with 23 additions and 0 deletions
  1. 7 0
      lib/private/Avatar/AvatarManager.php
  2. 16 0
      tests/lib/Avatar/AvatarManagerTest.php

+ 7 - 0
lib/private/Avatar/AvatarManager.php

@@ -102,6 +102,9 @@ class AvatarManager implements IAvatarManager {
 
 	/**
 	 * 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 @@ class AvatarManager implements IAvatarManager {
 			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();
 

+ 16 - 0
tests/lib/Avatar/AvatarManagerTest.php

@@ -108,6 +108,11 @@ class AvatarManagerTest extends \Test\TestCase {
 			->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 @@ class AvatarManagerTest extends \Test\TestCase {
 			->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 @@ class AvatarManagerTest extends \Test\TestCase {
 			->expects($this->once())
 			->method('getUID')
 			->willReturn('valid-user');
+
+		$user
+			->expects($this->any())
+			->method('isEnabled')
+			->willReturn(true);
+
 		$this->userManager
 			->expects($this->once())
 			->method('get')