Skip to content

Commit c381c15

Browse files
committed
fix(files_sharing): show proper share not found error message
Signed-off-by: skjnldsv <[email protected]>
1 parent ec66059 commit c381c15

4 files changed

Lines changed: 36 additions & 23 deletions

File tree

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: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
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 class="icon-big icon-share"></div>
14+
<h2><?php p($l->t('Share not found')); ?></h2>
15+
<p class="infogroup"><?php p($_['message'] ?: $l->t('This share does not exist or is no longer available')); ?></p>
16+
<p><a class="button primary" href="<?php p($urlGenerator->linkTo('', 'index.php')) ?>">
17+
<?php p($l->t('Back to %s', [$theme->getName()])); ?>
18+
</a></p>
19+
</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) {

0 commit comments

Comments
 (0)