Skip to content

Commit

Permalink
Properly trigger 404 if date of unavailable event is requested (#39)
Browse files Browse the repository at this point in the history
  • Loading branch information
DanielSiepmann committed Oct 16, 2023
1 parent 27ee70d commit 82df4de
Show file tree
Hide file tree
Showing 9 changed files with 113 additions and 1 deletion.
22 changes: 22 additions & 0 deletions Classes/Controller/AbstractController.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,13 @@
* 02110-1301, USA.
*/

use TYPO3\CMS\Core\Exception\Page\PageNotFoundException;
use TYPO3\CMS\Core\Http\ImmediateResponseException;
use TYPO3\CMS\Core\Http\PropagateResponseException;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Extbase\Mvc\Controller\ActionController;
use TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer;
use TYPO3\CMS\Frontend\Controller\ErrorController;
use Wrm\Events\Caching\CacheManager;

class AbstractController extends ActionController
Expand Down Expand Up @@ -66,4 +71,21 @@ protected function resolveView()

return $view;
}

protected function trigger404(string $message): void
{
$errorController = GeneralUtility::makeInstance(ErrorController::class);

if (class_exists(ImmediateResponseException::class)) {
throw new ImmediateResponseException(
$errorController->pageNotFoundAction($GLOBALS['TYPO3_REQUEST'], $message),
1695881164
);
}

throw new PropagateResponseException(
$errorController->pageNotFoundAction($this->request, $message),
1695881170
);
}
}
7 changes: 7 additions & 0 deletions Classes/Controller/DateController.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use TYPO3\CMS\Core\EventDispatcher\EventDispatcher;
use TYPO3\CMS\Extbase\Annotation as Extbase;
use TYPO3\CMS\Extbase\Service\ExtensionService;
use Throwable;
use Wrm\Events\Domain\Model\Date;
use Wrm\Events\Domain\Model\Dto\DateDemandFactory;
use Wrm\Events\Domain\Repository\CategoryRepository;
Expand Down Expand Up @@ -155,6 +156,12 @@ public function teaserAction(): void
*/
public function showAction(Date $date): void
{
try {
$date->getEvent();
} catch (Throwable $e) {
$this->trigger404('No event found for requested date.');
}

$this->view->assign('date', $date);
}

Expand Down
31 changes: 31 additions & 0 deletions Documentation/Changelog/3.5.1.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
3.5.1
=====

Breaking
--------

Nothing

Features
--------

Nothing

Fixes
-----

* Properly trigger 404 if a date is requested where event is not available.
This might happen if an event is set to hidden.
The date record is still available and can be requested.
But the event is missing, which in turn should make dates also unavailable.
This situation is now properly handled and will result in a 404.

Tasks
-----

Nothing

Deprecation
-----------

Nothing
6 changes: 6 additions & 0 deletions Documentation/Maintenance/TYPO3/V10.rst
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,9 @@ Remove fetching cached page stage from body from tests

We have different assertions based on TYPO3 version, due to how TYPO3 exposes the info.
We can remove the condition with its content once we drop v10.

Remove condition for page not found handling
--------------------------------------------

The :php:`AbstractController->trigger404()` method has a condition to handle 404 differently for TYPO3 v10.
The condition can be removed.
5 changes: 5 additions & 0 deletions Tests/Functional/AbstractFunctionalTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,11 @@ protected function setUp(): void
]);

ArrayUtility::mergeRecursiveWithOverrule($this->configurationToUseInTestInstance, [
'FE' => [
'cacheHash' => [
'enforceValidation' => false,
],
],
'GFX' => [
'processor_enabled' => true,
'processor_path' => '/usr/bin/',
Expand Down
17 changes: 17 additions & 0 deletions Tests/Functional/Frontend/DatesTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,23 @@ public function returnsDateWithinTimeSpan(): void
self::assertStringContainsString('Event 9', $html);
}

/**
* @test
*/
public function returns404IfEventIsHidden(): void
{
$this->importCSVDataSet(__DIR__ . '/DatesTestFixtures/Returns404IfEventIsHidden.csv');

$request = new InternalRequest();
$request = $request->withPageId(1);
$request = $request->withQueryParameters([
'tx_events_dateshow[date]' => '1',
]);
$response = $this->executeFrontendRequest($request);

self::assertSame(404, $response->getStatusCode());
}

/**
* @test
*/
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
tt_content
,uid,pid,CType,list_type,header
,1,1,list,events_dateshow,Singleview
tx_events_domain_model_event
,uid,pid,title,hidden
,1,2,"Event 1 starts before search, ends before search",1
tx_events_domain_model_date
,uid,pid,event,start,end
,1,2,1,1676419200,1676484000
2 changes: 1 addition & 1 deletion ext_emconf.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
'state' => 'alpha',
'createDirs' => '',
'clearCacheOnLoad' => 0,
'version' => '3.5.0',
'version' => '3.5.1',
'constraints' => [
'depends' => [
'typo3' => '10.4.00-11.5.99',
Expand Down
15 changes: 15 additions & 0 deletions phpstan-baseline.neon
Original file line number Diff line number Diff line change
@@ -1,5 +1,20 @@
parameters:
ignoreErrors:
-
message: "#^Instantiated class TYPO3\\\\CMS\\\\Core\\\\Http\\\\PropagateResponseException not found\\.$#"
count: 1
path: Classes/Controller/AbstractController.php

-
message: "#^Parameter \\#1 \\$request of method TYPO3\\\\CMS\\\\Frontend\\\\Controller\\\\ErrorController\\:\\:pageNotFoundAction\\(\\) expects Psr\\\\Http\\\\Message\\\\ServerRequestInterface, TYPO3\\\\CMS\\\\Extbase\\\\Mvc\\\\Request given\\.$#"
count: 1
path: Classes/Controller/AbstractController.php

-
message: "#^Throwing object of an unknown class TYPO3\\\\CMS\\\\Core\\\\Http\\\\PropagateResponseException\\.$#"
count: 1
path: Classes/Controller/AbstractController.php

-
message: "#^Cannot call method typoLink_URL\\(\\) on TYPO3\\\\CMS\\\\Frontend\\\\ContentObject\\\\ContentObjectRenderer\\|null\\.$#"
count: 1
Expand Down

0 comments on commit 82df4de

Please sign in to comment.