Add comment restore button
This commit is contained in:
@@ -89,6 +89,25 @@ class Comment extends Component
|
|||||||
$this->dispatch('refresh');
|
$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()
|
public function postReply()
|
||||||
{
|
{
|
||||||
if (! ($this->comment->depth() < 2)) {
|
if (! ($this->comment->depth() < 2)) {
|
||||||
|
|||||||
@@ -25,4 +25,19 @@ class CommentPolicy
|
|||||||
|
|
||||||
return $user->id === $comment->user_id;
|
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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -109,6 +109,16 @@
|
|||||||
Delete
|
Delete
|
||||||
</button>
|
</button>
|
||||||
@endcan
|
@endcan
|
||||||
|
|
||||||
|
@can ('restore', $comment)
|
||||||
|
<button
|
||||||
|
wire:click="restoreComment"
|
||||||
|
type="button"
|
||||||
|
class="text-gray-900 dark:text-gray-100 font-medium"
|
||||||
|
>
|
||||||
|
Restore
|
||||||
|
</button>
|
||||||
|
@endcan
|
||||||
@endauth
|
@endauth
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
Reference in New Issue
Block a user