]> source.dussan.org Git - nextcloud-server.git/commitdiff
fix(ldap): avatar is not being fetched
authorArthur Schiwon <blizzz@arthur-schiwon.de>
Mon, 3 Jul 2023 20:25:03 +0000 (22:25 +0200)
committerbackportbot-nextcloud[bot] <backportbot-nextcloud[bot]@users.noreply.github.com>
Mon, 11 Sep 2023 17:53:16 +0000 (17:53 +0000)
Signed-off-by: Arthur Schiwon <blizzz@arthur-schiwon.de>
apps/user_ldap/lib/User/User.php
apps/user_ldap/tests/User/UserTest.php

index f85e4206efffbb746df7764a2c79a099ad79bf09..cc80ac7a8751bc2e002499956101e9d9788e05b9 100644 (file)
@@ -714,7 +714,7 @@ class User {
                // 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;
                }
 
@@ -728,6 +728,15 @@ class User {
                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
index 470b0829868d383b7daf0dc89b854488d59d52f4..23ce407dfd7337c9b5c9f64478c477e9b55ba024 100644 (file)
@@ -585,9 +585,17 @@ class UserTest extends \Test\TestCase {
                $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')