Skip to content

Commit

Permalink
Error handler minor corrections [SLE-192]
Browse files Browse the repository at this point in the history
  • Loading branch information
samuelgfeller committed Mar 8, 2024
1 parent bbaacb6 commit adda351
Show file tree
Hide file tree
Showing 9 changed files with 30 additions and 15 deletions.
6 changes: 4 additions & 2 deletions config/defaults.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
*
* This file should contain all keys even secret ones to serve as template
*
* This is the first file loaded in settings.php and can as such safely define arrays
* This is the first file loaded in settings.php and can safely define arrays
* without the risk of overwriting something.
* Permitted to do the following: $settings['db'] = ['key' => 'val', 'nextKey' => 'nextVal',];
*/
Expand Down Expand Up @@ -135,7 +135,9 @@
// Table that keeps track of the migrations
'default_migration_table' => 'phinx_migration_log',
'default_environment' => 'local',
'local' => [/* Environment specifics such as db credentials are added in env.phinx.php */],
'local' => [
/* Environment specifics such as db credentials from the secret config are added in env.phinx.php */
],
],
];

Expand Down
4 changes: 2 additions & 2 deletions config/env/env.dev.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@
// Set false to show production error pages
$settings['dev'] = true;

// In case error is not caught by error handler (below)
// For the that the error is not caught by custom error handler (below)
ini_set('display_errors', $settings['dev'] ? '1' : '0');

// Error handler. More controlled than ini
// Display error details in browser and throw ErrorException for notices and warnings
$settings['error']['display_error_details'] = $settings['dev'];

// Database
Expand Down
5 changes: 5 additions & 0 deletions public/assets/client/list/client-list-loading.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ export function fetchAndLoadClients(
card.addEventListener('click', openClientReadPageOnCardClick);
// Middle mouse wheel click
card.addEventListener('auxclick', openClientReadPageOnCardClick);

card.addEventListener('mousedown', disableMouseWheelClickScrolling);
// Enter or space bar key press
card.addEventListener('keypress', triggerClickOnHtmlElementEnterKeypress);
Expand Down Expand Up @@ -160,6 +161,10 @@ function addClientsToDom(clients, allUsers, allStatuses, clientWrapperId = null)
* @param event
*/
function openClientReadPageOnCardClick(event) {
// Don't open client read if not left-click, or middle mouse wheel, or select option click
if ((event.type === 'auxclick' && event.button !== 1) || event.target.tagName === 'OPTION') {
return;
}
// "this" is the card
openLinkOnHtmlElement(event, this, `clients/${this.dataset.clientId}`);
}
Expand Down
2 changes: 1 addition & 1 deletion public/assets/client/list/client-list.css
Original file line number Diff line number Diff line change
Expand Up @@ -85,10 +85,10 @@
background: var(--background-accent-2-color);
border-radius: 99px;
box-shadow: 0 4px 8px 0 rgba(0, 0, 0, 0.1), 0 6px 20px 0 rgba(0, 0, 0, 0.1);
padding: 5px;
}

.profile-card-avatar img {
padding: 5px;
border-radius: 99px;
filter: var(--accent-2-filter);
}
Expand Down
2 changes: 1 addition & 1 deletion public/assets/error/error-details.css
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@
}

#num-th {
font-size: 2em;
font-size: 1.3em;
color: #a46856;
margin-right: 50px;
}
Expand Down
3 changes: 2 additions & 1 deletion src/Application/ErrorHandler/DefaultErrorHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,11 @@
use Psr\Log\LoggerInterface;
use Selective\BasePath\BasePathDetector;
use Slim\Exception\HttpException;
use Slim\Interfaces\ErrorHandlerInterface;
use Slim\Views\PhpRenderer;
use Throwable;

