Skip to content

Commit 47eb750

Browse files
authored
Merge pull request #320 from nextcloud/excessive-group-share2
fix file being shared with group when already shared
2 parents d4fcd4d + 35cfd20 commit 47eb750

File tree

2 files changed

+27
-3
lines changed

2 files changed

+27
-3
lines changed

lib/Service/ApprovalService.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -532,7 +532,7 @@ private function shareWithApprovers(int $fileId, array $rule, string $userId): a
532532
}
533533
if ($this->shareManager->allowGroupSharing()) {
534534
foreach ($rule['approvers'] as $approver) {
535-
if ($approver['type'] === 'group') {
535+
if ($approver['type'] === 'group' && !$this->utilsService->groupHasAccessTo($fileOwner, $node, $approver['entityId'])) {
536536
if ($this->utilsService->createShare($node, IShare::TYPE_GROUP, $approver['entityId'], $fileOwner, $label)) {
537537
$createdShares[] = $approver;
538538
}

lib/Service/UtilsService.php

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,10 @@
88
namespace OCA\Approval\Service;
99

1010
use Exception;
11+
use OC;
1112
use OCA\Approval\AppInfo\Application;
13+
use OCA\Circles\CirclesManager;
14+
use OCA\Circles\Exceptions\CircleNotFoundException;
1215
use OCP\Constants;
1316
use OCP\Files\IRootFolder;
1417
use OCP\Files\Node;
@@ -121,11 +124,11 @@ public function createShare(Node $node, int $type, string $sharedWith, string $s
121124
* @return bool
122125
*/
123126
public function isUserInCircle(string $userId, string $circleId): bool {
124-
$circlesManager = \OC::$server->get(\OCA\Circles\CirclesManager::class);
127+
$circlesManager = OC::$server->get(CirclesManager::class);
125128
$circlesManager->startSuperSession();
126129
try {
127130
$circle = $circlesManager->getCircle($circleId);
128-
} catch (\OCA\Circles\Exceptions\CircleNotFoundException $e) {
131+
} catch (CircleNotFoundException $e) {
129132
$circlesManager->stopSession();
130133
return false;
131134
}
@@ -166,6 +169,27 @@ public function userHasAccessTo(int $fileId, ?string $userId): bool {
166169
return false;
167170
}
168171

172+
/**
173+
* Return false if this folder and no parents are shared with that group
174+
*
175+
* @param string $userId
176+
* @param Node $fileNode
177+
* @param string|null $groupId
178+
* @return bool
179+
*/
180+
public function groupHasAccessTo(string $userId, Node $fileNode, ?string $groupId): bool {
181+
do {
182+
$groupShares = $this->shareManager->getSharesBy($userId, ISHARE::TYPE_GROUP, $fileNode);
183+
foreach ($groupShares as $groupShare) {
184+
if ($groupShare->getSharedWith() === $groupId) {
185+
return true;
186+
}
187+
}
188+
$fileNode = $fileNode->getParent();
189+
} while ($fileNode->getParentId() !== -1);
190+
return false;
191+
}
192+
169193
/**
170194
* @param string $name of the new tag
171195
* @return array

0 commit comments

Comments
 (0)