Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature zms 3434 print info on ekiosk ticket #727

Merged
merged 3 commits into from
Dec 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions zmsticketprinter/src/Zmsticketprinter/Index.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,14 @@ public function readResponse(
$currentLang = 'de';
}

$translations = [];
$translations = [
'printText' => ''
];
$languages = [];
$defaultLanguage = 'de';

if ($languageConfig) {
$defaultLanguage = $languageConfig['defaultLanguage'];
$defaultLanguage = $languageConfig['defaultLanguage'] ?? '';
foreach ($languageConfig['languages'] as $language) {
$languages[] = $language['language'];

Expand All @@ -62,6 +64,10 @@ public function readResponse(
}
}

if (empty($currentLang) || $currentLang === 'de') {
$translations['printText'] = $languageConfig['defaultPrintText'] ?? '';
}
Comment on lines +67 to +69
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Simplify language condition and validate config structure

The current implementation could be improved in two ways:

  1. The language condition could be simplified
  2. The languageConfig structure should be validated

Consider this approach:

+        if (!isset($languageConfig['defaultPrintText'])) {
+            throw new \InvalidArgumentException('Missing defaultPrintText in language config');
+        }
+
-        if (empty($currentLang) || $currentLang === 'de') {
-            $translations['printText'] = $languageConfig['defaultPrintText'] ?? '';
-        }
+        $translations['printText'] = ($currentLang === 'de' || empty($currentLang))
+            ? $languageConfig['defaultPrintText']
+            : '';
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
if (empty($currentLang) || $currentLang === 'de') {
$translations['printText'] = $languageConfig['defaultPrintText'] ?? '';
}
if (!isset($languageConfig['defaultPrintText'])) {
throw new \InvalidArgumentException('Missing defaultPrintText in language config');
}
$translations['printText'] = ($currentLang === 'de' || empty($currentLang))
? $languageConfig['defaultPrintText']
: '';


$ticketprinterHelper = (new Helper\Ticketprinter($args, $request));
$ticketprinter = $ticketprinterHelper->getEntity();
$ticketprinter->testValid();
Expand Down
2 changes: 2 additions & 0 deletions zmsticketprinter/src/Zmsticketprinter/Process.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ public function readResponse(
$validator = $request->getAttribute('validator');
$scopeId = $validator->getParameter('scopeId')->isNumber()->getValue();
$requestId = $validator->getParameter('requestId')->isNumber()->getValue();
$printText = $validator->getParameter('printText')->isString()->getValue();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Add length validation for printText parameter

While type validation is implemented, there's no maximum length restriction on the printText parameter. This could potentially lead to very large strings being processed and displayed.

Consider adding length validation:

-        $printText = $validator->getParameter('printText')->isString()->getValue();
+        $printText = $validator->getParameter('printText')->isString()->matchLength(1, 255)->getValue();
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
$printText = $validator->getParameter('printText')->isString()->getValue();
$printText = $validator->getParameter('printText')->isString()->matchLength(1, 255)->getValue();

if (null === $scopeId) {
throw new Exception\ScopeNotFound();
}
Expand All @@ -55,6 +56,7 @@ public function readResponse(
'ticketprinter' => $ticketprinterHelper->getEntity(),
'organisation' => $ticketprinterHelper->getOrganisation(),
'process' => $process,
'printText' => $printText,
'waitingTime' => $queueListHelper->getEstimatedWaitingTime(),
'waitingClients' => ($queueListHelper->getClientsBefore()),
'config' => $config,
Expand Down
3 changes: 3 additions & 0 deletions zmsticketprinter/templates/block/content/buttons.twig
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
{{ hiddenfield({ "name": "scopeId", "value": ticketprinter.buttons|first.scope.id }) }}
{{ hiddenfield({ "name": "clusterId", "value": ticketprinter.buttons|first.cluster.id }) }}
{{ hiddenfield({ "name": "requestId", "value": button.requestId }) }}
{{ hiddenfield({ "name": "printText", "value": translations['printText'] }) }}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Add null check and ensure XSS prevention

While adding the printText hidden field aligns with the PR objective, consider these security and robustness improvements:

  1. Add a null check for the translations array
  2. Ensure proper escaping of the translation value
-{{ hiddenfield({ "name": "printText", "value": translations['printText'] }) }}
+{{ hiddenfield({ "name": "printText", "value": translations['printText']|default('')|escape }) }}
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
{{ hiddenfield({ "name": "printText", "value": translations['printText'] }) }}
{{ hiddenfield({ "name": "printText", "value": translations['printText']|default('')|escape }) }}

{% set label = buttonLabelPrefix ~ ticketprinter.buttons|first.name %}
{% if ticketprinter.buttons|first.type == "link" %}
{% set label = "Information" %}
Expand Down Expand Up @@ -43,6 +44,7 @@
{{ hiddenfield({ "name": "scopeId", "value": button.scope.id }) }}
{{ hiddenfield({ "name": "clusterId", "value": button.cluster.id }) }}
{{ hiddenfield({ "name": "requestId", "value": button.requestId }) }}
{{ hiddenfield({ "name": "printText", "value": translations['printText'] }) }}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Maintain consistent implementation with button_single

Apply the same null check and escaping improvements as suggested for the button_single block.

-{{ hiddenfield({ "name": "printText", "value": translations['printText'] }) }}
+{{ hiddenfield({ "name": "printText", "value": translations['printText']|default('')|escape }) }}
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
{{ hiddenfield({ "name": "printText", "value": translations['printText'] }) }}
{{ hiddenfield({ "name": "printText", "value": translations['printText']|default('')|escape }) }}

{% set label = buttonLabelPrefix ~ button.name %}
<div class="variablerwarteschlangebutton" id="variablerwarteschlangebutton">
{{ formbutton({ "type":"submit", "name": "Eintragen", "class": "eintragen" ~ disabled, "label": translations[button.requestId] ?? label|trans, "value": "Wartenummer anfordern", "disabled": disabled }) }}
Expand All @@ -69,6 +71,7 @@
{{ hiddenfield({ "name": "scopeId", "value": button.scope.id }) }}
{{ hiddenfield({ "name": "clusterId", "value": button.cluster.id }) }}
{{ hiddenfield({ "name": "requestId", "value": button.requestId }) }}
{{ hiddenfield({ "name": "printText", "value": translations['printText'] }) }}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Maintain consistent implementation with other blocks

Apply the same null check and escaping improvements as suggested for the other blocks.

-{{ hiddenfield({ "name": "printText", "value": translations['printText'] }) }}
+{{ hiddenfield({ "name": "printText", "value": translations['printText']|default('')|escape }) }}
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
{{ hiddenfield({ "name": "printText", "value": translations['printText'] }) }}
{{ hiddenfield({ "name": "printText", "value": translations['printText']|default('')|escape }) }}

{% set label = buttonLabelPrefix ~ button.name %}

<div class="variablerwarteschlangebutton" id="variablerwarteschlangebutton">
Expand Down
5 changes: 4 additions & 1 deletion zmsticketprinter/templates/block/content/print.twig
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@
<div class="printausgabe msg_ihre_nummernanzeige nummernanzeige">{{ process.queue.number }}</div>
<span class="printausgabe msg_stdname">
<span class="printausgabe msg_ihre_wartenummer">
{{ process.scope.contact.name }}<br>
{{ process.scope.contact.name }}
<br>
{% if printText %}{{ printText }}{% endif %}
<br>
{{ process.queue.arrivalTime|format_date(pattern="EE dd. MMMM Y") }}, {{ process.queue.arrivalTime|format_date(pattern="HH:mm") }} {% trans %}Uhr{% endtrans %}<br>
</span>
</span>
Expand Down
Loading