aboutsummaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorCôme Chilliet <come.chilliet@nextcloud.com>2024-06-13 17:05:29 +0200
committerCôme Chilliet <91878298+come-nc@users.noreply.github.com>2024-08-19 10:33:11 +0200
commit2e05ae2ffc8207752b5aa3e7619704115942ebf1 (patch)
tree632085e411baf2e8a618c15cbefed723156e5922 /lib
parente472831280aa23dc6dfb1b147f50b097e91e4833 (diff)
downloadnextcloud-server-2e05ae2ffc8207752b5aa3e7619704115942ebf1.tar.gz
nextcloud-server-2e05ae2ffc8207752b5aa3e7619704115942ebf1.zip
fix: Remove shares only if there are no more common groups between users
Signed-off-by: Côme Chilliet <come.chilliet@nextcloud.com>
Diffstat (limited to 'lib')
-rw-r--r--lib/private/Share20/DefaultShareProvider.php74
1 files changed, 36 insertions, 38 deletions
diff --git a/lib/private/Share20/DefaultShareProvider.php b/lib/private/Share20/DefaultShareProvider.php
index 2d9ec7d3d68..65c4a167311 100644
--- a/lib/private/Share20/DefaultShareProvider.php
+++ b/lib/private/Share20/DefaultShareProvider.php
@@ -1306,6 +1306,7 @@ class DefaultShareProvider implements IShareProvider {
*
* @param string $uid
* @param string $gid
+ * @return void
*/
public function userDeletedFromGroup($uid, $gid) {
/*
@@ -1339,45 +1340,42 @@ class DefaultShareProvider implements IShareProvider {
}
if ($this->shareManager->shareWithGroupMembersOnly()) {
- $deleteQuery = $this->dbConn->getQueryBuilder();
- $deleteQuery->delete('share')
- ->where($deleteQuery->expr()->in('id', $deleteQuery->createParameter('id')));
+ $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);
- // 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);
+ 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);
+ }
+ }
}
}