Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/Service/ApprovalService.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
28 changes: 26 additions & 2 deletions lib/Service/UtilsService.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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
Expand Down
Loading