Skip to content

Commit

Permalink
fix #3226 【お気に入り】お気に入り一覧に別のユーザーのデータまで表示される (#3228)
Browse files Browse the repository at this point in the history
Co-authored-by: Đỗ Văn Hùng <[email protected]>
  • Loading branch information
HungDV2022 and dovanhung authored Mar 13, 2024
1 parent 5bf7870 commit 112087e
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
6 changes: 4 additions & 2 deletions plugins/bc-favorite/src/Service/FavoritesService.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

namespace BcFavorite\Service;

use BaserCore\Utility\BcUtil;
use Cake\Datasource\EntityInterface;
use Cake\ORM\Exception\PersistenceFailedException;
use Cake\ORM\Query;
Expand Down Expand Up @@ -68,8 +69,9 @@ public function getIndex(array $queryParams): Query
if (!empty($queryParams['num'])) {
$options = ['limit' => $queryParams['num']];
}
$query = $this->Favorites->find('all', ...$options)->orderBy(['sort']);
return $query;
return $this->Favorites->find('all', $options)->where(
['user_id' => BcUtil::loginUser()->id]
)->orderBy(['sort']);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,8 @@ public function testGet(): void
*/
public function testGetIndex(): void
{
$this->loadFixtureScenario(InitAppScenario::class);
$this->loginAdmin($this->getRequest());
$this->loadFixtureScenario(FavoritesScenario::class);
$result = $this->FavoritesService->getIndex(['num' => 2]);
$this->assertEquals(2, $result->all()->count());
Expand Down Expand Up @@ -144,6 +146,8 @@ public function testUpdate(): void
public function testDelete()
{
$this->loadFixtureScenario(FavoritesScenario::class);
$this->loadFixtureScenario(InitAppScenario::class);
$this->loginAdmin($this->getRequest());
$this->FavoritesService->delete(1);
$users = $this->FavoritesService->getIndex([]);
$this->assertEquals(5, $users->all()->count());
Expand Down

0 comments on commit 112087e

Please sign in to comment.