Skip to content
Snippets Groups Projects
Commit 08582f73 authored by catch's avatar catch
Browse files

Issue #3101108 by Krzysztof Domański, manuel.adan, Hardik_Patel_12, dagmar:...

Issue #3101108 by Krzysztof Domański, manuel.adan, Hardik_Patel_12, dagmar: Dblog event page for non-existing event returns 200, should be 404
parent c674f626
No related branches found
No related tags found
6 merge requests!7452Issue #1797438. HTML5 validation is preventing form submit and not fully...,!1012Issue #3226887: Hreflang on non-canonical content pages,!789Issue #3210310: Adjust Database API to remove deprecated Drupal 9 code in Drupal 10,!596Issue #3046532: deleting an entity reference field, used in a contextual view, makes the whole site unrecoverable,!496Issue #2463967: Use .user.ini file for PHP settings,!144Issue #2666286: Clean up menu_ui to conform to Drupal coding standards
...@@ -17,6 +17,7 @@ ...@@ -17,6 +17,7 @@
use Drupal\user\Entity\User; use Drupal\user\Entity\User;
use Symfony\Component\DependencyInjection\ContainerInterface; use Symfony\Component\DependencyInjection\ContainerInterface;
use Drupal\Core\Link; use Drupal\Core\Link;
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
/** /**
* Returns responses for dblog routes. * Returns responses for dblog routes.
...@@ -242,64 +243,71 @@ public function overview() { ...@@ -242,64 +243,71 @@ public function overview() {
* @return array * @return array
* If the ID is located in the Database Logging table, a build array in the * If the ID is located in the Database Logging table, a build array in the
* format expected by \Drupal\Core\Render\RendererInterface::render(). * format expected by \Drupal\Core\Render\RendererInterface::render().
*
* @throws \Symfony\Component\HttpKernel\Exception\NotFoundHttpException
* If no event found for the given ID.
*/ */
public function eventDetails($event_id) { public function eventDetails($event_id) {
$build = []; $dblog = $this->database->query('SELECT w.*, u.uid FROM {watchdog} w LEFT JOIN {users} u ON u.uid = w.uid WHERE w.wid = :id', [':id' => $event_id])->fetchObject();
if ($dblog = $this->database->query('SELECT w.*, u.uid FROM {watchdog} w LEFT JOIN {users} u ON u.uid = w.uid WHERE w.wid = :id', [':id' => $event_id])->fetchObject()) {
$severity = RfcLogLevel::getLevels(); if (empty($dblog)) {
$message = $this->formatMessage($dblog); throw new NotFoundHttpException();
$username = [
'#theme' => 'username',
'#account' => $dblog->uid ? $this->userStorage->load($dblog->uid) : User::getAnonymousUser(),
];
$rows = [
[
['data' => $this->t('Type'), 'header' => TRUE],
$this->t($dblog->type),
],
[
['data' => $this->t('Date'), 'header' => TRUE],
$this->dateFormatter->format($dblog->timestamp, 'long'),
],
[
['data' => $this->t('User'), 'header' => TRUE],
['data' => $username],
],
[
['data' => $this->t('Location'), 'header' => TRUE],
$this->createLink($dblog->location),
],
[
['data' => $this->t('Referrer'), 'header' => TRUE],
$this->createLink($dblog->referer),
],
[
['data' => $this->t('Message'), 'header' => TRUE],
$message,
],
[
['data' => $this->t('Severity'), 'header' => TRUE],
$severity[$dblog->severity],
],
[
['data' => $this->t('Hostname'), 'header' => TRUE],
$dblog->hostname,
],
[
['data' => $this->t('Operations'), 'header' => TRUE],
['data' => ['#markup' => $dblog->link]],
],
];
$build['dblog_table'] = [
'#type' => 'table',
'#rows' => $rows,
'#attributes' => ['class' => ['dblog-event']],
'#attached' => [
'library' => ['dblog/drupal.dblog'],
],
];
} }
$build = [];
$severity = RfcLogLevel::getLevels();
$message = $this->formatMessage($dblog);
$username = [
'#theme' => 'username',
'#account' => $dblog->uid ? $this->userStorage->load($dblog->uid) : User::getAnonymousUser(),
];
$rows = [
[
['data' => $this->t('Type'), 'header' => TRUE],
$this->t($dblog->type),
],
[
['data' => $this->t('Date'), 'header' => TRUE],
$this->dateFormatter->format($dblog->timestamp, 'long'),
],
[
['data' => $this->t('User'), 'header' => TRUE],
['data' => $username],
],
[
['data' => $this->t('Location'), 'header' => TRUE],
$this->createLink($dblog->location),
],
[
['data' => $this->t('Referrer'), 'header' => TRUE],
$this->createLink($dblog->referer),
],
[
['data' => $this->t('Message'), 'header' => TRUE],
$message,
],
[
['data' => $this->t('Severity'), 'header' => TRUE],
$severity[$dblog->severity],
],
[
['data' => $this->t('Hostname'), 'header' => TRUE],
$dblog->hostname,
],
[
['data' => $this->t('Operations'), 'header' => TRUE],
['data' => ['#markup' => $dblog->link]],
],
];
$build['dblog_table'] = [
'#type' => 'table',
'#rows' => $rows,
'#attributes' => ['class' => ['dblog-event']],
'#attached' => [
'library' => ['dblog/drupal.dblog'],
],
];
return $build; return $build;
} }
......
...@@ -135,6 +135,19 @@ public function testLogEventPage() { ...@@ -135,6 +135,19 @@ public function testLogEventPage() {
$this->assertText('Notice', 'The severity was properly displayed on the detail page.'); $this->assertText('Notice', 'The severity was properly displayed on the detail page.');
} }
/**
* Test not-existing log event page.
*/
public function testLogEventNotFoundPage() {
// Login the admin user.
$this->drupalLogin($this->adminUser);
// Try to read details of not existing event.
$this->drupalGet('admin/reports/dblog/event/999999');
// Verify 404 response.
$this->assertResponse(404);
}
/** /**
* Test individual log event page with missing log attributes. * Test individual log event page with missing log attributes.
* *
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment