|
8 | 8 | namespace OCA\Approval\Service; |
9 | 9 |
|
10 | 10 | use Exception; |
| 11 | +use OC; |
11 | 12 | use OCA\Approval\AppInfo\Application; |
| 13 | +use OCA\Circles\CirclesManager; |
| 14 | +use OCA\Circles\Exceptions\CircleNotFoundException; |
12 | 15 | use OCP\Constants; |
13 | 16 | use OCP\Files\IRootFolder; |
14 | 17 | use OCP\Files\Node; |
@@ -121,11 +124,11 @@ public function createShare(Node $node, int $type, string $sharedWith, string $s |
121 | 124 | * @return bool |
122 | 125 | */ |
123 | 126 | public function isUserInCircle(string $userId, string $circleId): bool { |
124 | | - $circlesManager = \OC::$server->get(\OCA\Circles\CirclesManager::class); |
| 127 | + $circlesManager = OC::$server->get(CirclesManager::class); |
125 | 128 | $circlesManager->startSuperSession(); |
126 | 129 | try { |
127 | 130 | $circle = $circlesManager->getCircle($circleId); |
128 | | - } catch (\OCA\Circles\Exceptions\CircleNotFoundException $e) { |
| 131 | + } catch (CircleNotFoundException $e) { |
129 | 132 | $circlesManager->stopSession(); |
130 | 133 | return false; |
131 | 134 | } |
@@ -166,6 +169,27 @@ public function userHasAccessTo(int $fileId, ?string $userId): bool { |
166 | 169 | return false; |
167 | 170 | } |
168 | 171 |
|
| 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 | + |
169 | 193 | /** |
170 | 194 | * @param string $name of the new tag |
171 | 195 | * @return array |
|
0 commit comments