Skip to content

Commit cddcba4

Browse files
authored
Merge pull request #40371 from nextcloud/backport/39128/stable25
[stable25] fix(ldap): avatar is not being fetched
2 parents c7328ca + d87831a commit cddcba4

File tree

2 files changed

+22
-5
lines changed

2 files changed

+22
-5
lines changed

apps/user_ldap/lib/User/User.php

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -525,9 +525,9 @@ public function updateAvatarPostLogin($params) {
525525

526526
/**
527527
* @brief attempts to get an image from LDAP and sets it as Nextcloud avatar
528-
* @return bool
528+
* @return bool true when the avatar was set successfully or is up to date
529529
*/
530-
public function updateAvatar($force = false) {
530+
public function updateAvatar(bool $force = false): bool {
531531
if (!$force && $this->wasRefreshed('avatar')) {
532532
return false;
533533
}
@@ -544,7 +544,7 @@ public function updateAvatar($force = false) {
544544
// use the checksum before modifications
545545
$checksum = md5($this->image->data());
546546

547-
if ($checksum === $this->config->getUserValue($this->uid, 'user_ldap', 'lastAvatarChecksum', '')) {
547+
if ($checksum === $this->config->getUserValue($this->uid, 'user_ldap', 'lastAvatarChecksum', '') && $this->avatarExists()) {
548548
return true;
549549
}
550550

@@ -558,6 +558,15 @@ public function updateAvatar($force = false) {
558558
return $isSet;
559559
}
560560

561+
private function avatarExists(): bool {
562+
try {
563+
$currentAvatar = $this->avatarManager->getAvatar($this->uid);
564+
return $currentAvatar->exists() && $currentAvatar->isCustomAvatar();
565+
} catch (\Exception $e) {
566+
return false;
567+
}
568+
}
569+
561570
/**
562571
* @brief sets an image as Nextcloud avatar
563572
* @return bool

apps/user_ldap/tests/User/UserTest.php

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -585,9 +585,17 @@ public function testUpdateAvatarKnownJpegPhotoProvided() {
585585
$avatar = $this->createMock(IAvatar::class);
586586
$avatar->expects($this->never())
587587
->method('set');
588+
$avatar->expects($this->any())
589+
->method('exists')
590+
->willReturn(true);
591+
$avatar->expects($this->any())
592+
->method('isCustomAvatar')
593+
->willReturn(true);
588594

589-
$this->avatarManager->expects($this->never())
590-
->method('getAvatar');
595+
$this->avatarManager->expects($this->any())
596+
->method('getAvatar')
597+
->with($this->uid)
598+
->willReturn($avatar);
591599

592600
$this->connection->expects($this->any())
593601
->method('resolveRule')

0 commit comments

Comments
 (0)