From e3042f7709db36567d07d26d9cac4b83e31db0ad Mon Sep 17 00:00:00 2001 From: Ioannis Igoumenos Date: Tue, 20 Aug 2024 20:18:30 +0300 Subject: [PATCH] Remove extended query parameters from picker URL --- app/src/Lib/Traits/IndexQueryTrait.php | 29 +++++++++++++++++-- app/src/Lib/Traits/QueryModificationTrait.php | 29 +++++++++++++++++-- app/src/Lib/Traits/SearchFilterTrait.php | 2 +- app/src/Model/Table/PeopleTable.php | 5 ++++ .../autocomplete/cm-autocomplete-people.js | 1 - 5 files changed, 60 insertions(+), 6 deletions(-) diff --git a/app/src/Lib/Traits/IndexQueryTrait.php b/app/src/Lib/Traits/IndexQueryTrait.php index d5236ffe9..ad784d451 100644 --- a/app/src/Lib/Traits/IndexQueryTrait.php +++ b/app/src/Lib/Traits/IndexQueryTrait.php @@ -57,13 +57,38 @@ public function constructGetIndexContains(Query $query): object { $containClause = $table->getIndexContains(); } - if($this->request->is('restful')|| $this->request->is('ajax')) { + if($this->request->is('restful') || $this->request->is('ajax')) { $containClause = $this->containClauseFromQueryParams(); } return empty($containClause) ? $query : $query->contain($containClause); } + /** + * Construct the Picker Contain array + * + * @param Query $query + * + * @return object Cake ORM Query object + * @since COmanage Registry v5.0.0 + */ + public function constructGetPickerContains(Query $query): object { + // $this->name = Models + $modelsName = $this->name; + // $table = the actual table object + $table = $this->$modelsName; + // Initialize the containClause + $containClause = []; + + // Get whatever the table configuration has + if(method_exists($table, 'getPickerContains') + && $table->getPickerContains()) { + $containClause = $table->getPickerContains(); + } + + return empty($containClause) ? $query : $query->contain($containClause); + } + /** * Construct the Contain Clause from the query parameters of an AJAX or REST call @@ -151,7 +176,7 @@ public function getIndexQuery(bool $pickerMode = false, array $requestParams = [ } // Get Associated Model Data - $query = $this->constructGetIndexContains($query); + $query = $pickerMode ? $this->constructGetPickerContains($query) : $this->constructGetIndexContains($query); // Attributes to search for if(method_exists($table, 'getSearchableAttributes')) { diff --git a/app/src/Lib/Traits/QueryModificationTrait.php b/app/src/Lib/Traits/QueryModificationTrait.php index 1aa061bcd..6670ef894 100644 --- a/app/src/Lib/Traits/QueryModificationTrait.php +++ b/app/src/Lib/Traits/QueryModificationTrait.php @@ -52,6 +52,9 @@ trait QueryModificationTrait { // Array of associated models to pull during a view private $viewContains = false; + // Array of associated models to pull during a pick action + private $pickerContains = false; + /** * Construct the checkValidity for the fields valid_from and valid_through @@ -121,7 +124,18 @@ public function getIndexContains() { public function getPatchAssociated() { return $this->patchAssociated; } - + + /** + * Obtain the set of associated models to pull during a pick. + * + * @since COmanage Registry v5.0.0 + * @return array Array of associated models + */ + + public function getPickerContains() { + return $this->pickerContains; + } + /** * Obtain the set of associated models to pull during a view. * @@ -187,7 +201,18 @@ public function setIndexFilter(array|\Closure $filter) { public function setPatchAssociated(array $a) { $this->patchAssociated = $a; } - + + /** + * Set the associated models to pull during a pick. + * + * @since COmanage Registry v5.0.0 + * @param array $c Array of associated models + */ + + public function setPickerContains(array $c) { + $this->pickerContains = $c; + } + /** * Set the associated models to pull during a view. * diff --git a/app/src/Lib/Traits/SearchFilterTrait.php b/app/src/Lib/Traits/SearchFilterTrait.php index 6b266a0b8..eeaec4665 100644 --- a/app/src/Lib/Traits/SearchFilterTrait.php +++ b/app/src/Lib/Traits/SearchFilterTrait.php @@ -124,7 +124,7 @@ public function addJoins(Query $query, string $attribute, ServerRequest $request return $query->join($joinAssociations); - // XXX We can not use the inenerJoinWith since it applies EagerLoading and includes all the fields which + // XXX We can not use the innerJoinWith since it applies EagerLoading and includes all the fields which // causes problems // return $query->innerJoinWith($this->searchFilters[$attribute]['model']); } diff --git a/app/src/Model/Table/PeopleTable.php b/app/src/Model/Table/PeopleTable.php index a81456961..95a2d4e16 100644 --- a/app/src/Model/Table/PeopleTable.php +++ b/app/src/Model/Table/PeopleTable.php @@ -165,6 +165,11 @@ public function initialize(array $config): void { ]); $this->setIndexContains(['PrimaryName']); $this->setViewContains(['PrimaryName']); + $this->setPickerContains([ + 'EmailAddresses', + 'Identifiers', + 'PrimaryName', + ]); $this->setAutoViewVars([ 'statuses' => [ diff --git a/app/webroot/js/comanage/components/autocomplete/cm-autocomplete-people.js b/app/webroot/js/comanage/components/autocomplete/cm-autocomplete-people.js index dfdfc50ad..7495aa770 100644 --- a/app/webroot/js/comanage/components/autocomplete/cm-autocomplete-people.js +++ b/app/webroot/js/comanage/components/autocomplete/cm-autocomplete-people.js @@ -63,7 +63,6 @@ export default { const url = new URL(urlString); let queryParams = url.searchParams; // Query parameters - queryParams.append('extended', 'PrimaryName,Identifiers,EmailAddresses') queryParams.append('identifier', query) queryParams.append('mail', query) queryParams.append('given', query)