aboutsummaryrefslogtreecommitdiffstats
path: root/lib/private
diff options
context:
space:
mode:
Diffstat (limited to 'lib/private')
-rw-r--r--lib/private/Share20/DefaultShareProvider.php46
-rw-r--r--lib/private/Share20/ProviderFactory.php1
2 files changed, 45 insertions, 2 deletions
diff --git a/lib/private/Share20/DefaultShareProvider.php b/lib/private/Share20/DefaultShareProvider.php
index 366b9cad976..6d1d04d3c0b 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,
) {
}
@@ -1223,6 +1225,7 @@ class DefaultShareProvider implements IShareProviderWithNotification, IShareProv
*
* @param string $uid
* @param string $gid
+ * @return void
*/
public function userDeletedFromGroup($uid, $gid) {
/*
@@ -1234,7 +1237,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,7 +1254,46 @@ 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()) {
+ $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 dbe251a49df..37af0482838 100644
--- a/lib/private/Share20/ProviderFactory.php
+++ b/lib/private/Share20/ProviderFactory.php
@@ -88,6 +88,7 @@ class ProviderFactory implements IProviderFactory {
$this->serverContainer->getURLGenerator(),
$this->serverContainer->query(ITimeFactory::class),
$this->serverContainer->get(LoggerInterface::class),
+ $this->serverContainer->get(IManager::class),
);
}