Skip to content

Commit

Permalink
implements getAccessList
Browse files Browse the repository at this point in the history
Signed-off-by: Maxence Lange <maxence@artificial-owl.com>
  • Loading branch information
ArtificialOwl authored and backportbot[bot] committed Jun 13, 2024
1 parent 8938fcb commit 37b6279
Show file tree
Hide file tree
Showing 4 changed files with 73 additions and 5 deletions.
24 changes: 24 additions & 0 deletions lib/Db/ShareWrapperRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -275,6 +275,30 @@ public function getSharesByFileId(int $fileId, bool $getData = false): array {
}


/**
* returns all share, related to a list of fileids.
* if $getData is true, will return details about the recipient circle.
*
* @param array $fileIds
* @param bool $getData
*
* @return ShareWrapper[]
* @throws RequestBuilderException
*/
public function getSharesByFileIds(array $fileIds, bool $getData = false): array {
$qb = $this->getShareSelectSql();
$qb->limitToFileSourceArray($fileIds);

if ($getData) {
$qb->setOptions([CoreQueryBuilder::SHARE], ['getData' => $getData]);
$qb->leftJoinCircle(CoreQueryBuilder::SHARE, null, 'share_with');
$qb->limitNull('parent', false);
}

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


/**
* @param FederatedUser $federatedUser
* @param int $nodeId
Expand Down
11 changes: 11 additions & 0 deletions lib/Service/ShareWrapperService.php
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,17 @@ public function getSharesByFileId(int $fileId, bool $getData = false): array {
return $this->shareWrapperRequest->getSharesByFileId($fileId, $getData);
}

/**
* @param array $fileIds
* @param bool $getData
*
* @return ShareWrapper[]
* @throws RequestBuilderException
*/
public function getSharesByFileIds(array $fileIds, bool $getData = false): array {
return $this->shareWrapperRequest->getSharesByFileIds($fileIds, $getData);
}

/**
* @param string $token
* @param FederatedUser|null $federatedUser
Expand Down
39 changes: 38 additions & 1 deletion lib/ShareByCircleProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@
use OCA\Circles\FederatedItems\Files\FileShare;
use OCA\Circles\FederatedItems\Files\FileUnshare;
use OCA\Circles\Model\Federated\FederatedEvent;
use OCA\Circles\Model\Member;
use OCA\Circles\Model\Probes\CircleProbe;
use OCA\Circles\Model\Probes\DataProbe;
use OCA\Circles\Model\ShareWrapper;
Expand Down Expand Up @@ -654,7 +655,43 @@ public function userDeletedFromGroup($uid, $gid): void {
* @return array
*/
public function getAccessList($nodes, $currentAccess): array {
return [];
$ids = [];
foreach ($nodes as $node) {
$ids[] = $node->getId();
}

$users = $remote = $mails = [];
$shares = $this->shareWrapperService->getSharesByFileIds($ids, true);

foreach($shares as $share) {
$circle = $share->getCircle();
foreach ($circle->getInheritedMembers() as $member) {
switch ($member->getUserType()) {
case Member::TYPE_USER:
if ($member->isLocal()) {
if (!in_array($member->getUserId(), $users)) {
$users[] = $member->getUserId();
}
} else {
if (!in_array($member->getUserId(), $remote)) {
$remote[] = $member->getUserid() . '@' . $member->getInstance();
}
}
break;
case Member::TYPE_MAIL:
if (!in_array($member->getUserId(), $mails)) {
$mails[] = $member->getUserId();
}
break;
}
}
}

return [
'users' => $users,
'remote' => $remote,
'email' => $mails
];
}


Expand Down
4 changes: 0 additions & 4 deletions lib/Tools/Db/ExtendedQueryBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -528,10 +528,6 @@ public function exprLimitArray(
string $alias = '',
bool $cs = true
): ICompositeExpression {
if ($this->getType() === DBALQueryBuilder::SELECT) {
$field = (($alias === '') ? $this->getDefaultSelectAlias() : $alias) . '.' . $field;
}

$andX = $this->expr()->andX();
foreach ($values as $value) {
if (is_integer($value)) {
Expand Down

0 comments on commit 37b6279

Please sign in to comment.