Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[stable27] implements getAccessList #1603

Merged
merged 1 commit into from
Jun 13, 2024
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
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
Loading