From 1c9109c817fb7ec16d1ea00ccb154e7023b9bc73 Mon Sep 17 00:00:00 2001 From: Yuriy Bakhtin Date: Wed, 11 Jan 2023 19:21:43 +0400 Subject: [PATCH] Use all searchable profile fields in UserPicker searching (#6040) * Use all searchable profile fields in UserPicker searching * Fix user picker Co-authored-by: Lucas Bartholemy --- CHANGELOG.md | 1 + .../tests/codeception/acceptance.suite.yml | 3 +++ .../humhub/modules/user/models/UserFilter.php | 26 +++++++------------ .../humhub/modules/user/models/UserPicker.php | 2 +- .../modules/user/widgets/UserPicker.php | 2 +- 5 files changed, 16 insertions(+), 18 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index bb32977dfb..1c79649080 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,6 +11,7 @@ HumHub Changelog - Enh #6001: Added new `ContentActiveFixture` and migrated `PostFixture` to it - Fix #6007: Fix number of space members - Fix #6012: View own invisible profile +- Fix #6030: Use all searchable profile fields in UserPicker searching - Fix #6026: Fix visibility members counter for guests 1.13.0 (December 21, 2022) diff --git a/protected/humhub/modules/space/tests/codeception/acceptance.suite.yml b/protected/humhub/modules/space/tests/codeception/acceptance.suite.yml index 3f5c89765b..91d02b85eb 100644 --- a/protected/humhub/modules/space/tests/codeception/acceptance.suite.yml +++ b/protected/humhub/modules/space/tests/codeception/acceptance.suite.yml @@ -21,3 +21,6 @@ modules: port: 4444 window_size: maximize restart: true + capabilities: + chromeOptions: + args: ["--lang=en-US"] diff --git a/protected/humhub/modules/user/models/UserFilter.php b/protected/humhub/modules/user/models/UserFilter.php index fc09697692..3c5dbfc941 100644 --- a/protected/humhub/modules/user/models/UserFilter.php +++ b/protected/humhub/modules/user/models/UserFilter.php @@ -8,8 +8,8 @@ namespace humhub\modules\user\models; +use humhub\modules\user\components\ActiveQueryUser; use Yii; -use \humhub\modules\user\models\UserPicker; /** * Special user model class for the purpose of searching users. @@ -145,23 +145,17 @@ class UserFilter extends User return $query; } - + + /** + * Filter users by keyword + * + * @param ActiveQueryUser $query + * @param string|array $keyword + * @return ActiveQueryUser + */ public static function addKeywordFilter($query, $keyword) { - $query->joinWith('profile'); - $parts = explode(" ", $keyword); - foreach ($parts as $part) { - $query->andFilterWhere( - ['or', - ['like', 'user.email', $part], - ['like', 'user.username', $part], - ['like', 'profile.firstname', $part], - ['like', 'profile.lastname', $part], - ['like', 'profile.title', $part] - ] - ); - } - return $query; + return $query->search($keyword); } /** diff --git a/protected/humhub/modules/user/models/UserPicker.php b/protected/humhub/modules/user/models/UserPicker.php index 529ee3a74c..84e3bbe097 100644 --- a/protected/humhub/modules/user/models/UserPicker.php +++ b/protected/humhub/modules/user/models/UserPicker.php @@ -71,7 +71,7 @@ class UserPicker //Filter out users by means of the fillQuery or default the fillQuery $fillQuery = (isset($cfg['fillQuery'])) ? $cfg['fillQuery'] : UserFilter::find()->active(); UserFilter::addKeywordFilter($fillQuery, $cfg['keyword'], ($cfg['maxResult'] - count($user))); - $fillQuery->andFilterWhere(['not in', 'id', self::getUserIdArray($user)]); + $fillQuery->andFilterWhere(['not in', 'user.id', self::getUserIdArray($user)]); $fillUser = $fillQuery->all(); //Either the additional users are disabled (by default) or we disable them by permission diff --git a/protected/humhub/modules/user/widgets/UserPicker.php b/protected/humhub/modules/user/widgets/UserPicker.php index 28851273cb..3cf3f314b9 100644 --- a/protected/humhub/modules/user/widgets/UserPicker.php +++ b/protected/humhub/modules/user/widgets/UserPicker.php @@ -196,7 +196,7 @@ class UserPicker extends \yii\base\Widget //Filter out users by means of the fillQuery or default the fillQuery $fillQuery = (isset($cfg['fillQuery'])) ? $cfg['fillQuery'] : UserFilter::find(); UserFilter::addKeywordFilter($fillQuery, $cfg['keyword'], ($cfg['maxResult'] - count($user))); - $fillQuery->andFilterWhere(['not in', 'id', self::getUserIdArray($user)]); + $fillQuery->andFilterWhere(['not in', 'user.id', self::getUserIdArray($user)]); $fillUser = $fillQuery->all(); //Either the additional users are disabled (by default) or we disable them by permission