Skip to content

Commit 98e4b16

Browse files
committed
Add $shallow arg to ShareByCircleProvider::getSharesInFolder
A new `$shallow` argument was introduced to `IShareProvider::getSharesInFolder` in NC25 by nextcloud/server#31728. This PR adds this new argument and the necessary changes to make it work based on this example https://github.com/nextcloud/server/pull/31728/files#diff-dee1351696d7eae959761edf66c8e5a9052e28be73319733d857a9ab2d9fc967= Signed-off-by: Louis Chemineau <louis@chmn.me>
1 parent ce43d60 commit 98e4b16

File tree

4 files changed

+25
-13
lines changed

4 files changed

+25
-13
lines changed

lib/Db/ShareWrapperRequest.php

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040
use OCP\Files\NotFoundException;
4141
use OCP\Share\Exceptions\IllegalIDChangeException;
4242
use OCP\Share\IShare;
43+
use OCP\Files\Folder;
4344

4445
/**
4546
* Class ShareWrapperRequest
@@ -358,25 +359,32 @@ public function getSharesBy(
358359

359360
/**
360361
* @param FederatedUser $federatedUser
361-
* @param int $nodeId
362+
* @param Folder $node
362363
* @param bool $reshares
364+
* @param bool $shallow Whether the method should stop at the first level, or look into sub-folders.
363365
*
364366
* @return ShareWrapper[]
365367
* @throws RequestBuilderException
366368
*/
367369
public function getSharesInFolder(
368370
FederatedUser $federatedUser,
369-
int $nodeId,
370-
bool $reshares
371+
Folder $node,
372+
bool $reshares,
373+
bool $shallow = true
371374
): array {
372375
$qb = $this->getShareSelectSql();
373376

374377
$qb->leftJoinCircle(CoreQueryBuilder::SHARE, null, 'share_with');
375378
$qb->limitToShareOwner(CoreQueryBuilder::SHARE, $federatedUser, $reshares);
376379
$qb->leftJoinFileCache(CoreQueryBuilder::SHARE);
377-
if ($nodeId > 0) {
380+
if (!is_null($node)) {
378381
$aliasFileCache = $qb->generateAlias(CoreQueryBuilder::SHARE, CoreQueryBuilder::FILE_CACHE);
379-
$qb->limitInt('parent', $nodeId, $aliasFileCache);
382+
383+
if ($shallow) {
384+
$qb->limitInt('parent', $node->getId(), $aliasFileCache);
385+
} else {
386+
$qb->like('path', $node->getInternalPath() . '/%', $aliasFileCache);
387+
}
380388
}
381389
$qb->limitNull('parent', false);
382390

lib/Service/ShareWrapperService.php

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@
4545
use OCP\ICache;
4646
use OCP\ICacheFactory;
4747
use OCP\Share\IShare;
48+
use OCP\Files\Folder;
4849

4950
/**
5051
* Class ShareWrapperService
@@ -267,14 +268,15 @@ public function getSharesBy(
267268

268269
/**
269270
* @param FederatedUser $federatedUser
270-
* @param int $nodeId
271+
* @param Folder $node
271272
* @param bool $reshares
273+
* @param bool $shallow Whether the method should stop at the first level, or look into sub-folders.
272274
*
273275
* @return ShareWrapper[]
274276
* @throws RequestBuilderException
275277
*/
276-
public function getSharesInFolder(FederatedUser $federatedUser, int $nodeId, bool $reshares): array {
277-
return $this->shareWrapperRequest->getSharesInFolder($federatedUser, $nodeId, $reshares);
278+
public function getSharesInFolder(FederatedUser $federatedUser, Folder $node, bool $reshares, bool $shallow = true): array {
279+
return $this->shareWrapperRequest->getSharesInFolder($federatedUser, $node, $reshares, $shallow);
278280
}
279281

280282

lib/ShareByCircleProvider.php

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -390,7 +390,7 @@ public function move(IShare $share, $recipient): IShare {
390390
* @param string $userId
391391
* @param Folder $node
392392
* @param bool $reshares
393-
*
393+
* @param bool $shallow Whether the method should stop at the first level, or look into sub-folders.
394394
* @return array
395395
* @throws ContactAddressBookNotFoundException
396396
* @throws ContactFormatException
@@ -404,12 +404,13 @@ public function move(IShare $share, $recipient): IShare {
404404
* @throws RequestBuilderException
405405
* @throws SingleCircleNotFoundException
406406
*/
407-
public function getSharesInFolder($userId, Folder $node, $reshares): array {
407+
public function getSharesInFolder($userId, Folder $node, $reshares, bool $shallow = true): array {
408408
$federatedUser = $this->federatedUserService->getLocalFederatedUser($userId);
409409
$wrappedShares = $this->shareWrapperService->getSharesInFolder(
410410
$federatedUser,
411-
(!is_null($node)) ? $node->getId() : 0,
412-
$reshares
411+
$node,
412+
$reshares,
413+
$shallow
413414
);
414415

415416
$result = [];

lib/ShareByCircleProviderDeprecated.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -378,10 +378,11 @@ private function createShareChild($userId, $share) {
378378
* @param Folder $node
379379
* @param bool $reshares Also get the shares where $user is the owner instead of just the
380380
* shares where $user is the initiator
381+
* @param bool $shallow Whether the method should stop at the first level, or look into sub-folders.
381382
*
382383
* @return Share[]
383384
*/
384-
public function getSharesInFolder($userId, Folder $node, $reshares) {
385+
public function getSharesInFolder($userId, Folder $node, $reshares, bool $shallow = true) {
385386
\OC::$server->getLogger()->log(3, 'deprecated>getSharesInFolder');
386387
return [];
387388
//

0 commit comments

Comments
 (0)