Skip to content

Commit 25e9ff1

Browse files
committed
feature: implement IPartialShareProvider support
Signed-off-by: Salvatore Martire <[email protected]>
1 parent 2975e6d commit 25e9ff1

File tree

1 file changed

+64
-1
lines changed

1 file changed

+64
-1
lines changed

lib/Share/RoomShareProvider.php

Lines changed: 64 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;
@@ -856,6 +857,68 @@ public function getSharedWith($userId, $shareType, $node, $limit, $offset): arra
856857
return $shares;
857858
}
858859

860+
/**
861+
* @param bool $forChildren
862+
* @inheritDoc
863+
*/
864+
public function getSharedWithByPath(
865+
string $userId,
866+
int $shareType,
867+
string $path,
868+
bool $forChildren,
869+
int $limit,
870+
int $offset,
871+
): iterable {
872+
/** @var IShare[] $shares */
873+
$shares = [];
874+
$qb = $this->dbConnection->getQueryBuilder();
875+
$qb->select('s.*', 's2.permissions AS s2_permissions', 's2.file_target AS s2_file_target',
876+
'f.fileid', 'f.path', 'f.permissions AS f_permissions', 'f.storage', 'f.path_hash',
877+
'f.parent AS f_parent', 'f.name', 'f.mimetype', 'f.mimepart', 'f.size', 'f.mtime', 'f.storage_mtime',
878+
'f.encrypted', 'f.unencrypted_size', 'f.etag', 'f.checksum'
879+
)
880+
->selectAlias('st.id', 'storage_string_id')
881+
->from('share', 's2')
882+
->orderBy('s2.id', 'ASC')
883+
->leftJoin('s2', 'filecache', 'f', $qb->expr()->eq('s2.file_source', 'f.fileid'))
884+
->leftJoin('s2', 'share', 's', $qb->expr()->eq('s2.parent', 's.id'))
885+
->leftJoin('f', 'storages', 'st', $qb->expr()->eq('f.storage', 'st.numeric_id'))
886+
->setFirstResult($offset);
887+
888+
if ($limit !== -1) {
889+
$qb->setMaxResults($limit);
890+
}
891+
892+
$qb->andWhere($qb->expr()->eq('s2.share_type', $qb->createNamedParameter(self::SHARE_TYPE_USERROOM)))
893+
->andWhere($qb->expr()->eq('s2.share_with', $qb->createNamedParameter($userId)))
894+
->andWhere($qb->expr()->neq('s2.uid_initiator', $qb->createNamedParameter($userId)))
895+
->andWhere($qb->expr()->neq('s2.uid_owner', $qb->createNamedParameter($userId)));
896+
897+
if ($forChildren) {
898+
$qb->andWhere($qb->expr()->like('s2.file_target', $qb->createNamedParameter($this->dbConnection->escapeLikeParameter($path) . '_%')));
899+
} else {
900+
$qb->andWhere($qb->expr()->eq('s2.file_target', $qb->createNamedParameter($path)));
901+
}
902+
903+
$cursor = $qb->executeQuery();
904+
while ($data = $cursor->fetch()) {
905+
if (!$this->isAccessibleResult($data)) {
906+
continue;
907+
}
908+
909+
$share = $this->createShareObject($data);
910+
// patch the parent data with the user-specific changes
911+
$share->setPermissions((int)$data['s2_permissions']);
912+
$share->setTarget($data['s2_file_target']);
913+
$shares[] = $share;
914+
}
915+
$cursor->closeCursor();
916+
917+
// todo: check for group membership?
918+
919+
return $shares;
920+
}
921+
859922
private function isAccessibleResult(array $data): bool {
860923
// exclude shares leading to deleted file entries
861924
if ($data['fileid'] === null || $data['path'] === null) {

0 commit comments

Comments
 (0)