diff --git a/app/Http/Middleware/IsModerator.php b/app/Http/Middleware/IsModerator.php index 8d750c3..d6b96de 100644 --- a/app/Http/Middleware/IsModerator.php +++ b/app/Http/Middleware/IsModerator.php @@ -17,11 +17,13 @@ class IsModerator */ public function handle(Request $request, Closure $next): Response { - if (Auth::check() && Auth::user()->hasRole(UserRole::MODERATOR)) { + if (Auth::check() && ( + Auth::user()->hasRole(UserRole::MODERATOR) || + Auth::user()->hasRole(UserRole::ADMINISTRATOR))) { return $next($request); } - session()->flash('error_msg', 'This resource is restricted to Administrators!'); + session()->flash('error_msg', 'This resource is restricted to Moderators!'); return redirect()->route('home.index'); } diff --git a/app/Livewire/Comment.php b/app/Livewire/Comment.php index 9bb3c91..987ee79 100644 --- a/app/Livewire/Comment.php +++ b/app/Livewire/Comment.php @@ -2,6 +2,7 @@ namespace App\Livewire; +use App\Enums\UserRole; use App\Models\Episode; use App\Models\User; use App\Notifications\CommentNotification; @@ -43,7 +44,7 @@ class Comment extends Component 'replyState.body' => 'reply', ]; - public function updatedIsEditing($isEditing) + public function updatedIsEditing(bool $isEditing) { if (! $isEditing) { return; @@ -67,6 +68,15 @@ class Comment extends Component { $this->authorize('destroy', $this->comment); + $user = Auth::user(); + + if ($user->hasRole(UserRole::ADMINISTRATOR) || $user->hasRole(UserRole::MODERATOR)) { + $this->comment->deleted_by_moderator_id = $user->id; + $this->comment->save(); + $this->dispatch('refresh'); + return; + } + $this->comment->delete(); $this->dispatch('refresh'); diff --git a/app/Models/Comment.php b/app/Models/Comment.php index 2baaa16..9aa611e 100644 --- a/app/Models/Comment.php +++ b/app/Models/Comment.php @@ -72,4 +72,12 @@ class Comment extends Model { return cache()->remember('commentLikes'.$this->id, 300, fn () => $this->likes->count()); } + + /** + * Returns wether or not comment has been removed by moderation + */ + public function isDeletedByModerator(): bool + { + return $this->deleted_by_moderator_id !== null; + } } diff --git a/app/Policies/CommentPolicy.php b/app/Policies/CommentPolicy.php index 09784d2..7a653fc 100644 --- a/app/Policies/CommentPolicy.php +++ b/app/Policies/CommentPolicy.php @@ -2,6 +2,7 @@ namespace App\Policies; +use App\Enums\UserRole; use App\Models\Comment; use App\Models\User; use Illuminate\Auth\Access\HandlesAuthorization; @@ -17,6 +18,11 @@ class CommentPolicy public function destroy(User $user, Comment $comment): bool { + if ($user->hasRole(UserRole::ADMINISTRATOR) || + $user->hasRole(UserRole::MODERATOR)) { + return true; + } + return $user->id === $comment->user_id; } } diff --git a/database/migrations/2026_05_06_144901_add_deleted_by_moderator_to_comments_table.php b/database/migrations/2026_05_06_144901_add_deleted_by_moderator_to_comments_table.php new file mode 100644 index 0000000..1825fda --- /dev/null +++ b/database/migrations/2026_05_06_144901_add_deleted_by_moderator_to_comments_table.php @@ -0,0 +1,30 @@ +bigInteger('deleted_by_moderator_id') + ->nullable() + ->after('parent_id'); + }); + } + + /** + * Reverse the migrations. + */ + public function down(): void + { + Schema::table('comments', function (Blueprint $table) { + $table->dropColumn('deleted_by_moderator_id'); + }); + } +}; diff --git a/resources/views/admin/stream.blade.php b/resources/views/admin/stream.blade.php index 86e9b6c..0781371 100644 --- a/resources/views/admin/stream.blade.php +++ b/resources/views/admin/stream.blade.php @@ -1,15 +1,19 @@ @auth -@if(Auth::user()->hasRole(\App\Enums\UserRole::ADMINISTRATOR)) +@if(Auth::user()->hasRole(\App\Enums\UserRole::ADMINISTRATOR) || Auth::user()->hasRole(\App\Enums\UserRole::MODERATOR))
Deleted ({{ $comment->user->name }})
+ @else +Deleted
+ @endif + @else{{ $comment->user->name }}
+ @endif @if($comment->user->hasRole(\App\Enums\UserRole::ADMINISTRATOR)) @endif + @if($comment->user->hasRole(\App\Enums\UserRole::MODERATOR)) + Moderator + @endif @if($comment->user->hasRole(\App\Enums\UserRole::SUPPORTER)) @endif