Skip to content

Commit

Permalink
[FIX] some shortlinks not working without login
Browse files Browse the repository at this point in the history
  • Loading branch information
chfsx committed Dec 17, 2024
1 parent d74b544 commit 0105292
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ public function handle(Request $request, Context $context, Factory $response_fac
};

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

$uri = $capability->getUri();
Expand Down
22 changes: 15 additions & 7 deletions components/ILIAS/StaticURL/src/Handler/HandlerService.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,13 @@

namespace ILIAS\StaticURL\Handler;

use ILIAS\StaticURL\Request\Request;
use ILIAS\StaticURL\Request\RequestBuilder;
use ILIAS\Data\URI;
use ILIAS\StaticURL\Response\Factory;
use ILIAS\StaticURL\Context;
use ILIAS\StaticURL\Builder\StandardURIBuilder;
use ILIAS\StaticURL\Response\MaybeCanHandlerAfterLogin;

/**
* @author Fabian Schmid <[email protected]>
Expand All @@ -48,7 +50,10 @@ public function __construct(
}
}

public function performRedirect(URI $base_uri): never
/**
* @return never
*/
public function performRedirect(URI $base_uri): void
{
$http = $this->context->http();
$ctrl = $this->context->refinery();
Expand All @@ -58,12 +63,12 @@ public function performRedirect(URI $base_uri): never
$this->context->refinery(),
$this->handlers
);
if (!$request instanceof \ILIAS\StaticURL\Request\Request) {
if (!$request instanceof Request) {
throw new \RuntimeException('No request could be built');
}

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

// Check access to target
if (!$this->context->isUserLoggedIn() && !$this->context->isPublicSectionActive()) {
if (
$response instanceof MaybeCanHandlerAfterLogin
|| (!$this->context->isUserLoggedIn() && !$this->context->isPublicSectionActive())
) {
$uri_builder = new StandardURIBuilder(ILIAS_HTTP_PATH, false);
$target = $uri_builder->buildTarget(
$request->getNamespace(),
Expand All @@ -88,7 +96,7 @@ public function performRedirect(URI $base_uri): never
} else {
// Perform Redirect
$uri_path = $response->getURIPath();
$full_uri = $base_uri . '/' . trim($uri_path, '/');
$full_uri = $base_uri . '/' . trim((string) $uri_path, '/');
}

$http->saveResponse(
Expand All @@ -105,7 +113,7 @@ public function performRedirect(URI $base_uri): never
private function appendUnknownParameters(Context $context, string $full_uri): string
{
if ($context->http()->wrapper()->query()->has('soap_pw')) {
$full_uri = \ilUtil::appendUrlParameterString(
return \ilUtil::appendUrlParameterString(
$full_uri,
'soap_pw=' . $context->http()->wrapper()->query()->retrieve(
'soap_pw',
Expand All @@ -114,7 +122,7 @@ private function appendUnknownParameters(Context $context, string $full_uri): st
);
}
if ($context->http()->wrapper()->query()->has('ext_uid')) {
$full_uri = ilUtil::appendUrlParameterString(
return ilUtil::appendUrlParameterString(
$full_uri,
'ext_uid=' . $context->http()->wrapper()->query()->retrieve(
'ext_uid',
Expand Down
4 changes: 4 additions & 0 deletions components/ILIAS/StaticURL/src/Response/Factory.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@ public function cannot(): CannotHandle
{
return new CannotHandle();
}
public function loginFirst(): MaybeCanHandlerAfterLogin
{
return new MaybeCanHandlerAfterLogin();
}

public function can(string $uri_path): CanHandleWithURIPath
{
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<?php

/**
* This file is part of ILIAS, a powerful learning management system
* published by ILIAS open source e-Learning e.V.
*
* ILIAS is licensed with the GPL-3.0,
* see https://www.gnu.org/licenses/gpl-3.0.en.html
* You should have received a copy of said license along with the
* source code, too.
*
* If this is not the case or you just want to try ILIAS, you'll find
* us at:
* https://www.ilias.de
* https://github.com/ILIAS-eLearning
*
*********************************************************************/

namespace ILIAS\StaticURL\Response;

/**
* @author Fabian Schmid <[email protected]>
*/
class MaybeCanHandlerAfterLogin implements Response
{
public function getURIPath(): ?string
{
return null;
}

public function targetCanBeReached(): bool
{
return true;
}

}

0 comments on commit 0105292

Please sign in to comment.