Skip to content

Commit 901eea1

Browse files
committed
when requesting with a rule having a group as approver, do not share the file with the group if it already has access
Signed-off-by: Julien Veyssier <julien-nc@posteo.net>
1 parent 5c576a6 commit 901eea1

2 files changed

Lines changed: 29 additions & 1 deletion

File tree

lib/Service/ApprovalService.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -582,7 +582,7 @@ private function shareWithApprovers(int $fileId, array $rule, string $userId): a
582582
}
583583
if ($this->shareManager->allowGroupSharing()) {
584584
foreach ($rule['approvers'] as $approver) {
585-
if ($approver['type'] === 'group') {
585+
if ($approver['type'] === 'group' && !$this->utilsService->groupHasAccessTo($fileId, $approver['entityId'])) {
586586
if ($this->utilsService->createShare($node, IShare::TYPE_GROUP, $approver['entityId'], $fileOwner, $label)) {
587587
$createdShares[] = $approver;
588588
}

lib/Service/UtilsService.php

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212
namespace OCA\Approval\Service;
1313

1414
use Exception;
15+
use OCP\IGroup;
16+
use OCP\IGroupManager;
1517
use OCP\IUserManager;
1618
use OCP\IUser;
1719
use OCP\Files\IRootFolder;
@@ -41,19 +43,25 @@ class UtilsService {
4143
* @var ISystemTagManager
4244
*/
4345
private $tagManager;
46+
/**
47+
* @var IGroupManager
48+
*/
49+
private $groupManager;
4450

4551
/**
4652
* Service providing storage, circles and tags tools
4753
*/
4854
public function __construct(string $appName,
4955
IUserManager $userManager,
56+
IGroupManager $groupManager,
5057
IShareManager $shareManager,
5158
IRootFolder $root,
5259
ISystemTagManager $tagManager) {
5360
$this->userManager = $userManager;
5461
$this->shareManager = $shareManager;
5562
$this->root = $root;
5663
$this->tagManager = $tagManager;
64+
$this->groupManager = $groupManager;
5765
}
5866

5967
/**
@@ -154,6 +162,26 @@ public function userHasAccessTo(int $fileId, ?string $userId): bool {
154162
return false;
155163
}
156164

165+
/**
166+
* Return false if at least one member of the group does not have access to the file
167+
*
168+
* @param int $fileId
169+
* @param string|null $groupId
170+
* @return bool
171+
*/
172+
public function groupHasAccessTo(int $fileId, ?string $groupId): bool {
173+
$group = $this->groupManager->get($groupId);
174+
if ($group instanceof IGroup) {
175+
foreach ($group->getUsers() as $groupUser) {
176+
if (!$this->userHasAccessTo($fileId, $groupUser->getUID())) {
177+
return false;
178+
}
179+
}
180+
return true;
181+
}
182+
return false;
183+
}
184+
157185
/**
158186
* @param string $name of the new tag
159187
* @return array

0 commit comments

Comments
 (0)