From 9a4fbe31f8ae4c375ff310a9e83616b376d26eef Mon Sep 17 00:00:00 2001 From: kato Date: Thu, 26 Dec 2024 14:47:32 +0900 Subject: [PATCH] =?UTF-8?q?fix=20#4105=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=E5=95=8F=E9=A1=8C=E3=82=92=E8=A7=A3=E6=B1=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- plugins/bc-favorite/src/Service/FavoritesService.php | 8 +++++++- .../tests/TestCase/Service/FavoritesServiceTest.php | 4 ++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/plugins/bc-favorite/src/Service/FavoritesService.php b/plugins/bc-favorite/src/Service/FavoritesService.php index 0a4047633a..531c94b825 100644 --- a/plugins/bc-favorite/src/Service/FavoritesService.php +++ b/plugins/bc-favorite/src/Service/FavoritesService.php @@ -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; @@ -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; } diff --git a/plugins/bc-favorite/tests/TestCase/Service/FavoritesServiceTest.php b/plugins/bc-favorite/tests/TestCase/Service/FavoritesServiceTest.php index 891199ae43..8b5de8dca0 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());