From 6a45db8e1c0b44f12d89d3eff55e21753fac700e Mon Sep 17 00:00:00 2001 From: Yuri Kuznetsov Date: Tue, 15 Mar 2022 14:15:41 +0200 Subject: [PATCH] api getQueryParam return string --- application/Espo/Controllers/Stream.php | 8 +++++++- application/Espo/Core/Api/Request.php | 4 +--- application/Espo/Core/Api/RequestNull.php | 5 +---- application/Espo/Core/Api/RequestWrapper.php | 12 +++--------- application/Espo/Core/Controllers/RecordTree.php | 8 +++++++- .../Espo/Core/Record/SearchParamsFetcher.php | 15 ++++++++++----- .../Espo/Modules/Crm/Controllers/Activities.php | 2 +- .../Espo/Modules/Crm/EntryPoints/CampaignUrl.php | 8 -------- .../Modules/Crm/EntryPoints/SubscribeAgain.php | 4 ---- .../Espo/Modules/Crm/EntryPoints/Unsubscribe.php | 6 +----- 10 files changed, 31 insertions(+), 41 deletions(-) diff --git a/application/Espo/Controllers/Stream.php b/application/Espo/Controllers/Stream.php index ae1644519a..09ec284712 100644 --- a/application/Espo/Controllers/Stream.php +++ b/application/Espo/Controllers/Stream.php @@ -29,6 +29,8 @@ namespace Espo\Controllers; +use Espo\Core\Exceptions\BadRequest; + use Espo\Core\{ Api\Request, Record\SearchParamsFetcher, @@ -97,7 +99,11 @@ class Stream $maxSize = $searchParams->getMaxSize(); $after = $request->getQueryParam('after'); - $where = $request->getQueryParam('where'); + $where = $request->getQueryParams()['where'] ?? null; + + if ($where !== null && !is_array($where)) { + throw new BadRequest(); + } $result = $this->service->find($scope, $id, [ 'offset' => $offset, diff --git a/application/Espo/Core/Api/Request.php b/application/Espo/Core/Api/Request.php index cbb579ca7b..38d53a427f 100644 --- a/application/Espo/Core/Api/Request.php +++ b/application/Espo/Core/Api/Request.php @@ -45,10 +45,8 @@ interface Request /** * Get a query parameter. - * - * @return string|string[]|null */ - public function getQueryParam(string $name); + public function getQueryParam(string $name): ?string; /** * Get all query parameters. diff --git a/application/Espo/Core/Api/RequestNull.php b/application/Espo/Core/Api/RequestNull.php index e424039372..b7ce7c30b7 100644 --- a/application/Espo/Core/Api/RequestNull.php +++ b/application/Espo/Core/Api/RequestNull.php @@ -50,14 +50,11 @@ class RequestNull implements ApiRequest /** * @return null */ - public function getQueryParam(string $name) + public function getQueryParam(string $name): ?string { return null; } - /** - * @return string[] - */ public function getQueryParams(): array { return []; diff --git a/application/Espo/Core/Api/RequestWrapper.php b/application/Espo/Core/Api/RequestWrapper.php index 87d74f9812..a696ac799f 100644 --- a/application/Espo/Core/Api/RequestWrapper.php +++ b/application/Espo/Core/Api/RequestWrapper.php @@ -85,7 +85,7 @@ class RequestWrapper implements ApiRequest return $this->getRouteParam($name); } - return $this->getQueryParam($name); + return $this->request->getQueryParams()[$name] ?? null; } public function hasRouteParam(string $name): bool @@ -111,23 +111,17 @@ class RequestWrapper implements ApiRequest return array_key_exists($name, $this->request->getQueryParams()); } - /** - * @return string|string[]|null - */ - public function getQueryParam(string $name) + public function getQueryParam(string $name): ?string { $value = $this->request->getQueryParams()[$name] ?? null; - if ($value === null) { + if (!is_string($value)) { return null; } return $value; } - /** - * @return array - */ public function getQueryParams(): array { return $this->request->getQueryParams(); diff --git a/application/Espo/Core/Controllers/RecordTree.php b/application/Espo/Core/Controllers/RecordTree.php index e489a92b10..73f34734fe 100644 --- a/application/Espo/Core/Controllers/RecordTree.php +++ b/application/Espo/Core/Controllers/RecordTree.php @@ -30,6 +30,8 @@ namespace Espo\Core\Controllers; use Espo\Core\Exceptions\Forbidden; +use Espo\Core\Exceptions\BadRequest; + use Espo\Services\RecordTree as Service; use Espo\Core\Api\Request; @@ -52,10 +54,14 @@ class RecordTree extends Record return (object) $this->actionListTree($request->getRouteParams(), $request->getParsedBody(), $request); } - $where = $request->getQueryParam('where'); + $where = $request->getQueryParams()['where'] ?? null; $parentId = $request->getQueryParam('parentId'); $maxDepth = $request->getQueryParam('maxDepth'); $onlyNotEmpty = (bool) $request->getQueryParam('onlyNotEmpty'); + + if ($where !== null && !is_array($where)) { + throw new BadRequest(); + } if ($maxDepth !== null) { $maxDepth = (int) $maxDepth; diff --git a/application/Espo/Core/Record/SearchParamsFetcher.php b/application/Espo/Core/Record/SearchParamsFetcher.php index 10fffae3af..9fa523bff6 100644 --- a/application/Espo/Core/Record/SearchParamsFetcher.php +++ b/application/Espo/Core/Record/SearchParamsFetcher.php @@ -92,7 +92,12 @@ class SearchParamsFetcher { $params = []; - $params['where'] = $request->getQueryParam('where'); + $params['where'] = $request->getQueryParams()['where'] ?? null; + + if ($params['where'] !== null && !is_array($params['where'])) { + $params['where'] = null; + } + $params['maxSize'] = $request->getQueryParam('maxSize'); $params['offset'] = $request->getQueryParam('offset'); @@ -141,12 +146,12 @@ class SearchParamsFetcher $params['primaryFilter'] = $request->getQueryParam('primaryFilter'); } - if ($request->getQueryParam('boolFilterList')) { - $params['boolFilterList'] = $request->getQueryParam('boolFilterList'); + if ($request->getQueryParams()['boolFilterList'] ?? null) { + $params['boolFilterList'] = (array) $request->getQueryParams()['boolFilterList']; } - if ($request->getQueryParam('filterList')) { - $params['filterList'] = $request->getQueryParam('filterList'); + if ($request->getQueryParams()['filterList'] ?? null) { + $params['filterList'] = (array) $request->getQueryParams()['filterList']; } if ($request->getQueryParam('select')) { diff --git a/application/Espo/Modules/Crm/Controllers/Activities.php b/application/Espo/Modules/Crm/Controllers/Activities.php index b6dc90e824..81771202be 100644 --- a/application/Espo/Modules/Crm/Controllers/Activities.php +++ b/application/Espo/Modules/Crm/Controllers/Activities.php @@ -172,7 +172,7 @@ class Activities $offset = $searchParams->getOffset(); $maxSize = $searchParams->getMaxSize(); - $entityTypeList = $request->getQueryParam('entityTypeList'); + $entityTypeList = (array) ($request->getQueryParams()['entityTypeList'] ?? null); $futureDays = intval($request->getQueryParam('futureDays')); diff --git a/application/Espo/Modules/Crm/EntryPoints/CampaignUrl.php b/application/Espo/Modules/Crm/EntryPoints/CampaignUrl.php index 37fadd6ca5..c63d39fb80 100644 --- a/application/Espo/Modules/Crm/EntryPoints/CampaignUrl.php +++ b/application/Espo/Modules/Crm/EntryPoints/CampaignUrl.php @@ -120,17 +120,9 @@ class CampaignUrl implements EntryPoint } if ($emailAddress && $hash) { - if (!is_string($emailAddress) || !is_string($hash)) { - throw new BadRequest(); - } - $this->processWithHash($trackingUrl, $emailAddress, $hash); } else if ($uid && $hash) { - if (!is_string($uid) || !is_string($hash)) { - throw new BadRequest(); - } - $this->processWithUniqueId($trackingUrl, $uid, $hash); } else { diff --git a/application/Espo/Modules/Crm/EntryPoints/SubscribeAgain.php b/application/Espo/Modules/Crm/EntryPoints/SubscribeAgain.php index 6f6a04fbe5..585fb77d0f 100644 --- a/application/Espo/Modules/Crm/EntryPoints/SubscribeAgain.php +++ b/application/Espo/Modules/Crm/EntryPoints/SubscribeAgain.php @@ -91,10 +91,6 @@ class SubscribeAgain implements EntryPoint $hash = $request->getQueryParam('hash') ?? null; if ($emailAddress && $hash) { - if (!is_string($emailAddress) || !is_string($hash)) { - throw new BadRequest(); - } - $this->processWithHash($emailAddress, $hash); return; diff --git a/application/Espo/Modules/Crm/EntryPoints/Unsubscribe.php b/application/Espo/Modules/Crm/EntryPoints/Unsubscribe.php index c5b2fc2950..9ab46b769a 100644 --- a/application/Espo/Modules/Crm/EntryPoints/Unsubscribe.php +++ b/application/Espo/Modules/Crm/EntryPoints/Unsubscribe.php @@ -96,16 +96,12 @@ class Unsubscribe implements EntryPoint $hash = $request->getQueryParam('hash') ?? null; if ($emailAddress && $hash) { - if (!is_string($emailAddress) || !is_string($hash)) { - throw new BadRequest(); - } - $this->processWithHash($emailAddress, $hash); return; } - if (!$id || !is_string($id)) { + if (!$id) { throw new BadRequest(); }