summaryrefslogtreecommitdiffstats
path: root/lib/private
diff options
context:
space:
mode:
authorMorris Jobke <hey@morrisjobke.de>2020-04-27 11:06:50 +0200
committerGitHub <noreply@github.com>2020-04-27 11:06:50 +0200
commit673267cd91a340bbc9cf1414fe671dfe2cdf0799 (patch)
tree502d2b984cb7a7a3fab613ff8f8326639c25cd9f /lib/private
parent1738e17e204c813bc3ab970e18a94b415c41af41 (diff)
parentd74e9045ac5856c728e7b325ca0cfc22c92674bd (diff)
downloadnextcloud-server-673267cd91a340bbc9cf1414fe671dfe2cdf0799.tar.gz
nextcloud-server-673267cd91a340bbc9cf1414fe671dfe2cdf0799.zip
Merge pull request #19929 from nextcloud/bugfix/user-delete-avatar
Delete avatar if a user is deleted
Diffstat (limited to 'lib/private')
-rw-r--r--lib/private/Avatar/AvatarManager.php16
-rw-r--r--lib/private/User/User.php5
2 files changed, 21 insertions, 0 deletions
diff --git a/lib/private/Avatar/AvatarManager.php b/lib/private/Avatar/AvatarManager.php
index 3bb0c4077e2..37f57c90769 100644
--- a/lib/private/Avatar/AvatarManager.php
+++ b/lib/private/Avatar/AvatarManager.php
@@ -33,8 +33,10 @@ declare(strict_types=1);
namespace OC\Avatar;
use OC\User\Manager;
+use OC\User\NoUserException;
use OCP\Files\IAppData;
use OCP\Files\NotFoundException;
+use OCP\Files\NotPermittedException;
use OCP\IAvatar;
use OCP\IAvatarManager;
use OCP\IConfig;
@@ -125,6 +127,20 @@ class AvatarManager implements IAvatarManager {
}
}
+ public function deleteUserAvatar(string $userId): void {
+ try {
+ $folder = $this->appData->getFolder($userId);
+ $folder->delete();
+ } catch (NotFoundException $e) {
+ $this->logger->debug("No cache for the user $userId. Ignoring avatar deletion");
+ } catch (NotPermittedException $e) {
+ $this->logger->error("Unable to delete user avatars for $userId. gnoring avatar deletion");
+ } catch (NoUserException $e) {
+ $this->logger->debug("User $userId not found. gnoring avatar deletion");
+ }
+ $this->config->deleteUserValue($userId, 'avatar', 'generated');
+ }
+
/**
* Returns a GuestAvatar.
*
diff --git a/lib/private/User/User.php b/lib/private/User/User.php
index dd451c8eb3f..ccf5936c659 100644
--- a/lib/private/User/User.php
+++ b/lib/private/User/User.php
@@ -36,6 +36,7 @@
namespace OC\User;
use OC\Accounts\AccountManager;
+use OC\Avatar\AvatarManager;
use OC\Files\Cache\Storage;
use OC\Hooks\Emitter;
use OC_Helper;
@@ -238,6 +239,10 @@ class User implements IUser {
\OC::$server->getCommentsManager()->deleteReferencesOfActor('users', $this->uid);
\OC::$server->getCommentsManager()->deleteReadMarksFromUser($this);
+ /** @var IAvatarManager $avatarManager */
+ $avatarManager = \OC::$server->query(AvatarManager::class);
+ $avatarManager->deleteUserAvatar($this->uid);
+
$notification = \OC::$server->getNotificationManager()->createNotification();
$notification->setUser($this->uid);
\OC::$server->getNotificationManager()->markProcessed($notification);