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
......@@ -17,6 +17,7 @@
use Drupal\user\Entity\User;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Drupal\Core\Link;
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
/**
* Returns responses for dblog routes.
......@@ -242,64 +243,71 @@ public function overview() {
* @return array
* If the ID is located in the Database Logging table, a build array in the
* 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) {
$build = [];
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();
$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'],
],
];
$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 (empty($dblog)) {
throw new NotFoundHttpException();
}
$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;
}
......
......@@ -135,6 +135,19 @@ public function testLogEventPage() {
$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.
*
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment