Skip to content
Merged
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
18 changes: 18 additions & 0 deletions lib/CirclesManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -344,6 +344,24 @@ public function getCircle(string $singleId, ?CircleProbe $probe = null): Circle
return $this->circleService->getCircle($singleId, $probe);
}

/**
* better than using getCircle() if only interested in teams current user is member of
*
* @since 33.0.0
*/
public function probeCircle(string $singleId, ?CircleProbe $probe = null, ?DataProbe $dataProbe = null): Circle {
return $this->circleService->probeCircle($singleId, $probe, $dataProbe);
}

/**
* get details from a list of circles the current user is a member of
*
* @since 33.0.0
*/
public function getCirclesByIds(array $ids, ?DataProbe $dataProbe = null): array {
return $this->circleService->probeCirclesByIds($ids, $dataProbe);
}


/**
* @param Circle $circle
Expand Down
30 changes: 30 additions & 0 deletions lib/Db/CircleRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,36 @@ public function probeCircles(
return $this->getItemsFromRequest($qb);
}

/**
* returns details about circles using a list of ids.
* initiator permissions are respected
*/
public function probeCirclesByIds(
IFederatedUser $initiator,
array $ids,
DataProbe $dataProbe,
): array {
$qb = $this->getCircleSelectSql();
if (!$dataProbe->has(DataProbe::MEMBERSHIPS)) {
$dataProbe->add(DataProbe::MEMBERSHIPS);
}

$qb->setSqlPath(CoreQueryBuilder::CIRCLE, $dataProbe->getPath());
$qb->leftJoinOwner(CoreQueryBuilder::CIRCLE);
$qb->innerJoinMembership(null, CoreQueryBuilder::CIRCLE);

$aliasMembership = $qb->generateAlias(CoreQueryBuilder::CIRCLE, CoreQueryBuilder::MEMBERSHIPS);
$limit = $qb->exprLimit('single_id', $initiator->getSingleId(), $aliasMembership);
$qb->completeProbeWithInitiator(CoreQueryBuilder::CIRCLE, 'single_id', $aliasMembership);
$qb->andWhere(
$limit,
$qb->expr()->in(CoreQueryBuilder::CIRCLE . '.unique_id', $qb->createNamedParameter($ids, IQueryBuilder::PARAM_STR_ARRAY))
);
$qb->resetSqlPath();

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

/**
* @param IFederatedUser|null $initiator
* @param CircleProbe $circleProbe
Expand Down
4 changes: 2 additions & 2 deletions lib/Db/CoreQueryBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -843,7 +843,7 @@ public function leftJoinOwner(string $alias, string $field = 'unique_id'): void
* @param string $field
*/
public function innerJoinMembership(
CircleProbe $probe,
?CircleProbe $probe,
string $alias,
string $field = 'unique_id',
): void {
Expand All @@ -862,7 +862,7 @@ public function innerJoinMembership(
$on = $expr->andX($expr->eq($aliasMembership . '.circle_id', $alias . '.' . $field));

// limit on membership level if requested
$minLevel = $probe->getMinimumLevel();
$minLevel = $probe?->getMinimumLevel() ?? 0;
if ($minLevel > Member::LEVEL_MEMBER) {
$on->add($this->exprGt('level', $minLevel, true, $aliasMembership));
}
Expand Down
18 changes: 18 additions & 0 deletions lib/Db/ShareWrapperRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,24 @@ public function getSharesToCircle(
}


/**
* @param string $circleId
* @param FederatedUser|null $shareRecipient
* @param FederatedUser|null $shareInitiator
* @param bool $completeDetails
*
* @return ShareWrapper[]
* @throws RequestBuilderException
*/
public function getSharesToCircles(array $circleIds): array {
$qb = $this->getShareSelectSql();
$qb->limitNull('parent', false);
$qb->expr()->in('share_with', $qb->createNamedParameter($circleIds, IQueryBuilder::PARAM_STR_ARRAY));
return $this->getItemsFromRequest($qb);
}



/**
* @param int $shareId
* @param FederatedUser|null $federatedUser
Expand Down
29 changes: 29 additions & 0 deletions lib/FileSharingTeamResourceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,35 @@ public function getSharedWith(string $teamId): array {
}

$shares = $this->shareByCircleProvider->getSharesToCircle($teamId);
return $this->convertWrappedShareToResource($shares);
}

/**
* @return array<string, TeamResource[]>
*/
public function getSharedWithList(array $teams): array {
$data = $shares = [];
foreach ($this->shareByCircleProvider->getSharesToCircles($teams) as $share) {
if (!array_key_exists($share->getId(), $shares)) {
$shares[$share->getSharedWith()] = [];
}
$shares[$share->getSharedWith()][] = $share;
}

foreach ($teams as $teamId) {
$data[$teamId] = $this->convertWrappedShareToResource($shares[$teamId]);
}

return $data;
}

/**
* convert list of ShareWrapper to TeamResource
*
* @param ShareWrapper[] $shares
* @return TeamResource[]
*/
private function convertWrappedShareToResource(array $shares): array {
usort($shares, function ($a, $b) {
return (int)($b->getItemType() === 'folder') - (int)($a->getItemType() === 'folder');
});
Expand Down
15 changes: 15 additions & 0 deletions lib/Service/CircleService.php
Original file line number Diff line number Diff line change
Expand Up @@ -811,4 +811,19 @@ public function probeCircles(CircleProbe $circleProbe, ?DataProbe $dataProbe = n
$dataProbe
);
}

/**
* @return Circle[]
*/
public function probeCirclesByIds(array $ids, ?DataProbe $dataProbe = null): array {
if (empty($ids)) {
return [];
}
$this->federatedUserService->mustHaveCurrentUser();
return $this->circleRequest->probeCirclesByIds(
$this->federatedUserService->getCurrentUser(),
$ids,
$dataProbe ?? new DataProbe()
);
}
}
7 changes: 7 additions & 0 deletions lib/Service/ShareWrapperService.php
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,13 @@ public function getSharesToCircle(
);
}

/**
* @return ShareWrapper[]
*/
public function getSharesToCircles(array $circleIds): array {
return $this->shareWrapperRequest->getSharesToCircles($circleIds);
}


/**
* @param int $shareId
Expand Down
Loading