Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 42 additions & 1 deletion lib/Sharing/DeckShareProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
use OCP\Share\Exceptions\GenericShareException;
use OCP\Share\Exceptions\ShareNotFound;
use OCP\Share\IManager;
use OCP\Share\IPartialShareProvider;
use OCP\Share\IShare;

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

class DeckShareProvider implements \OCP\Share\IShareProvider {
class DeckShareProvider implements \OCP\Share\IShareProvider, IPartialShareProvider {
public const DECK_FOLDER = '/Deck';
public const DECK_FOLDER_PLACEHOLDER = '/{DECK_PLACEHOLDER}';

Expand Down Expand Up @@ -702,6 +703,34 @@ public function getSharesByPath(Node $path): array {
* @return IShare[]
*/
public function getSharedWith($userId, $shareType, $node, $limit, $offset): array {
return $this->_getSharedWith($userId, $limit, $offset, $node);
}

public function getSharedWithByPath(
string $userId,
int $shareType,
string $path,
bool $forChildren,
int $limit,
int $offset,
): iterable {
return $this->_getSharedWith($userId, $limit, $offset, null, $path, $forChildren);
}

/**
* Get received shared for the given user.
* You can optionally provide a node or a path to filter the shares.
*
* @return IShare[]
*/
private function _getSharedWith(
string $userId,
int $limit,
int $offset,
?Node $node = null,
?string $path = null,
?bool $forChildren = false,
): array {
$allBoards = $this->boardMapper->findBoardIds($userId);

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

if ($path !== null) {
$qb->leftJoin('s', 'share', 'sc', $qb->expr()->eq('s.parent', 'sc.id'))
->andWhere($qb->expr()->eq('sc.share_type', $qb->createNamedParameter(IShare::TYPE_DECK_USER)))
->andWhere($qb->expr()->eq('sc.share_with', $qb->createNamedParameter($userId)));

if ($forChildren) {
$qb->andWhere($qb->expr()->like('sc.file_target', $qb->createNamedParameter($this->dbConnection->escapeLikeParameter($path) . '_%')));
} else {
$qb->andWhere($qb->expr()->eq('sc.file_target', $qb->createNamedParameter($path)));
}
}

$qb->andWhere($qb->expr()->eq('s.share_type', $qb->createNamedParameter(IShare::TYPE_DECK)))
->andWhere($qb->expr()->in('db.id', $qb->createNamedParameter(
$boards,
Expand Down