diff options
author | Julius Härtl <jus@bitgrid.net> | 2023-09-11 19:43:18 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-09-11 19:43:18 +0200 |
commit | 97dd09c4348ebbd88089cf572ac18e6cdf341493 (patch) | |
tree | 90aa5e3c61717bc16edb10ed1a88808cc5e62f1a /apps/user_ldap | |
parent | 9e2b2484317d2380baa46c7edd858c697dd51f9b (diff) | |
parent | 4054a7ddc8c29ae1cfb71507f7145257a0b08152 (diff) | |
download | nextcloud-server-97dd09c4348ebbd88089cf572ac18e6cdf341493.tar.gz nextcloud-server-97dd09c4348ebbd88089cf572ac18e6cdf341493.zip |
Merge pull request #39128 from nextcloud/fix/35319/ldap-missing-avatar
Diffstat (limited to 'apps/user_ldap')
-rw-r--r-- | apps/user_ldap/lib/User/User.php | 15 | ||||
-rw-r--r-- | apps/user_ldap/tests/User/UserTest.php | 12 |
2 files changed, 22 insertions, 5 deletions
diff --git a/apps/user_ldap/lib/User/User.php b/apps/user_ldap/lib/User/User.php index dac8bf1cfbc..0de30a18899 100644 --- a/apps/user_ldap/lib/User/User.php +++ b/apps/user_ldap/lib/User/User.php @@ -695,9 +695,9 @@ class User { /** * @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; } @@ -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 diff --git a/apps/user_ldap/tests/User/UserTest.php b/apps/user_ldap/tests/User/UserTest.php index 470b0829868..23ce407dfd7 100644 --- a/apps/user_ldap/tests/User/UserTest.php +++ b/apps/user_ldap/tests/User/UserTest.php @@ -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') |