Skip to content

Commit d92d3fa

Browse files
authored
Merge pull request #55499 from nextcloud/backport-55151-stable30
2 parents 1728d02 + 39a8ae8 commit d92d3fa

File tree

1 file changed

+25
-55
lines changed

1 file changed

+25
-55
lines changed

apps/files_sharing/lib/Controller/ShareAPIController.php

Lines changed: 25 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -1685,66 +1685,36 @@ private function parseDate(string $expireDate): \DateTime {
16851685
* @throws ShareNotFound
16861686
*/
16871687
private function getShareById(string $id): IShare {
1688-
$share = null;
1689-
1690-
// First check if it is an internal share.
1691-
try {
1692-
$share = $this->shareManager->getShareById('ocinternal:' . $id, $this->currentUser);
1693-
return $share;
1694-
} catch (ShareNotFound $e) {
1695-
// Do nothing, just try the other share type
1696-
}
1697-
1698-
1699-
try {
1700-
if ($this->shareManager->shareProviderExists(IShare::TYPE_CIRCLE)) {
1701-
$share = $this->shareManager->getShareById('ocCircleShare:' . $id, $this->currentUser);
1702-
return $share;
1703-
}
1704-
} catch (ShareNotFound $e) {
1705-
// Do nothing, just try the other share type
1706-
}
1707-
1708-
try {
1709-
if ($this->shareManager->shareProviderExists(IShare::TYPE_EMAIL)) {
1710-
$share = $this->shareManager->getShareById('ocMailShare:' . $id, $this->currentUser);
1711-
return $share;
1712-
}
1713-
} catch (ShareNotFound $e) {
1714-
// Do nothing, just try the other share type
1715-
}
1716-
1717-
try {
1718-
$share = $this->shareManager->getShareById('ocRoomShare:' . $id, $this->currentUser);
1719-
return $share;
1720-
} catch (ShareNotFound $e) {
1721-
// Do nothing, just try the other share type
1722-
}
1688+
$providers = [
1689+
'ocinternal' => null, // No type check needed
1690+
'ocCircleShare' => IShare::TYPE_CIRCLE,
1691+
'ocMailShare' => IShare::TYPE_EMAIL,
1692+
'ocRoomShare' => null,
1693+
'deck' => IShare::TYPE_DECK,
1694+
'sciencemesh' => IShare::TYPE_SCIENCEMESH,
1695+
];
17231696

1724-
try {
1725-
if ($this->shareManager->shareProviderExists(IShare::TYPE_DECK)) {
1726-
$share = $this->shareManager->getShareById('deck:' . $id, $this->currentUser);
1727-
return $share;
1728-
}
1729-
} catch (ShareNotFound $e) {
1730-
// Do nothing, just try the other share type
1697+
// Add federated sharing as a provider only if it's allowed
1698+
if ($this->shareManager->outgoingServer2ServerSharesAllowed()) {
1699+
$providers['ocFederatedSharing'] = null; // No type check needed
17311700
}
17321701

1733-
try {
1734-
if ($this->shareManager->shareProviderExists(IShare::TYPE_SCIENCEMESH)) {
1735-
$share = $this->shareManager->getShareById('sciencemesh:' . $id, $this->currentUser);
1736-
return $share;
1702+
foreach ($providers as $prefix => $type) {
1703+
try {
1704+
if ($type === null || $this->shareManager->shareProviderExists($type)) {
1705+
return $this->shareManager->getShareById($prefix . ':' . $id, $this->currentUser);
1706+
}
1707+
} catch (ShareNotFound $e) {
1708+
// Do nothing, continue to next provider
1709+
} catch (\Exception $e) {
1710+
$this->logger->warning('Unexpected error in share provider', [
1711+
'shareId' => $id,
1712+
'provider' => $prefix,
1713+
'exception' => $e,
1714+
]);
17371715
}
1738-
} catch (ShareNotFound $e) {
1739-
// Do nothing, just try the other share type
17401716
}
1741-
1742-
if (!$this->shareManager->outgoingServer2ServerSharesAllowed()) {
1743-
throw new ShareNotFound();
1744-
}
1745-
$share = $this->shareManager->getShareById('ocFederatedSharing:' . $id, $this->currentUser);
1746-
1747-
return $share;
1717+
throw new ShareNotFound();
17481718
}
17491719

17501720
/**

0 commit comments

Comments
 (0)