Skip to content

Commit e2021ea

Browse files
Merge pull request #63563 from nextcloud/bugfix/noid/user-avatars-before-remote
fix(avatar): Fix loading avatars for users with email address user ids
2 parents d65fbd5 + ce9940b commit e2021ea

3 files changed

Lines changed: 26 additions & 7 deletions

File tree

build/integration/features/avatar.feature

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,3 +97,21 @@ Feature: avatar
9797
| Content-Type | image/png |
9898
And last avatar is a square of size 512
9999
And last avatar is not a single color
100+
101+
Scenario: Get avatar for users with cloudID formatted user id
102+
Given user "user@example.tld" exists
103+
Given Logging in using web as "user@example.tld"
104+
When logged in user posts avatar from file "data/green-square-256.png"
105+
And user "user@example.tld" gets avatar for user "user@example.tld"
106+
And The following headers should be set
107+
| Content-Type | image/png |
108+
| X-NC-IsCustomAvatar | 1 |
109+
# Last avatar size is 512 by default when getting avatar without size parameter
110+
And last avatar is a square of size 512
111+
And last avatar is a single "#00FF00" color
112+
And user "anonymous" gets avatar for user "user@example.tld"
113+
And The following headers should be set
114+
| Content-Type | image/png |
115+
| X-NC-IsCustomAvatar | 1 |
116+
And last avatar is a square of size 512
117+
And last avatar is a single "#00FF00" color

lib/private/Avatar/AvatarManager.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -49,18 +49,18 @@ public function __construct(
4949
* If the user is disabled a guest avatar will be returned
5050
*
5151
* @see \OCP\IAvatar
52-
* @param string $userId the ownCloud user id
52+
* @param string $userId the user id
5353
* @throws \Exception In case the username is potentially dangerous
5454
* @throws NotFoundException In case there is no user folder yet
5555
*/
5656
#[\Override]
5757
public function getAvatar(string $userId): IAvatar {
58-
if ($this->cloudIdManager->isValidCloudId($userId)) {
59-
return $this->getRemoteAvatar($userId);
60-
}
61-
6258
$user = $this->userManager->get($userId);
6359
if ($user === null) {
60+
if ($this->cloudIdManager->isValidCloudId($userId)) {
61+
return $this->getRemoteAvatar($userId);
62+
}
63+
6464
throw new \Exception('user does not exist');
6565
}
6666

tests/lib/Avatar/AvatarManagerTest.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -287,8 +287,9 @@ public function testGetAvatarForRemoteUser(): void {
287287
$cloudId = 'user@https://remote.example.com';
288288

289289
$this->userManager
290-
->expects($this->never())
291-
->method('get');
290+
->expects($this->once())
291+
->method('get')
292+
->willReturn(null);
292293

293294
$resolvedCloudId = $this->createMock(ICloudId::class);
294295
$resolvedCloudId->method('getUser')->willReturn('user');

0 commit comments

Comments
 (0)