fix: remove products from search if vacationMode (#746)

This commit is contained in:
JacquesDurand 2024-10-02 09:17:04 +02:00 committed by Hugo Nicolas
parent 030eb6c805
commit 11cfd01872
No known key found for this signature in database
GPG key ID: 09CB3D93EB8B0E61
2 changed files with 14 additions and 0 deletions

View file

@ -309,6 +309,9 @@ class Meilisearch
if ($product === null) { if ($product === null) {
return null; return null;
} }
if ($product->getOwner()->isInVacation()) {
return null;
}
// enrich with the distance to the geoPoint if it is available // enrich with the distance to the geoPoint if it is available
if (\array_key_exists('_geoDistance', $hit)) { if (\array_key_exists('_geoDistance', $hit)) {

View file

@ -64,5 +64,16 @@ final class IndexProductsCommandTest extends KernelTestCase
$searchDto->q = 'jumeles'; $searchDto->q = 'jumeles';
$results = $meilisearch->search($searchDto); $results = $meilisearch->search($searchDto);
self::assertSame(1, $results->getHitsCount()); self::assertSame(1, $results->getHitsCount());
// test vacation
$searchDto->user = null;
$searchDto->q = '';
$user16 = $this->getUserRepository()->get(TestReference::USER_16);
$user16->setVacationMode(true);
$this->getUserManager()->save($user16);
$results = $meilisearch->search($searchDto);
// two objects are now hidden
self::assertSame(TestReference::PRODUCTS_VISIBLE_COUNT - 3, $results->getHitsCount());
} }
} }