final readonly class DefaultErrorHandler
final readonly class DefaultErrorHandler implements ErrorHandlerInterface
{
private string $fileSystemPath;

Expand Down
2 changes: 1 addition & 1 deletion src/Domain/Security/Service/SecurityLoginChecker.php
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ private function performLoginCheck(array $loginsByIp, array $loginsByEmail, stri
($loginsByIp['failures'] >= $requestLimit && $loginsByIp['failures'] !== 0)
|| ($loginsByEmail['failures'] >= $requestLimit && $loginsByEmail['failures'] !== 0)
// To prevent bots from increasing the total login requests and thus manipulating the global threshold,
// the same limit of failed login attempts per user is used is also enforced for successful logins.
// the same limit is enforced for failed and successful login attempts
|| ($loginsByIp['successes'] >= $requestLimit && $loginsByIp['successes'] !== 0)
|| ($loginsByEmail['successes'] >= $requestLimit && $loginsByEmail['successes'] !== 0)
) {
Expand Down
9 changes: 6 additions & 3 deletions src/Infrastructure/Console/SqlSchemaGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public function __construct(
}

/**
* Generates schema.sql from current database.
* Generates schema.sql with the current database.
* Used by the command line.
*
* @return int
Expand All @@ -36,6 +36,7 @@ public function generateSqlSchema(): int
// Changes the case of the keys in the fetched row to lower case
$row = array_change_key_case($row);
// Execute SQL query to get the 'CREATE TABLE' statement for the current table
// SHOW CREATE TABLE is specific to MySQL
$statement2 = $this->query(sprintf('SHOW CREATE TABLE `%s`;', (string)$row['table_name']));
// Fetch the 'CREATE TABLE' statement and remove the 'AUTO_INCREMENT' part
$createTableSql = $statement2->fetch()['Create Table'];
Expand All @@ -60,16 +61,18 @@ public function generateSqlSchema(): int
*
* @param string $sql The sql
*
* @return PDOStatement The statement
* @throws UnexpectedValueException
*
* @return PDOStatement The statement
*/
private function query(string $sql): PDOStatement
{
$statement = $this->pdo->query($sql);

if (!$statement) {
throw new UnexpectedValueException('Query failed: ' . $sql . ' Error: ' . $this->pdo->errorInfo()[2]);
throw new UnexpectedValueException(
'Query failed: ' . $sql . ' Error: ' . $this->pdo->errorInfo()[2]
);
}

return $statement;
Expand Down
12 changes: 8 additions & 4 deletions templates/dashboard/dashboard.html.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,10 @@
<?php
foreach ($dashboards as $dashboard) {
$checked = in_array($dashboard->panelId, $enabledDashboards, true) ? 'checked' : '';
echo '<label class="checkbox-label dashboard-panel-toggle-btn" data-panel-id="'.html($dashboard->panelId).'">
<input type="checkbox" '.$checked.'><span>'.html($dashboard->title).'</span>
echo '<label class="checkbox-label dashboard-panel-toggle-btn" data-panel-id="' . html($dashboard->panelId) . '">
<input type="checkbox" ' . $checked . '><span>' .
/* The html panel title is hardcoded html from the server and needs to be interpreted */
$dashboard->title . '</span>
</label>';
}
?>
Expand All @@ -43,12 +45,14 @@
foreach ($dashboards as $dashboard) { ?>
<div class="panel-container <?= html($dashboard->panelClass) ?>" id="<?= html($dashboard->panelId) ?>">
<div class="panel-header">
<h2><?= html($dashboard->title) ?></h2>
<h2><?= /* The html panel title is hardcoded html from the server and needs to be interpreted */
$dashboard->title ?></h2>
<img class="toggle-panel-icon" src="assets/general/general-img/action/arrow-icon.svg"
alt="toggle-open-close">
</div>
<div class="panel-content">
<?= html($dashboard->panelHtmlContent) ?>
<?= // The html panel content is hardcoded html from the server and needs to be interpreted
$dashboard->panelHtmlContent ?>
</div>
</div>
<?php
Expand Down

0 comments on commit adda351

Please sign in to comment.