Add comment restore button
This commit is contained in:
@@ -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)) {
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user