Skip to content

Commit

Permalink
fix #4105 【お気に入り】お気に入り一覧に別のユーザーのデータまで表示される問題を解決
Browse files Browse the repository at this point in the history
  • Loading branch information
kato committed Dec 26, 2024
1 parent ad4cadc commit 9a4fbe3
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
8 changes: 7 additions & 1 deletion plugins/bc-favorite/src/Service/FavoritesService.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
namespace BcFavorite\Service;

use BcFavorite\Model\Table\FavoritesTable;
use BaserCore\Utility\BcUtil;
use Cake\Datasource\EntityInterface;
use Cake\ORM\Exception\PersistenceFailedException;
use Cake\ORM\Query;
Expand Down Expand Up @@ -70,7 +71,12 @@ public function getIndex(array $queryParams): Query
if (!empty($queryParams['num'])) {
$options = ['limit' => $queryParams['num']];
}
$query = $this->Favorites->find('all', $options)->order(['sort']);
$query = $this->Favorites->find('all', $options)
->where(
['Favorites.user_id' => BcUtil::loginUser()->id]
)
->order(['sort']);

return $query;
}

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 9a4fbe3

Please sign in to comment.