From 99fab63f9d07cbd3fa75c6a8d3e7db5a752305d4 Mon Sep 17 00:00:00 2001 From: Ioannis Igoumenos Date: Wed, 13 Mar 2024 18:03:50 +0200 Subject: [PATCH] add filtering with given and family name. Fetch only active users. --- app/src/Lib/Traits/IndexQueryTrait.php | 14 +++++++++++--- .../autocomplete/cm-autocomplete-people.js | 3 ++- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/app/src/Lib/Traits/IndexQueryTrait.php b/app/src/Lib/Traits/IndexQueryTrait.php index eb8ec2f45..9ee9d4655 100644 --- a/app/src/Lib/Traits/IndexQueryTrait.php +++ b/app/src/Lib/Traits/IndexQueryTrait.php @@ -29,6 +29,8 @@ namespace App\Lib\Traits; +use App\Lib\Enum\StatusEnum; +use Cake\Database\Expression\QueryExpression; use Cake\ORM\Query; trait IndexQueryTrait { @@ -98,12 +100,12 @@ public function constructGetIndexContains(Query $query): object { /** * Build the Index Query * - * @params boolean $mode True for OR and False for AND. AND is the default behavior + * @params boolean $picker_mode True for OR and False for AND. AND is the default behavior * * @return object Cake ORM Query object * @since COmanage Registry v5.0.0 */ - public function getIndexQuery(bool $mode = false): object { + public function getIndexQuery(bool $picker_mode = false): object { // $this->name = Models $modelsName = $this->name; // $table = the actual table object @@ -116,7 +118,7 @@ public function getIndexQuery(bool $mode = false): object { $newexp = $query->newExpr(); // The searchable attributes can have an AND or an OR conjunction. The first one is used from the filtering block // while the second one from the picker vue module. - $newexp = $newexp->setConjunction($mode ? 'OR' : 'AND'); + $newexp = $newexp->setConjunction($picker_mode ? 'OR' : 'AND'); if(!empty($link->attr) && !empty($link->value)) { // If a link attribute is defined but no value is provided, then query @@ -155,6 +157,12 @@ public function getIndexQuery(bool $mode = false): object { } } + if($picker_mode) { + // Get only the active People + // XXX Perhaps we need to make this a configuration + $query = $query->where(fn(QueryExpression $exp, Query $query) => $exp->in($table->getAlias().'.status', [StatusEnum::Active, StatusEnum::GracePeriod])); + } + // Append the new conditions $query = $query->where($newexp); } 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 8c0c81f8b..1ae4fd039 100644 --- a/app/webroot/js/comanage/components/autocomplete/cm-autocomplete-people.js +++ b/app/webroot/js/comanage/components/autocomplete/cm-autocomplete-people.js @@ -95,7 +95,8 @@ export default { const queryParams = `identifier=${event.query}` + `&mail=${event.query}` + - `&name=${event.query}` + + `&family=${event.query}` + + `&given=${event.query}` + `&limit=10` // AJAX Request