Add comment restore button

This commit is contained in:
2026-05-06 21:15:15 +02:00
parent 75f631c3e6
commit 09c08f3fea
3 changed files with 44 additions and 0 deletions

View File

@@ -89,6 +89,25 @@ class Comment extends Component
$this->dispatch('refresh');
}
public function restoreComment()
{
$this->authorize('restore', $this->comment);
$user = Auth::user();
if ($user->hasRole(UserRole::ADMINISTRATOR) || $user->hasRole(UserRole::MODERATOR)) {
// Log to ModLog
ModLog::create([
'moderator' => $user->name,
'data' => "Restored comment {$this->comment->id} written by {$this->comment->user->id} with contents: {$this->comment->body}",
]);
$this->comment->deleted_by_moderator_id = null;
$this->comment->save();
$this->dispatch('refresh');
}
}
public function postReply()
{
if (! ($this->comment->depth() < 2)) {

View File

@@ -25,4 +25,19 @@ class CommentPolicy
return $user->id === $comment->user_id;
}
public function restore(User $user, Comment $comment): bool
{
// Comment not deleted
if ($comment->deleted_by_moderator_id === null) {
return false;
}
if ($user->hasRole(UserRole::ADMINISTRATOR) ||
$user->hasRole(UserRole::MODERATOR)) {
return true;
}
return false;
}
}