Skip to content

Commit

Permalink
Simplify getAllShares function
Browse files Browse the repository at this point in the history
  • Loading branch information
michielbdejong committed Apr 19, 2022
1 parent 0b1e654 commit ffd31df
Showing 1 changed file with 25 additions and 28 deletions.
53 changes: 25 additions & 28 deletions apps/files_sharing/lib/Controller/ShareAPIController.php
Original file line number Diff line number Diff line change
Expand Up @@ -1685,15 +1685,9 @@ private function getDeckShareHelper() {
return $this->serverContainer->get('\OCA\Deck\Sharing\ShareAPIHelper');
}

/**
* @param string $viewer
* @param Node $node
* @param bool $reShares
*
* @return IShare[]
*/
private function getSharesFromNode(string $viewer, $node, bool $reShares): array {
$providers = [
private function getProvidersExceptOutgoing() {
// FIXME: load this list dynamically
return [
IShare::TYPE_USER,
IShare::TYPE_GROUP,
IShare::TYPE_LINK,
Expand All @@ -1703,6 +1697,17 @@ private function getSharesFromNode(string $viewer, $node, bool $reShares): array
IShare::TYPE_DECK,
IShare::TYPE_SCIENCEMESH
];
}

/**
* @param string $viewer
* @param Node $node
* @param bool $reShares
*
* @return IShare[]
*/
private function getSharesFromNode(string $viewer, $node, bool $reShares): array {
$providers = $this->getProviders(false);

// Should we assume that the (currentUser) viewer is the owner of the node !?
$shares = [];
Expand Down Expand Up @@ -1840,24 +1845,16 @@ private function shareProviderResharingRights(string $userId, IShare $share, $no
* @return IShare[]
*/
private function getAllShares(?Node $path = null, bool $reshares = false) {
// Get all shares
$userShares = $this->shareManager->getSharesBy($this->currentUser, IShare::TYPE_USER, $path, $reshares, -1, 0);
$groupShares = $this->shareManager->getSharesBy($this->currentUser, IShare::TYPE_GROUP, $path, $reshares, -1, 0);
$linkShares = $this->shareManager->getSharesBy($this->currentUser, IShare::TYPE_LINK, $path, $reshares, -1, 0);

// EMAIL SHARES
$mailShares = $this->shareManager->getSharesBy($this->currentUser, IShare::TYPE_EMAIL, $path, $reshares, -1, 0);

// CIRCLE SHARES
$circleShares = $this->shareManager->getSharesBy($this->currentUser, IShare::TYPE_CIRCLE, $path, $reshares, -1, 0);

// TALK SHARES
$roomShares = $this->shareManager->getSharesBy($this->currentUser, IShare::TYPE_ROOM, $path, $reshares, -1, 0);

$deckShares = $this->shareManager->getSharesBy($this->currentUser, IShare::TYPE_DECK, $path, $reshares, -1, 0);

// SCIENCEMESH SHARES
$scienceMeshShares = $this->shareManager->getSharesBy($this->currentUser, IShare::TYPE_SCIENCEMESH, $path, $reshares, -1, 0);
$providers = $this->getProvidersExceptOutgoing();
$shares = [];
foreach ($providers as $provider) {
if (!$this->shareManager->shareProviderExists($provider)) {
continue;
}
$providerShares =
$this->shareManager->getSharesBy($this->currentUser, $provider, $path, $reshares, -1, 0);
$shares = array_merge($shares, $providerShares);
}

// FEDERATION
if ($this->shareManager->outgoingServer2ServerSharesAllowed()) {
Expand All @@ -1871,7 +1868,7 @@ private function getAllShares(?Node $path = null, bool $reshares = false) {
$federatedGroupShares = [];
}

return array_merge($userShares, $groupShares, $linkShares, $mailShares, $circleShares, $roomShares, $deckShares, $federatedShares, $federatedGroupShares, $scienceMeshShares);
return array_merge($shares, $federatedShares, $federatedGroupShares);
}


Expand Down

0 comments on commit ffd31df

Please sign in to comment.