Skip to content

Commit 8daf438

Browse files
committed
[FIX] some shortlinks not working without login
1 parent 8fca8c3 commit 8daf438

File tree

4 files changed

+56
-8
lines changed

4 files changed

+56
-8
lines changed

Modules/File/classes/class.ilFileStaticURLHandler.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ public function handle(Request $request, Context $context, Factory $response_fac
7979
};
8080

8181
if (!$capability->isUnlocked() || $capability->getUri() === null) {
82-
return $response_factory->cannot();
82+
return $response_factory->loginFirst();
8383
}
8484

8585
$uri = $capability->getUri();

src/StaticURL/Handler/HandlerService.php

+15-7
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,13 @@
2020

2121
namespace ILIAS\StaticURL\Handler;
2222

23+
use ILIAS\StaticURL\Request\Request;
2324
use ILIAS\StaticURL\Request\RequestBuilder;
2425
use ILIAS\Data\URI;
2526
use ILIAS\StaticURL\Response\Factory;
2627
use ILIAS\StaticURL\Context;
2728
use ILIAS\StaticURL\Builder\StandardURIBuilder;
29+
use ILIAS\StaticURL\Response\MaybeCanHandlerAfterLogin;
2830

2931
/**
3032
* @author Fabian Schmid <[email protected]>
@@ -48,7 +50,10 @@ public function __construct(
4850
}
4951
}
5052

51-
public function performRedirect(URI $base_uri): never
53+
/**
54+
* @return never
55+
*/
56+
public function performRedirect(URI $base_uri): void
5257
{
5358
$http = $this->context->http();
5459
$ctrl = $this->context->refinery();
@@ -58,12 +63,12 @@ public function performRedirect(URI $base_uri): never
5863
$this->context->refinery(),
5964
$this->handlers
6065
);
61-
if (!$request instanceof \ILIAS\StaticURL\Request\Request) {
66+
if (!$request instanceof Request) {
6267
throw new \RuntimeException('No request could be built');
6368
}
6469

6570
$handler = $this->handlers[$request->getNamespace()] ?? null;
66-
if (!$handler instanceof \ILIAS\StaticURL\Handler\Handler) {
71+
if (!$handler instanceof Handler) {
6772
throw new \InvalidArgumentException('No handler found for namespace ' . $request->getNamespace());
6873
}
6974
$response = $handler->handle($request, $this->context, $this->response_factory);
@@ -74,7 +79,10 @@ public function performRedirect(URI $base_uri): never
7479
}
7580

7681
// Check access to target
77-
if (!$this->context->isUserLoggedIn() && !$this->context->isPublicSectionActive()) {
82+
if (
83+
$response instanceof MaybeCanHandlerAfterLogin
84+
|| (!$this->context->isUserLoggedIn() && !$this->context->isPublicSectionActive())
85+
) {
7886
$uri_builder = new StandardURIBuilder(ILIAS_HTTP_PATH, false);
7987
$target = $uri_builder->buildTarget(
8088
$request->getNamespace(),
@@ -88,7 +96,7 @@ public function performRedirect(URI $base_uri): never
8896
} else {
8997
// Perform Redirect
9098
$uri_path = $response->getURIPath();
91-
$full_uri = $base_uri . '/' . trim($uri_path, '/');
99+
$full_uri = $base_uri . '/' . trim((string) $uri_path, '/');
92100
}
93101

94102
$http->saveResponse(
@@ -105,7 +113,7 @@ public function performRedirect(URI $base_uri): never
105113
private function appendUnknownParameters(Context $context, string $full_uri): string
106114
{
107115
if ($context->http()->wrapper()->query()->has('soap_pw')) {
108-
$full_uri = \ilUtil::appendUrlParameterString(
116+
return \ilUtil::appendUrlParameterString(
109117
$full_uri,
110118
'soap_pw=' . $context->http()->wrapper()->query()->retrieve(
111119
'soap_pw',
@@ -114,7 +122,7 @@ private function appendUnknownParameters(Context $context, string $full_uri): st
114122
);
115123
}
116124
if ($context->http()->wrapper()->query()->has('ext_uid')) {
117-
$full_uri = ilUtil::appendUrlParameterString(
125+
return ilUtil::appendUrlParameterString(
118126
$full_uri,
119127
'ext_uid=' . $context->http()->wrapper()->query()->retrieve(
120128
'ext_uid',

src/StaticURL/Response/Factory.php

+4
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,10 @@ public function cannot(): CannotHandle
2727
{
2828
return new CannotHandle();
2929
}
30+
public function loginFirst(): MaybeCanHandlerAfterLogin
31+
{
32+
return new MaybeCanHandlerAfterLogin();
33+
}
3034

3135
public function can(string $uri_path): CanHandleWithURIPath
3236
{
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
<?php
2+
3+
/**
4+
* This file is part of ILIAS, a powerful learning management system
5+
* published by ILIAS open source e-Learning e.V.
6+
*
7+
* ILIAS is licensed with the GPL-3.0,
8+
* see https://www.gnu.org/licenses/gpl-3.0.en.html
9+
* You should have received a copy of said license along with the
10+
* source code, too.
11+
*
12+
* If this is not the case or you just want to try ILIAS, you'll find
13+
* us at:
14+
* https://www.ilias.de
15+
* https://github.com/ILIAS-eLearning
16+
*
17+
*********************************************************************/
18+
19+
namespace ILIAS\StaticURL\Response;
20+
21+
/**
22+
* @author Fabian Schmid <[email protected]>
23+
*/
24+
class MaybeCanHandlerAfterLogin implements Response
25+
{
26+
public function getURIPath(): ?string
27+
{
28+
return null;
29+
}
30+
31+
public function targetCanBeReached(): bool
32+
{
33+
return true;
34+
}
35+
36+
}

0 commit comments

Comments
 (0)