aboutsummaryrefslogtreecommitdiffstats
path: root/lib/private/Share20/DefaultShareProvider.php
diff options
context:
space:
mode:
authorLouis Chemineau <louis@chmn.me>2024-05-22 11:55:47 +0200
committerCôme Chilliet <come.chilliet@nextcloud.com>2024-08-12 14:41:19 +0200
commit5559beb28c336b39a09ff0965296d7647c62d99b (patch)
tree6b6ebc28136f77949ccd24851479b573775abc82 /lib/private/Share20/DefaultShareProvider.php
parent1a7acf061e26d938e2162f791afb262dc7c2b90d (diff)
downloadnextcloud-server-5559beb28c336b39a09ff0965296d7647c62d99b.tar.gz
nextcloud-server-5559beb28c336b39a09ff0965296d7647c62d99b.zip
fix(files_sharing): Delete user shares if needed when user is removed from a group
Signed-off-by: Louis Chemineau <louis@chmn.me>
Diffstat (limited to 'lib/private/Share20/DefaultShareProvider.php')
-rw-r--r--lib/private/Share20/DefaultShareProvider.php48
1 files changed, 46 insertions, 2 deletions
diff --git a/lib/private/Share20/DefaultShareProvider.php b/lib/private/Share20/DefaultShareProvider.php
index 366b9cad976..ce37e141af2 100644
--- a/lib/private/Share20/DefaultShareProvider.php
+++ b/lib/private/Share20/DefaultShareProvider.php
@@ -28,6 +28,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\IShareProviderSupportsAccept;
use OCP\Share\IShareProviderWithNotification;
@@ -54,6 +55,7 @@ class DefaultShareProvider implements IShareProviderWithNotification, IShareProv
private IURLGenerator $urlGenerator,
private ITimeFactory $timeFactory,
private LoggerInterface $logger,
+ private IManager $shareManager,
) {
}
@@ -1234,7 +1236,7 @@ class DefaultShareProvider implements IShareProviderWithNotification, IShareProv
->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'];
@@ -1251,9 +1253,51 @@ class DefaultShareProvider implements IShareProviderWithNotification, IShareProv
->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()) {
+ $deleteQuery = $this->dbConn->getQueryBuilder();
+ $deleteQuery->delete('share')
+ ->where($deleteQuery->expr()->in('id', $deleteQuery->createParameter('id')));
+
+ // Delete direct shares received by the user from users in the group.
+ $selectInboundShares = $this->dbConn->getQueryBuilder();
+ $selectInboundShares->select('id')
+ ->from('share', 's')
+ ->join('s', 'group_user', 'g', 's.uid_initiator = g.uid')
+ ->where($selectInboundShares->expr()->eq('share_type', $selectInboundShares->createNamedParameter(IShare::TYPE_USER)))
+ ->andWhere($selectInboundShares->expr()->eq('share_with', $selectInboundShares->createNamedParameter($uid)))
+ ->andWhere($selectInboundShares->expr()->eq('gid', $selectInboundShares->createNamedParameter($gid)))
+ ->setMaxResults(1000)
+ ->executeQuery();
+
+ do {
+ $rows = $selectInboundShares->executeQuery();
+ $ids = $rows->fetchAll();
+ $deleteQuery->setParameter('id', array_column($ids, 'id'), IQueryBuilder::PARAM_INT_ARRAY);
+ $deleteQuery->executeStatement();
+ } while (count($ids) > 0);
+
+ // Delete direct shares from the user to users in the group.
+ $selectOutboundShares = $this->dbConn->getQueryBuilder();
+ $selectOutboundShares->select('id')
+ ->from('share', 's')
+ ->join('s', 'group_user', 'g', 's.share_with = g.uid')
+ ->where($selectOutboundShares->expr()->eq('share_type', $selectOutboundShares->createNamedParameter(IShare::TYPE_USER)))
+ ->andWhere($selectOutboundShares->expr()->eq('uid_initiator', $selectOutboundShares->createNamedParameter($uid)))
+ ->andWhere($selectOutboundShares->expr()->eq('gid', $selectOutboundShares->createNamedParameter($gid)))
+ ->setMaxResults(1000)
+ ->executeQuery();
+
+ do {
+ $rows = $selectOutboundShares->executeQuery();
+ $ids = $rows->fetchAll();
+ $deleteQuery->setParameter('id', array_column($ids, 'id'), IQueryBuilder::PARAM_INT_ARRAY);
+ $deleteQuery->executeStatement();
+ } while (count($ids) > 0);
+ }
}
/**