Skip to content

Commit 63278ab

Browse files
salmart-devartonge
authored andcommitted
feat: implement IPartialShareProvider support
Signed-off-by: Salvatore Martire <4652631+salmart-dev@users.noreply.github.com>
1 parent a4110c9 commit 63278ab

File tree

1 file changed

+41
-1
lines changed

1 file changed

+41
-1
lines changed

lib/Sharing/DeckShareProvider.php

Lines changed: 41 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,17 @@ 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+
776+
if ($forChildren) {
777+
$qb->andWhere($qb->expr()->like('sc.file_target', $qb->createNamedParameter($this->dbConnection->escapeLikeParameter($path) . '_%')));
778+
} else {
779+
$qb->andWhere($qb->expr()->eq('sc.file_target', $qb->createNamedParameter($path)));
780+
}
781+
}
782+
743783
$qb->andWhere($qb->expr()->eq('s.share_type', $qb->createNamedParameter(IShare::TYPE_DECK)))
744784
->andWhere($qb->expr()->in('db.id', $qb->createNamedParameter(
745785
$boards,

0 commit comments

Comments
 (0)