diff --git a/app/Livewire/Welcome/RecentComments.php b/app/Livewire/Welcome/RecentComments.php index 129c93a3..68877a7f 100644 --- a/app/Livewire/Welcome/RecentComments.php +++ b/app/Livewire/Welcome/RecentComments.php @@ -21,7 +21,12 @@ class RecentComments extends Component implements HasTable, HasForms, HasActions public function table(Table $table): Table { return $table - ->query(Comment::query()->public()->limit(10)) + ->query( + Comment::query() + ->public() + ->whereHas('item', fn ($query) => $query->visibleForCurrentUser()) + ->limit(10) + ) ->columns([ TextColumn::make('content')->label(trans('table.content')), TextColumn::make('item.title')->label(trans('table.item')), diff --git a/tests/Feature/Livewire/Welcome/RecentCommentsTest.php b/tests/Feature/Livewire/Welcome/RecentCommentsTest.php new file mode 100644 index 00000000..31de69d8 --- /dev/null +++ b/tests/Feature/Livewire/Welcome/RecentCommentsTest.php @@ -0,0 +1,26 @@ +private()->create(); + $privateItem = Item::factory()->create(['project_id' => $privateProject->id]); + $publicItem = Item::factory()->create(); + + Comment::factory()->create([ + 'item_id' => $privateItem->id, + 'content' => 'Private project comment', + ]); + Comment::factory()->create([ + 'item_id' => $publicItem->id, + 'content' => 'Public item comment', + ]); + + Livewire::test(RecentComments::class) + ->assertSee('Public item comment') + ->assertDontSee('Private project comment'); +});