Skip to content

Commit 42650f6

Browse files
authored
Merge pull request #46967 from nextcloud/fix/share-not-found
2 parents e6457aa + db28aa8 commit 42650f6

File tree

5 files changed

+44
-25
lines changed

5 files changed

+44
-25
lines changed

apps/files_sharing/lib/Controller/ShareController.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -294,11 +294,11 @@ public function showShare($path = ''): TemplateResponse {
294294
} catch (ShareNotFound $e) {
295295
// The share does not exists, we do not emit an ShareLinkAccessedEvent
296296
$this->emitAccessShareHook($this->getToken(), 404, 'Share not found');
297-
throw new NotFoundException();
297+
throw new NotFoundException($this->l10n->t('This share does not exist or is no longer available'));
298298
}
299299

300300
if (!$this->validateShare($share)) {
301-
throw new NotFoundException();
301+
throw new NotFoundException($this->l10n->t('This share does not exist or is no longer available'));
302302
}
303303

304304
$shareNode = $share->getNode();
@@ -309,15 +309,15 @@ public function showShare($path = ''): TemplateResponse {
309309
} catch (NotFoundException $e) {
310310
$this->emitAccessShareHook($share, 404, 'Share not found');
311311
$this->emitShareAccessEvent($share, ShareController::SHARE_ACCESS, 404, 'Share not found');
312-
throw new NotFoundException();
312+
throw new NotFoundException($this->l10n->t('This share does not exist or is no longer available'));
313313
}
314314

315315
// We can't get the path of a file share
316316
try {
317317
if ($shareNode instanceof \OCP\Files\File && $path !== '') {
318318
$this->emitAccessShareHook($share, 404, 'Share not found');
319319
$this->emitShareAccessEvent($share, self::SHARE_ACCESS, 404, 'Share not found');
320-
throw new NotFoundException();
320+
throw new NotFoundException($this->l10n->t('This share does not exist or is no longer available'));
321321
}
322322
} catch (\Exception $e) {
323323
$this->emitAccessShareHook($share, 404, 'Share not found');
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<?php
2+
/**
3+
* SPDX-FileCopyrightText: 2024 Nextcloud GmbH and Nextcloud contributors
4+
* SPDX-License-Identifier: AGPL-3.0-only
5+
*/
6+
7+
use OCP\IURLGenerator;
8+
use OCP\Server;
9+
10+
$urlGenerator = Server::get(IURLGenerator::class);
11+
?>
12+
<div class="body-login-container update">
13+
<div>
14+
<svg xmlns="http://www.w3.org/2000/svg" height="70" viewBox="0 -960 960 960" width="70">
15+
<path fill="currentColor" d="m674-456-50-50 69-70-69-69 50-51 70 70 69-70 51 51-70 69 70 70-51 50-69-69-70 69Zm-290-24q-60 0-102-42t-42-102q0-60 42-102t102-42q60 0 102 42t42 102q0 60-42 102t-102 42ZM96-192v-92q0-26 12.5-47.5T143-366q55-32 116-49t125-17q64 0 125 17t116 49q22 13 34.5 34.5T672-284v92H96Z"/>
16+
</svg>
17+
</div>
18+
<h2><?php p($l->t('Share not found')); ?></h2>
19+
<p class="infogroup"><?php p($_['message'] ?: $l->t('This share does not exist or is no longer available')); ?></p>
20+
<p><a class="button primary" href="<?php p($urlGenerator->linkTo('', 'index.php')) ?>">
21+
<?php p($l->t('Back to %s', [$theme->getName()])); ?>
22+
</a></p>
23+
</div>

lib/private/AppFramework/DependencyInjection/DIContainer.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -288,7 +288,7 @@ public function __construct(string $appName, array $urlParams = [], ?ServerConta
288288
new OC\AppFramework\Middleware\PublicShare\PublicShareMiddleware(
289289
$c->get(IRequest::class),
290290
$c->get(ISession::class),
291-
$c->get(\OCP\IConfig::class),
291+
$c->get(IConfig::class),
292292
$c->get(IThrottler::class)
293293
)
294294
);

lib/private/AppFramework/Middleware/PublicShare/PublicShareMiddleware.php

Lines changed: 12 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,10 @@
66
namespace OC\AppFramework\Middleware\PublicShare;
77

88
use OC\AppFramework\Middleware\PublicShare\Exceptions\NeedAuthenticationException;
9+
use OCA\Files_Sharing\AppInfo\Application;
910
use OCP\AppFramework\AuthPublicShareController;
10-
use OCP\AppFramework\Http\NotFoundResponse;
11+
use OCP\AppFramework\Http;
12+
use OCP\AppFramework\Http\TemplateResponse;
1113
use OCP\AppFramework\Middleware;
1214
use OCP\AppFramework\PublicShareController;
1315
use OCP\Files\NotFoundException;
@@ -17,23 +19,13 @@
1719
use OCP\Security\Bruteforce\IThrottler;
1820

1921
class PublicShareMiddleware extends Middleware {
20-
/** @var IRequest */
21-
private $request;
2222

23-
/** @var ISession */
24-
private $session;
25-
26-
/** @var IConfig */
27-
private $config;
28-
29-
/** @var IThrottler */
30-
private $throttler;
31-
32-
public function __construct(IRequest $request, ISession $session, IConfig $config, IThrottler $throttler) {
33-
$this->request = $request;
34-
$this->session = $session;
35-
$this->config = $config;
36-
$this->throttler = $throttler;
23+
public function __construct(
24+
private IRequest $request,
25+
private ISession $session,
26+
private IConfig $config,
27+
private IThrottler $throttler
28+
) {
3729
}
3830

3931
public function beforeController($controller, $methodName) {
@@ -92,7 +84,9 @@ public function afterException($controller, $methodName, \Exception $exception)
9284
}
9385

9486
if ($exception instanceof NotFoundException) {
95-
return new NotFoundResponse();
87+
return new TemplateResponse(Application::APP_ID, 'sharenotfound', [
88+
'message' => $exception->getMessage(),
89+
], 'guest', Http::STATUS_NOT_FOUND);
9690
}
9791

9892
if ($controller instanceof AuthPublicShareController && $exception instanceof NeedAuthenticationException) {

tests/lib/AppFramework/Middleware/PublicShare/PublicShareMiddlewareTest.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,9 @@
1010
use OC\AppFramework\Middleware\PublicShare\PublicShareMiddleware;
1111
use OCP\AppFramework\AuthPublicShareController;
1212
use OCP\AppFramework\Controller;
13-
use OCP\AppFramework\Http\NotFoundResponse;
13+
use OCP\AppFramework\Http;
1414
use OCP\AppFramework\Http\RedirectResponse;
15+
use OCP\AppFramework\Http\TemplateResponse;
1516
use OCP\AppFramework\PublicShareController;
1617
use OCP\Files\NotFoundException;
1718
use OCP\IConfig;
@@ -236,7 +237,8 @@ public function testAfterExceptionPublicShareControllerNotFoundException() {
236237
$exception = new NotFoundException();
237238

238239
$result = $this->middleware->afterException($controller, 'method', $exception);
239-
$this->assertInstanceOf(NotFoundResponse::class, $result);
240+
$this->assertInstanceOf(TemplateResponse::class, $result);
241+
$this->assertEquals($result->getStatus(), Http::STATUS_NOT_FOUND);
240242
}
241243

242244
public function testAfterExceptionPublicShareController() {

0 commit comments

Comments
 (0)