Skip to content

Commit 756bbae

Browse files
salmart-devnickvergessen
authored andcommitted
feature: implement IPartialShareProvider support
Signed-off-by: Salvatore Martire <4652631+salmart-dev@users.noreply.github.com> Signed-off-by: Louis Chmn <louis@chmn.me>
1 parent 5608d73 commit 756bbae

File tree

1 file changed

+40
-1
lines changed

1 file changed

+40
-1
lines changed

lib/Share/RoomShareProvider.php

Lines changed: 40 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
use OCP\Share\Exceptions\GenericShareException;
3232
use OCP\Share\Exceptions\ShareNotFound;
3333
use OCP\Share\IManager as IShareManager;
34+
use OCP\Share\IPartialShareProvider;
3435
use OCP\Share\IShare;
3536
use OCP\Share\IShareProvider;
3637

@@ -44,7 +45,7 @@
4445
* Like in group shares, a recipient can move or delete a share without
4546
* modifying the share for the other users in the room.
4647
*/
47-
class RoomShareProvider implements IShareProvider {
48+
class RoomShareProvider implements IShareProvider, IPartialShareProvider {
4849
use TTransactional;
4950
// Special share type for user modified room shares
5051
public const SHARE_TYPE_USERROOM = 11;
@@ -792,6 +793,33 @@ public function getSharesByPath(Node $path): array {
792793
*/
793794
#[\Override]
794795
public function getSharedWith($userId, $shareType, $node, $limit, $offset): array {
796+
return $this->_getSharedWith($userId, $limit, $offset, $node);
797+
}
798+
799+
#[\Override]
800+
public function getSharedWithByPath(
801+
string $userId,
802+
int $shareType,
803+
string $path,
804+
bool $forChildren,
805+
int $limit,
806+
int $offset,
807+
): iterable {
808+
return $this->_getSharedWith($userId, $limit, $offset, null, $path, $forChildren);
809+
}
810+
811+
/**
812+
* Get received shared for the given user.
813+
* You can optionally provide a node or a path to filter the shares.
814+
*/
815+
private function _getSharedWith(
816+
string $userId,
817+
int $limit,
818+
int $offset,
819+
?Node $node = null,
820+
?string $path = null,
821+
?bool $forChildren = false,
822+
): iterable {
795823
$allRooms = $this->manager->getRoomTokensWithAttachmentsForUser($userId);
796824

797825
if (empty($allRooms)) {
@@ -824,6 +852,17 @@ public function getSharedWith($userId, $shareType, $node, $limit, $offset): arra
824852
$qb->andWhere($qb->expr()->eq('s.file_source', $qb->createNamedParameter($node->getId())));
825853
}
826854

855+
if ($path !== null) {
856+
$qb->leftJoin('s', 'share', 'sc', $qb->expr()->eq('s.parent', 'sc.id'))
857+
->andWhere($qb->expr()->eq('sc.share_type', $qb->createNamedParameter(self::SHARE_TYPE_USERROOM)));
858+
859+
if ($forChildren) {
860+
$qb->andWhere($qb->expr()->like('s.file_target', $qb->createNamedParameter($this->dbConnection->escapeLikeParameter($path) . '_%')));
861+
} else {
862+
$qb->andWhere($qb->expr()->eq('s.file_target', $qb->createNamedParameter($path)));
863+
}
864+
}
865+
827866
$qb->andWhere($qb->expr()->eq('s.share_type', $qb->createNamedParameter(IShare::TYPE_ROOM)))
828867
->andWhere($qb->expr()->in('s.share_with', $qb->createNamedParameter(
829868
$rooms,

0 commit comments

Comments
 (0)