Skip to content

Commit

Permalink
long and short access list
Browse files Browse the repository at this point in the history
Signed-off-by: Maxence Lange <maxence@artificial-owl.com>
  • Loading branch information
ArtificialOwl committed Aug 8, 2024
1 parent 2252939 commit 38b60d7
Showing 1 changed file with 77 additions and 2 deletions.
79 changes: 77 additions & 2 deletions lib/ShareByCircleProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -684,8 +684,83 @@ public function getAccessList($nodes, $currentAccess): array {
$ids[] = $node->getId();
}

if (!$currentAccess) {
return $this->getAccessListShort($ids);
}

$shareIds = $knownIds = $users = $remote = $mails = [];
foreach ($this->shareWrapperService->getSharesByFileIds($ids, true, true) as $share) {
$shareIds[] = $share->getId();
$circle = $share->getCircle();
foreach ($circle->getInheritedMembers() as $member) {
if ($share->getParent() > 0 && in_array($member->getSingleId(), $knownIds[$share->getFileSource()] ?? [])) {
continue;
}
$knownIds[$share->getFileSource()][] = $member->getSingleId();

switch ($member->getUserType()) {
case Member::TYPE_USER:
if ($member->isLocal()) {
$users[$member->getUserId()] = [
'node_id' => $share->getFileSource(),
'node_path' => $share->getFileTarget()
];
} else {
// we only store temp value, as token is unknown at this point
$remote[$member->getUserid() . '@' . $member->getInstance()] = [
'node_id' => $share->getFileSource(),
'shareId' => $share->getId(),
'memberId' => $member->getId(),
];
}
break;
case Member::TYPE_MAIL:
// we only store temp value, as token is unknown at this point
$mails[$member->getUserId()] = [
'node_id' => $share->getFileSource(),
'shareId' => $share->getId(),
'memberId' => $member->getId(),
];
break;
}
}
}

// list share tokens in an indexed array and update details for remote/mail entries with the correct token
$shareTokens = [];
foreach ($this->shareTokenService->getTokensFromShares(array_values(array_unique($shareIds))) as $shareToken) {
$shareTokens[$shareToken->getShareId()][$shareToken->getMemberId()] = $shareToken->getToken();
}

foreach ($shares as $share) {
return [
'users' => $users,
'remote' => $this->updateAccessListTokens($remote, $shareTokens),
'email' => $this->updateAccessListTokens($mails, $shareTokens)
];
}

/**
* returns short version of the access list:
* [
* 'users' => ['user1', 'user2', 'user4'],
* 'remote' => bool,
* 'mail' => ['email1@maildomain1', 'email2@maildomain2']
* ]
*
* @param array $ids
*
* @return array
* @throws FederatedItemException
* @throws RemoteInstanceException
* @throws RemoteNotFoundException
* @throws RemoteResourceNotFoundException
* @throws RequestBuilderException
* @throws UnknownRemoteException
*/
private function getAccessListShort(array $ids): array {
$users = $mails = [];
$remote = false;
foreach ($this->shareWrapperService->getSharesByFileIds($ids, true) as $share) {
$circle = $share->getCircle();
foreach ($circle->getInheritedMembers() as $member) {
switch ($member->getUserType()) {
Expand Down Expand Up @@ -722,7 +797,7 @@ public function getAccessList($nodes, $currentAccess): array {
*/
private function updateAccessListTokens(array $list, array $shareTokens): array {
$result = [];
foreach($list as $id => $data) {
foreach ($list as $id => $data) {
$result[$id] = [
'node_id' => $data['node_id'],
'token' => $shareTokens[$data['shareId']][$data['memberId']]
Expand Down

0 comments on commit 38b60d7

Please sign in to comment.