Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion app/Livewire/Welcome/RecentComments.php
Original file line number Diff line number Diff line change
Expand Up @@ -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')),
Expand Down
26 changes: 26 additions & 0 deletions tests/Feature/Livewire/Welcome/RecentCommentsTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?php

use App\Models\Item;
use Livewire\Livewire;
use App\Models\Comment;
use App\Models\Project;
use App\Livewire\Welcome\RecentComments;

test('recent comments exclude comments from private projects', function () {
$privateProject = Project::factory()->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');
});
Loading