Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/nextcloud/server.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVincent Petry <vincent@nextcloud.com>2021-10-04 12:04:04 +0300
committerVincent Petry <vincent@nextcloud.com>2021-10-04 12:04:04 +0300
commitfa23a9f720a7612ee337a55768d24d0085aed4f0 (patch)
tree0c32fa41bbf0ddae46c0a41f214249a17aab0b0a /apps/files/lib
parentc1d2a613d224eaf84abe99ea7217a92cd0c04d0a (diff)
Do not transfer shares for deleted users
Whenever a user was deleted but is still recipient of share entries, delete these entries upon transfer. Usually such entries would disappear after running cleanup background jobs. Signed-off-by: Vincent Petry <vincent@nextcloud.com>
Diffstat (limited to 'apps/files/lib')
-rw-r--r--apps/files/lib/Service/OwnershipTransferService.php27
1 files changed, 20 insertions, 7 deletions
diff --git a/apps/files/lib/Service/OwnershipTransferService.php b/apps/files/lib/Service/OwnershipTransferService.php
index ecb2365ef1b..93a3a188399 100644
--- a/apps/files/lib/Service/OwnershipTransferService.php
+++ b/apps/files/lib/Service/OwnershipTransferService.php
@@ -43,6 +43,7 @@ use OCP\Files\IHomeStorage;
use OCP\Files\InvalidPathException;
use OCP\Files\Mount\IMountManager;
use OCP\IUser;
+use OCP\IUserManager;
use OCP\Share\IManager as IShareManager;
use OCP\Share\IShare;
use Symfony\Component\Console\Helper\ProgressBar;
@@ -69,14 +70,19 @@ class OwnershipTransferService {
/** @var IUserMountCache */
private $userMountCache;
+ /** @var IUserManager */
+ private $userManager;
+
public function __construct(IEncryptionManager $manager,
IShareManager $shareManager,
IMountManager $mountManager,
- IUserMountCache $userMountCache) {
+ IUserMountCache $userMountCache,
+ IUserManager $userManager) {
$this->encryptionManager = $manager;
$this->shareManager = $shareManager;
$this->mountManager = $mountManager;
$this->userMountCache = $userMountCache;
+ $this->userManager = $userManager;
}
/**
@@ -401,13 +407,20 @@ class OwnershipTransferService {
$share->setSharedBy($destinationUid);
}
+ if ($share->getShareType() === IShare::TYPE_USER &&
+ !$this->userManager->userExists($share->getSharedWith())) {
+ // stray share with deleted user
+ $output->writeln('<error>Share with id ' . $share->getId() . ' points at deleted user "' . $share->getSharedWith() . '", deleting</error>');
+ $this->shareManager->deleteShare($share);
+ continue;
+ } else {
+ // trigger refetching of the node so that the new owner and mountpoint are taken into account
+ // otherwise the checks on the share update will fail due to the original node not being available in the new user scope
+ $this->userMountCache->clear();
+ $share->setNodeId($share->getNode()->getId());
- // trigger refetching of the node so that the new owner and mountpoint are taken into account
- // otherwise the checks on the share update will fail due to the original node not being available in the new user scope
- $this->userMountCache->clear();
- $share->setNodeId($share->getNode()->getId());
-
- $this->shareManager->updateShare($share);
+ $this->shareManager->updateShare($share);
+ }
}
} catch (\OCP\Files\NotFoundException $e) {
$output->writeln('<error>Share with id ' . $share->getId() . ' points at deleted file, skipping</error>');