diff --git a/lib/Share/RoomShareProvider.php b/lib/Share/RoomShareProvider.php index e4eeb1445c4..0081e94e0fb 100644 --- a/lib/Share/RoomShareProvider.php +++ b/lib/Share/RoomShareProvider.php @@ -31,6 +31,7 @@ use OCP\Share\Exceptions\GenericShareException; use OCP\Share\Exceptions\ShareNotFound; use OCP\Share\IManager as IShareManager; +use OCP\Share\IPartialShareProvider; use OCP\Share\IShare; use OCP\Share\IShareProvider; @@ -44,7 +45,7 @@ * Like in group shares, a recipient can move or delete a share without * modifying the share for the other users in the room. */ -class RoomShareProvider implements IShareProvider { +class RoomShareProvider implements IShareProvider, IPartialShareProvider { use TTransactional; // Special share type for user modified room shares public const SHARE_TYPE_USERROOM = 11; @@ -792,6 +793,33 @@ public function getSharesByPath(Node $path): array { */ #[\Override] public function getSharedWith($userId, $shareType, $node, $limit, $offset): array { + return $this->_getSharedWith($userId, $limit, $offset, $node); + } + + #[\Override] + 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. + */ + public function _getSharedWith( + string $userId, + int $limit, + int $offset, + ?Node $node = null, + ?string $path = null, + ?bool $forChildren = false, + ): array { $allRooms = $this->manager->getRoomTokensWithAttachmentsForUser($userId); if (empty($allRooms)) { @@ -824,6 +852,17 @@ 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(self::SHARE_TYPE_USERROOM))); + + if ($forChildren) { + $qb->andWhere($qb->expr()->like('s.file_target', $qb->createNamedParameter($this->dbConnection->escapeLikeParameter($path) . '_%'))); + } else { + $qb->andWhere($qb->expr()->eq('s.file_target', $qb->createNamedParameter($path))); + } + } + $qb->andWhere($qb->expr()->eq('s.share_type', $qb->createNamedParameter(IShare::TYPE_ROOM))) ->andWhere($qb->expr()->in('s.share_with', $qb->createNamedParameter( $rooms,