Skip to content

Commit

Permalink
Merge pull request #39128 from nextcloud/fix/35319/ldap-missing-avatar
Browse files Browse the repository at this point in the history
  • Loading branch information
juliushaertl committed Sep 11, 2023
2 parents 9e2b248 + 4054a7d commit 97dd09c
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 5 deletions.
15 changes: 12 additions & 3 deletions apps/user_ldap/lib/User/User.php
Expand Up @@ -695,9 +695,9 @@ public function updateAvatarPostLogin($params) {

/**
* @brief attempts to get an image from LDAP and sets it as Nextcloud avatar
* @return bool
* @return bool true when the avatar was set successfully or is up to date
*/
public function updateAvatar($force = false) {
public function updateAvatar(bool $force = false): bool {
if (!$force && $this->wasRefreshed('avatar')) {
return false;
}
Expand All @@ -714,7 +714,7 @@ public function updateAvatar($force = false) {
// use the checksum before modifications
$checksum = md5($this->image->data());

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

Expand All @@ -728,6 +728,15 @@ public function updateAvatar($force = false) {
return $isSet;
}

private function avatarExists(): bool {
try {
$currentAvatar = $this->avatarManager->getAvatar($this->uid);
return $currentAvatar->exists() && $currentAvatar->isCustomAvatar();
} catch (\Exception $e) {
return false;
}
}

/**
* @brief sets an image as Nextcloud avatar
* @return bool
Expand Down
12 changes: 10 additions & 2 deletions apps/user_ldap/tests/User/UserTest.php
Expand Up @@ -585,9 +585,17 @@ public function testUpdateAvatarKnownJpegPhotoProvided() {
$avatar = $this->createMock(IAvatar::class);
$avatar->expects($this->never())
->method('set');
$avatar->expects($this->any())
->method('exists')
->willReturn(true);
$avatar->expects($this->any())
->method('isCustomAvatar')
->willReturn(true);

$this->avatarManager->expects($this->never())
->method('getAvatar');
$this->avatarManager->expects($this->any())
->method('getAvatar')
->with($this->uid)
->willReturn($avatar);

$this->connection->expects($this->any())
->method('resolveRule')
Expand Down

0 comments on commit 97dd09c

Please sign in to comment.