Skip to content
Draft
Show file tree
Hide file tree
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
19 changes: 18 additions & 1 deletion lib/Db/CoreQueryBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -345,6 +345,20 @@ public function limitToFileSource(int $nodeId): void {
$this->limitInt('file_source', $nodeId);
}

public function limitToFileTarget(string $target, string $alias): void {
$this->orWhere(
$this->exprLimit('file_target', $target),
$this->exprLimit('file_target', $target, $alias),
);
}

public function limitToFileTargetLike(string $target, string $alias): void {
$this->orWhere(
$this->exprLike('file_target', $target),
$this->exprLike('file_target', $target, $alias),
);
}

/**
* @param array $files
*/
Expand Down Expand Up @@ -1465,9 +1479,11 @@ public function leftJoinFileCache(string $aliasShare) {
* @param string $aliasShare
* @param string $aliasShareMemberships
*
* @return string the alias generated for the join
*
* @throws RequestBuilderException
*/
public function leftJoinShareChild(string $aliasShare, string $aliasShareMemberships = '') {
public function leftJoinShareChild(string $aliasShare, string $aliasShareMemberships = ''): string {
$expr = $this->expr();

$aliasShareChild = $this->generateAlias($aliasShare, self::SHARE);
Expand All @@ -1491,6 +1507,7 @@ public function leftJoinShareChild(string $aliasShare, string $aliasShareMembers
);

// $this->selectAlias($aliasShareParent . '.permissions', 'parent_perms');
return $aliasShareChild;
}


Expand Down
34 changes: 34 additions & 0 deletions lib/Db/ShareWrapperRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -359,6 +359,40 @@ public function getSharedWith(
return $this->getItemsFromRequest($qb);
}

public function getSharedWithByPath(
FederatedUser $federatedUser,
string $path,
bool $forChildren,
CircleProbe $probe,
): array {
$qb = $this->getShareSelectSql();
$qb->setOptions(
[CoreQueryBuilder::SHARE],
array_merge(
$probe->getAsOptions(),
['getData' => true]
)
);

$qb->leftJoinCircle(CoreQueryBuilder::SHARE, null, 'share_with');

$aliasCircle = $qb->generateAlias(CoreQueryBuilder::SHARE, CoreQueryBuilder::CIRCLE);
$qb->limitToFederatedUserMemberships(CoreQueryBuilder::SHARE, $aliasCircle, $federatedUser);

$qb->leftJoinFileCache(CoreQueryBuilder::SHARE);
$qb->limitNull('parent', false);
$childAlias = $qb->leftJoinShareChild(CoreQueryBuilder::SHARE);

if ($forChildren) {
$qb->limitToFileTargetLike($path . '_%', $childAlias);
} else {
$qb->limitToFileTarget($path, $childAlias);
}

$qb->chunk($probe->getItemsOffset(), $probe->getItemsLimit());

return $this->getItemsFromRequest($qb);
}

/**
* @param FederatedUser $federatedUser
Expand Down
35 changes: 35 additions & 0 deletions lib/Service/ShareWrapperService.php
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,29 @@ public function getSharedWith(
return $shares;
}

public function getSharedWithByPath(
FederatedUser $federatedUser,
string $path,
bool $forChildren,
?CircleProbe $probe,
): array {
$key = $this->generateSharedWithByPathCacheKey($federatedUser, $path, $forChildren, $probe?->getChecksum());

$cachedData = $this->cache->get($key);
try {
if (!is_string($cachedData)) {
throw new InvalidItemException();
}

return $this->deserializeList($cachedData, ShareWrapper::class);
} catch (InvalidItemException $e) {
}

$shares = $this->shareWrapperRequest->getSharedWithByPath($federatedUser, $path, $forChildren, $probe);
$this->cache->set($key, json_encode($shares), self::CACHE_SHARED_WITH_TTL);

return $shares;
}

/**
* @param FederatedUser $federatedUser
Expand Down Expand Up @@ -322,6 +345,18 @@ private function createChild(IShare $share, FederatedUser $federatedUser): Share
return $this->getShareById($childId, $federatedUser);
}

private function generateSharedWithByPathCacheKey(
FederatedUser $federatedUser,
string $path,
bool $forChildren,
?string $probeSum,
): string {
$pathHash = \md5($path);
return $federatedUser->getSingleId() . '#'
. $pathHash . '#'
. $forChildren . '#'
. $probeSum;
}

/**
* @param FederatedUser $federatedUser
Expand Down
45 changes: 44 additions & 1 deletion lib/ShareByCircleProvider.php
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
<?php

declare(strict_types=1);
Expand Down Expand Up @@ -56,6 +56,7 @@
use OCP\Share\Exceptions\AlreadySharedException;
use OCP\Share\Exceptions\IllegalIDChangeException;
use OCP\Share\Exceptions\ShareNotFound;
use OCP\Share\IPartialShareProvider;
use OCP\Share\IShare;
use OCP\Share\IShareProvider;
use Psr\Log\LoggerInterface;
Expand All @@ -65,7 +66,7 @@
*
* @package OCA\Circles
*/
class ShareByCircleProvider implements IShareProvider {
class ShareByCircleProvider implements IShareProvider, IPartialShareProvider {
use TArrayTools;
use TStringTools;
use TNCLogger;
Expand Down Expand Up @@ -522,6 +523,48 @@
);
}

/**
* @param bool $forChildren
* @inheritDoc
*/
public function getSharedWithByPath(
string $userId,
int $shareType,
string $path,
bool $forChildren,
int $limit,
int $offset,
): iterable {

Check failure on line 537 in lib/ShareByCircleProvider.php

View workflow job for this annotation

GitHub Actions / static-psalm-analysis

LessSpecificImplementedReturnType

lib/ShareByCircleProvider.php:537:5: LessSpecificImplementedReturnType: The inherited return type 'iterable<mixed, OCP\Share\IShare>' for OCP\Share\IPartialShareProvider::getSharedWithByPath is more specific than the implemented return type for OCA\Circles\ShareByCircleProvider::getsharedwithbypath 'iterable<mixed, mixed>' (see https://psalm.dev/166)
if ($shareType !== IShare::TYPE_CIRCLE) {
return [];
}

$federatedUser = $this->federatedUserService->getLocalFederatedUser($userId);
$probe = new CircleProbe();
$probe->includePersonalCircles()
->includeSystemCircles()
->mustBeMember()
->setItemsLimit((int)$limit)

Check failure on line 547 in lib/ShareByCircleProvider.php

View workflow job for this annotation

GitHub Actions / static-psalm-analysis

RedundantCast

lib/ShareByCircleProvider.php:547:20: RedundantCast: Redundant cast to int (see https://psalm.dev/262)
->setItemsOffset((int)$offset);

Check failure on line 548 in lib/ShareByCircleProvider.php

View workflow job for this annotation

GitHub Actions / static-psalm-analysis

RedundantCast

lib/ShareByCircleProvider.php:548:21: RedundantCast: Redundant cast to int (see https://psalm.dev/262)

$wrappedShares = $this->shareWrapperService->getSharedWithByPath(

Check failure on line 550 in lib/ShareByCircleProvider.php

View workflow job for this annotation

GitHub Actions / static-psalm-analysis

TooManyArguments

lib/ShareByCircleProvider.php:550:48: TooManyArguments: Too many arguments for method OCA\Circles\Service\ShareWrapperService::getsharedwithbypath - saw 5 (see https://psalm.dev/026)
$federatedUser,
$path,
$forChildren,
$probe,
$probe,
);

return array_filter(
array_map(
function (ShareWrapper $wrapper) {
return $wrapper->getShare(
$this->rootFolder, $this->userManager, $this->urlGenerator, true
);
}, $wrappedShares
)
);
}

/**
* @param string $token
Expand Down Expand Up @@ -776,7 +819,7 @@


/**
* @return iterable

Check failure on line 822 in lib/ShareByCircleProvider.php

View workflow job for this annotation

GitHub Actions / static-psalm-analysis

LessSpecificImplementedReturnType

lib/ShareByCircleProvider.php:822:13: LessSpecificImplementedReturnType: The inherited return type 'iterable<mixed, OCP\Share\IShare>' for OCP\Share\IShareProvider::getAllShares is more specific than the implemented return type for OCA\Circles\ShareByCircleProvider::getallshares 'iterable<mixed, mixed>' (see https://psalm.dev/166)
*/
public function getAllShares(): iterable {
// $qb = $this->dbConnection->getQueryBuilder();
Expand Down
Loading