Skip to content

Support viewing comments as guest / prevent exceptions #70

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
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
4 changes: 2 additions & 2 deletions resources/views/comments.blade.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<div class="flex flex-col h-full space-y-4">
@if (auth()->user()->can('create', \Parallax\FilamentComments\Models\FilamentComment::class))
@if (auth()->user()?->can('create', \Parallax\FilamentComments\Models\FilamentComment::class))
<div class="space-y-4">
{{ $this->form }}

Expand Down Expand Up @@ -33,7 +33,7 @@
</div>
</div>

@if (auth()->user()->can('delete', $comment))
@if (auth()->user()?->can('delete', $comment))
<div class="flex-shrink-0">
<x-filament::icon-button
wire:click="delete({{ $comment->id }})"
Expand Down
2 changes: 1 addition & 1 deletion src/Actions/CommentsAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,6 @@ protected function setUp(): void
->modalWidth(MaxWidth::Medium)
->modalSubmitAction(false)
->modalCancelAction(false)
->visible(fn (): bool => auth()->user()->can('viewAny', config('filament-comments.comment_model')));
->visible(fn (): bool => auth()->user()?->can('viewAny', config('filament-comments.comment_model')) ?? false);
}
}
2 changes: 1 addition & 1 deletion src/Infolists/Components/CommentsEntry.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,6 @@ protected function setUp(): void
{
parent::setUp();

$this->visible(fn (): bool => auth()->user()->can('viewAny', config('filament-comments.comment_model')));
$this->visible(fn (): bool => auth()->user()?->can('viewAny', config('filament-comments.comment_model')) ?? false);
}
}
6 changes: 3 additions & 3 deletions src/Livewire/CommentsComponent.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public function mount(): void

public function form(Form $form): Form
{
if (!auth()->user()->can('create', config('filament-comments.comment_model'))) {
if (!auth()->user()?->can('create', config('filament-comments.comment_model'))) {
return $form;
}

Expand Down Expand Up @@ -55,7 +55,7 @@ public function form(Form $form): Form

public function create(): void
{
if (!auth()->user()->can('create', config('filament-comments.comment_model'))) {
if (!auth()->user()?->can('create', config('filament-comments.comment_model'))) {
return;
}

Expand Down Expand Up @@ -85,7 +85,7 @@ public function delete(int $id): void
return;
}

if (!auth()->user()->can('delete', $comment)) {
if (!auth()->user()?->can('delete', $comment)) {
return;
}

Expand Down
2 changes: 1 addition & 1 deletion src/Tables/Actions/CommentsAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,6 @@ protected function setUp(): void
->modalWidth(MaxWidth::Medium)
->modalSubmitAction(false)
->modalCancelAction(false)
->visible(fn (): bool => auth()->user()->can('viewAny', config('filament-comments.comment_model')));
->visible(fn (): bool => auth()->user()?->can('viewAny', config('filament-comments.comment_model')) ?? false);
}
}