Skip to content

Commit e47a3ac

Browse files
authored
Merge pull request #7501 from nextcloud/feature/54562/implement-ipartialshareprovider
feat: implement IPartialShareProvider support
2 parents 877d790 + 04904ff commit e47a3ac

File tree

1 file changed

+42
-1
lines changed

1 file changed

+42
-1
lines changed

lib/Sharing/DeckShareProvider.php

Lines changed: 42 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
use OCP\Share\Exceptions\GenericShareException;
3333
use OCP\Share\Exceptions\ShareNotFound;
3434
use OCP\Share\IManager;
35+
use OCP\Share\IPartialShareProvider;
3536
use OCP\Share\IShare;
3637

3738
/** Taken from the talk shareapicontroller helper */
@@ -42,7 +43,7 @@ public function formatShare(IShare $share): array;
4243
public function canAccessShare(IShare $share, string $user): bool;
4344
}
4445

45-
class DeckShareProvider implements \OCP\Share\IShareProvider {
46+
class DeckShareProvider implements \OCP\Share\IShareProvider, IPartialShareProvider {
4647
public const DECK_FOLDER = '/Deck';
4748
public const DECK_FOLDER_PLACEHOLDER = '/{DECK_PLACEHOLDER}';
4849

@@ -702,6 +703,34 @@ public function getSharesByPath(Node $path): array {
702703
* @return IShare[]
703704
*/
704705
public function getSharedWith($userId, $shareType, $node, $limit, $offset): array {
706+
return $this->_getSharedWith($userId, $limit, $offset, $node);
707+
}
708+
709+
public function getSharedWithByPath(
710+
string $userId,
711+
int $shareType,
712+
string $path,
713+
bool $forChildren,
714+
int $limit,
715+
int $offset,
716+
): iterable {
717+
return $this->_getSharedWith($userId, $limit, $offset, null, $path, $forChildren);
718+
}
719+
720+
/**
721+
* Get received shared for the given user.
722+
* You can optionally provide a node or a path to filter the shares.
723+
*
724+
* @return IShare[]
725+
*/
726+
private function _getSharedWith(
727+
string $userId,
728+
int $limit,
729+
int $offset,
730+
?Node $node = null,
731+
?string $path = null,
732+
?bool $forChildren = false,
733+
): array {
705734
$allBoards = $this->boardMapper->findBoardIds($userId);
706735

707736
/** @var IShare[] $shares */
@@ -740,6 +769,18 @@ public function getSharedWith($userId, $shareType, $node, $limit, $offset): arra
740769
$qb->andWhere($qb->expr()->eq('s.file_source', $qb->createNamedParameter($node->getId())));
741770
}
742771

772+
if ($path !== null) {
773+
$qb->leftJoin('s', 'share', 'sc', $qb->expr()->eq('s.parent', 'sc.id'))
774+
->andWhere($qb->expr()->eq('sc.share_type', $qb->createNamedParameter(IShare::TYPE_DECK_USER)))
775+
->andWhere($qb->expr()->eq('sc.share_with', $qb->createNamedParameter($userId)));
776+
777+
if ($forChildren) {
778+
$qb->andWhere($qb->expr()->like('sc.file_target', $qb->createNamedParameter($this->dbConnection->escapeLikeParameter($path) . '_%')));
779+
} else {
780+
$qb->andWhere($qb->expr()->eq('sc.file_target', $qb->createNamedParameter($path)));
781+
}
782+
}
783+
743784
$qb->andWhere($qb->expr()->eq('s.share_type', $qb->createNamedParameter(IShare::TYPE_DECK)))
744785
->andWhere($qb->expr()->in('db.id', $qb->createNamedParameter(
745786
$boards,

0 commit comments

Comments
 (0)