Skip to content

Commit

Permalink
Remove extended query parameters from picker URL
Browse files Browse the repository at this point in the history
  • Loading branch information
Ioannis committed Aug 20, 2024
1 parent 3324017 commit e3042f7
Show file tree
Hide file tree
Showing 5 changed files with 60 additions and 6 deletions.
29 changes: 27 additions & 2 deletions app/src/Lib/Traits/IndexQueryTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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')) {
Expand Down
29 changes: 27 additions & 2 deletions app/src/Lib/Traits/QueryModificationTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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.
*
Expand Down Expand Up @@ -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.
*
Expand Down
2 changes: 1 addition & 1 deletion app/src/Lib/Traits/SearchFilterTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -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']);
}
Expand Down
5 changes: 5 additions & 0 deletions app/src/Model/Table/PeopleTable.php
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,11 @@ public function initialize(array $config): void {
]);
$this->setIndexContains(['PrimaryName']);
$this->setViewContains(['PrimaryName']);
$this->setPickerContains([
'EmailAddresses',
'Identifiers',
'PrimaryName',
]);

$this->setAutoViewVars([
'statuses' => [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit e3042f7

Please sign in to comment.