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 <luke-@users.noreply.github.com>
This commit is contained in:
Yuriy Bakhtin 2023-01-11 19:21:43 +04:00 committed by GitHub
parent a37ef7c455
commit 1c9109c817
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 16 additions and 18 deletions

View File

@ -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)

View File

@ -21,3 +21,6 @@ modules:
port: 4444
window_size: maximize
restart: true
capabilities:
chromeOptions:
args: ["--lang=en-US"]

View File

@ -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);
}
/**

View File

@ -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

View File

@ -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