From 112087e7007241cbfeceae0eecb8aefbef8e560d Mon Sep 17 00:00:00 2001 From: HungDV2022 <110375578+HungDV2022@users.noreply.github.com> Date: Wed, 13 Mar 2024 10:32:11 +0900 Subject: [PATCH] =?UTF-8?q?fix=20#3226=20=E3=80=90=E3=81=8A=E6=B0=97?= =?UTF-8?q?=E3=81=AB=E5=85=A5=E3=82=8A=E3=80=91=E3=81=8A=E6=B0=97=E3=81=AB?= =?UTF-8?q?=E5=85=A5=E3=82=8A=E4=B8=80=E8=A6=A7=E3=81=AB=E5=88=A5=E3=81=AE?= =?UTF-8?q?=E3=83=A6=E3=83=BC=E3=82=B6=E3=83=BC=E3=81=AE=E3=83=87=E3=83=BC?= =?UTF-8?q?=E3=82=BF=E3=81=BE=E3=81=A7=E8=A1=A8=E7=A4=BA=E3=81=95=E3=82=8C?= =?UTF-8?q?=E3=82=8B=20(#3228)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Đỗ Văn Hùng --- plugins/bc-favorite/src/Service/FavoritesService.php | 6 ++++-- .../tests/TestCase/Service/FavoritesServiceTest.php | 4 ++++ 2 files changed, 8 insertions(+), 2 deletions(-) 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());