diff --git a/lib/Service/ApprovalService.php b/lib/Service/ApprovalService.php index 9be7374b..bda50992 100644 --- a/lib/Service/ApprovalService.php +++ b/lib/Service/ApprovalService.php @@ -532,7 +532,7 @@ private function shareWithApprovers(int $fileId, array $rule, string $userId): a } if ($this->shareManager->allowGroupSharing()) { foreach ($rule['approvers'] as $approver) { - if ($approver['type'] === 'group') { + if ($approver['type'] === 'group' && !$this->utilsService->groupHasAccessTo($fileOwner, $node, $approver['entityId'])) { if ($this->utilsService->createShare($node, IShare::TYPE_GROUP, $approver['entityId'], $fileOwner, $label)) { $createdShares[] = $approver; } diff --git a/lib/Service/UtilsService.php b/lib/Service/UtilsService.php index cc6092bb..2f611ed9 100644 --- a/lib/Service/UtilsService.php +++ b/lib/Service/UtilsService.php @@ -8,7 +8,10 @@ namespace OCA\Approval\Service; use Exception; +use OC; use OCA\Approval\AppInfo\Application; +use OCA\Circles\CirclesManager; +use OCA\Circles\Exceptions\CircleNotFoundException; use OCP\Constants; use OCP\Files\IRootFolder; use OCP\Files\Node; @@ -121,11 +124,11 @@ public function createShare(Node $node, int $type, string $sharedWith, string $s * @return bool */ public function isUserInCircle(string $userId, string $circleId): bool { - $circlesManager = \OC::$server->get(\OCA\Circles\CirclesManager::class); + $circlesManager = OC::$server->get(CirclesManager::class); $circlesManager->startSuperSession(); try { $circle = $circlesManager->getCircle($circleId); - } catch (\OCA\Circles\Exceptions\CircleNotFoundException $e) { + } catch (CircleNotFoundException $e) { $circlesManager->stopSession(); return false; } @@ -166,6 +169,27 @@ public function userHasAccessTo(int $fileId, ?string $userId): bool { return false; } + /** + * Return false if this folder and no parents are shared with that group + * + * @param string $userId + * @param Node $fileNode + * @param string|null $groupId + * @return bool + */ + public function groupHasAccessTo(string $userId, Node $fileNode, ?string $groupId): bool { + do { + $groupShares = $this->shareManager->getSharesBy($userId, ISHARE::TYPE_GROUP, $fileNode); + foreach ($groupShares as $groupShare) { + if ($groupShare->getSharedWith() === $groupId) { + return true; + } + } + $fileNode = $fileNode->getParent(); + } while ($fileNode->getParentId() !== -1); + return false; + } + /** * @param string $name of the new tag * @return array