diff options
author | John Molakvoæ <skjnldsv@users.noreply.github.com> | 2024-08-14 11:39:34 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-08-14 11:39:34 +0200 |
commit | aa7f5ac358ae9d489f5bbf71078e7066d25b0e9c (patch) | |
tree | cca54d82dd7c3eb6a50c2a21e62f3a49c5b5ad71 /lib | |
parent | 7b66e0d3c2dbcafb812b4815d9b2786d2b1b2a33 (diff) | |
parent | 3ea281269f846765b407cd9acf6ed931b3269556 (diff) | |
download | nextcloud-server-aa7f5ac358ae9d489f5bbf71078e7066d25b0e9c.tar.gz nextcloud-server-aa7f5ac358ae9d489f5bbf71078e7066d25b0e9c.zip |
Merge pull request #47192 from nextcloud/backport/47180/stable29
Diffstat (limited to 'lib')
-rw-r--r-- | lib/private/Share20/DefaultShareProvider.php | 46 | ||||
-rw-r--r-- | lib/private/Share20/ProviderFactory.php | 1 |
2 files changed, 45 insertions, 2 deletions
diff --git a/lib/private/Share20/DefaultShareProvider.php b/lib/private/Share20/DefaultShareProvider.php index f38dcf05298..fe13e336712 100644 --- a/lib/private/Share20/DefaultShareProvider.php +++ b/lib/private/Share20/DefaultShareProvider.php @@ -53,6 +53,7 @@ use OCP\L10N\IFactory; use OCP\Mail\IMailer; use OCP\Share\Exceptions\ShareNotFound; use OCP\Share\IAttributes; +use OCP\Share\IManager; use OCP\Share\IShare; use OCP\Share\IShareProvider; use Psr\Log\LoggerInterface; @@ -103,6 +104,7 @@ class DefaultShareProvider implements IShareProvider { IFactory $l10nFactory, IURLGenerator $urlGenerator, ITimeFactory $timeFactory, + private IManager $shareManager, ) { $this->dbConn = $connection; $this->userManager = $userManager; @@ -1293,6 +1295,7 @@ class DefaultShareProvider implements IShareProvider { * * @param string $uid * @param string $gid + * @return void */ public function userDeletedFromGroup($uid, $gid) { /* @@ -1304,7 +1307,7 @@ class DefaultShareProvider implements IShareProvider { ->where($qb->expr()->eq('share_type', $qb->createNamedParameter(IShare::TYPE_GROUP))) ->andWhere($qb->expr()->eq('share_with', $qb->createNamedParameter($gid))); - $cursor = $qb->execute(); + $cursor = $qb->executeQuery(); $ids = []; while ($row = $cursor->fetch()) { $ids[] = (int)$row['id']; @@ -1321,7 +1324,46 @@ class DefaultShareProvider implements IShareProvider { ->where($qb->expr()->eq('share_type', $qb->createNamedParameter(IShare::TYPE_USERGROUP))) ->andWhere($qb->expr()->eq('share_with', $qb->createNamedParameter($uid))) ->andWhere($qb->expr()->in('parent', $qb->createNamedParameter($chunk, IQueryBuilder::PARAM_INT_ARRAY))); - $qb->execute(); + $qb->executeStatement(); + } + } + + if ($this->shareManager->shareWithGroupMembersOnly()) { + $user = $this->userManager->get($uid); + if ($user === null) { + return; + } + $userGroups = $this->groupManager->getUserGroupIds($user); + $userGroups = array_diff($userGroups, $this->shareManager->shareWithGroupMembersOnlyExcludeGroupsList()); + + // Delete user shares received by the user from users in the group. + $userReceivedShares = $this->shareManager->getSharedWith($uid, IShare::TYPE_USER, null, -1); + foreach ($userReceivedShares as $share) { + $owner = $this->userManager->get($share->getSharedBy()); + if ($owner === null) { + continue; + } + $ownerGroups = $this->groupManager->getUserGroupIds($owner); + $mutualGroups = array_intersect($userGroups, $ownerGroups); + + if (count($mutualGroups) === 0) { + $this->shareManager->deleteShare($share); + } + } + + // Delete user shares from the user to users in the group. + $userEmittedShares = $this->shareManager->getSharesBy($uid, IShare::TYPE_USER, null, true, -1); + foreach ($userEmittedShares as $share) { + $recipient = $this->userManager->get($share->getSharedWith()); + if ($recipient === null) { + continue; + } + $recipientGroups = $this->groupManager->getUserGroupIds($recipient); + $mutualGroups = array_intersect($userGroups, $recipientGroups); + + if (count($mutualGroups) === 0) { + $this->shareManager->deleteShare($share); + } } } } diff --git a/lib/private/Share20/ProviderFactory.php b/lib/private/Share20/ProviderFactory.php index cac25226f1a..49307e219c7 100644 --- a/lib/private/Share20/ProviderFactory.php +++ b/lib/private/Share20/ProviderFactory.php @@ -109,6 +109,7 @@ class ProviderFactory implements IProviderFactory { $this->serverContainer->getL10NFactory(), $this->serverContainer->getURLGenerator(), $this->serverContainer->query(ITimeFactory::class), + $this->serverContainer->get(IManager::class), ); } |