diff --git a/plugins/bc-favorite/src/Service/FavoritesService.php b/plugins/bc-favorite/src/Service/FavoritesService.php index 385a66875b..6777763e0b 100644 --- a/plugins/bc-favorite/src/Service/FavoritesService.php +++ b/plugins/bc-favorite/src/Service/FavoritesService.php @@ -11,6 +11,7 @@ namespace BcFavorite\Service; +use BaserCore\Utility\BcUtil; use Cake\Datasource\EntityInterface; use Cake\ORM\Exception\PersistenceFailedException; use Cake\ORM\Query; @@ -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']); } /** diff --git a/plugins/bc-favorite/tests/TestCase/Service/FavoritesServiceTest.php b/plugins/bc-favorite/tests/TestCase/Service/FavoritesServiceTest.php index 0ce2e17ac6..782b38f307 100644 --- a/plugins/bc-favorite/tests/TestCase/Service/FavoritesServiceTest.php +++ b/plugins/bc-favorite/tests/TestCase/Service/FavoritesServiceTest.php @@ -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()); @@ -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());