Skip to content

Commit

Permalink
Merge pull request #526 from liviuk2/master
Browse files Browse the repository at this point in the history
UserSearch avoid fields name conflict if joined with other tables
  • Loading branch information
maxxer authored Dec 15, 2023
2 parents 739c0ca + 214eef6 commit cb93930
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 6 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
- Fix: Two Factor Authentication - Filter - Blocks even when two factor authentication is enabled
- Fix: update Dutch (nl) translations (squio)
- Enh: possibility to limit the depth of the recursion when getting user ids from roles (mp1509)
- Fix: UserSearch avoid fields name conflict if joined with other tables (liviuk2)

## 1.6.1 March 4th, 2023

Expand Down
18 changes: 12 additions & 6 deletions src/User/Search/UserSearch.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,18 @@

namespace Da\User\Search;

use Da\User\Model\User;
use Da\User\Query\UserQuery;
use Da\User\Traits\ContainerAwareTrait;
use Yii;
use yii\base\InvalidParamException;
use yii\base\Model;
use yii\data\ActiveDataProvider;

class UserSearch extends Model
{
use ContainerAwareTrait;

/**
* @var string
*/
Expand Down Expand Up @@ -106,21 +110,23 @@ public function search($params)
return $dataProvider;
}

$userClass = $this->getClassMap()->get(User::class);

if ($this->created_at !== null) {
$date = strtotime($this->created_at);
$query->andFilterWhere(['between', 'created_at', $date, $date + 3600 * 24]);
$query->andFilterWhere(['between', $userClass::tableName().'.created_at', $date, $date + 3600 * 24]);
}

if ($this->last_login_at !== null) {
$date = strtotime($this->last_login_at);
$query->andFilterWhere(['between', 'last_login_at', $date, $date + 3600 * 24]);
$query->andFilterWhere(['between', $userClass::tableName().'.last_login_at', $date, $date + 3600 * 24]);
}

$query
->andFilterWhere(['like', 'username', $this->username])
->andFilterWhere(['like', 'email', $this->email])
->andFilterWhere(['registration_ip' => $this->registration_ip])
->andFilterWhere(['last_login_ip' => $this->last_login_ip]);
->andFilterWhere(['like', $userClass::tableName().'.username', $this->username])
->andFilterWhere(['like', $userClass::tableName().'.email', $this->email])
->andFilterWhere([$userClass::tableName().'.registration_ip' => $this->registration_ip])
->andFilterWhere([$userClass::tableName().'.last_login_ip' => $this->last_login_ip]);

return $dataProvider;
}
Expand Down

0 comments on commit cb93930

Please sign in to comment.