Skip to content

Commit

Permalink
FFWEB-3063: Refactor parameter-whitelist
Browse files Browse the repository at this point in the history
Refactor parameter-whitelist
  • Loading branch information
Rayn93 authored May 28, 2024
1 parent 754c26d commit 9fe1252
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 8 deletions.
19 changes: 12 additions & 7 deletions src/Model/Config/Communication/BehaviourConfig.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,23 +23,28 @@ public function __construct(
public function getParameters(): array
{
$parameters = [
'add-params' => $this->getAddParams(), // postStringifier
'parameter-whitelist' => $this->getConfig(self::PATH_PARAMETER_WHITELIST), // allow setUrlParamOptionsListener
'add-params' => $this->getAddParams(),
'parameter-whitelist' => $this->getParameterWhitelist(),
];

return $parameters;
}

private function getConfig(string $path): string
{
return (string) $this->scopeConfig->getValue($path, ScopeInterface::SCOPE_STORES);
}

private function getAddParams(): array
{
$storedValue = $this->scopeConfig->getValue(self::PATH_ADD_PARAMS);
$unserialized = array_values($this->serializer->unserialize($storedValue ?: '[]'));

return array_column($unserialized, 'value', 'name');
}

private function getParameterWhitelist(): string
{
$storedValue = $this->scopeConfig->getValue(self::PATH_PARAMETER_WHITELIST);
$unserialized = array_values($this->serializer->unserialize($storedValue ?: '[]'));
$params = array_column($unserialized, 'name');
array_walk($params, fn(&$param) => $param = "'$param'");

return rtrim(implode(', ', $params));
}
}
7 changes: 6 additions & 1 deletion src/view/frontend/templates/ff/communication.phtml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,12 @@ $searchImmediate = $communicationParameters['search-immediate'] ?? 'false';
}));
<?php endif; ?>

<?php if(!empty($parameters['parameter-whitelist'])) : ?>
factfinder.routing.setUrlParamOptionsListener(() => ({
allow: [<?= /* @noEscape */ $parameters['parameter-whitelist']; ?>],
}));
<?php endif; ?>

factfinder.config.formatting = {
locale: `<?= $escaper->escapeUrl($parameters['currency-country-code'])?>`,
formatOptions: {
Expand All @@ -56,7 +62,6 @@ $searchImmediate = $communicationParameters['search-immediate'] ?? 'false';
window.location.href = `/factfinder/result?query=${searchParams.query}`;
<?php endif; ?>


// Cancel the pipeline to avoid sending a search request to FactFinder before the redirect is complete.
return false;
}
Expand Down

0 comments on commit 9fe1252

Please sign in to comment.