diff --git a/app/Http/Controllers/Forum/LogController.php b/app/Http/Controllers/Forum/LogController.php index b4c90280e5..3fadba8913 100644 --- a/app/Http/Controllers/Forum/LogController.php +++ b/app/Http/Controllers/Forum/LogController.php @@ -4,27 +4,57 @@ use Coyote\Post; use Coyote\Services\UrlBuilder; +use Illuminate\Database\Eloquent; use Illuminate\View\View; class LogController extends BaseController { - public function log(Post $post): View + public function log(int $postId): View { - $this->authorize('update', $post->topic->forum); - $this->breadcrumb($post->topic->forum); + $post = $this->postById($postId); + if ($post === null) { + abort(404); + } + $topic = $post->topic; + $forum = $topic->forum; + $this->authorize('update', $forum); + $this->breadcrumb($forum); $this->breadcrumb->push([ - $post->topic->title => UrlBuilder::topic($post->topic), - 'Historia posta' => route('forum.post.log', [$post->id]), + $topic->title => UrlBuilder::topic($topic), + 'Historia posta' => route('forum.post.log', [$post->id]), ]); - $logs = $this->post->history($post->id)->map(function (Post\Log $log): Post\Log { - $log->text = \htmlEntities($log->text); - return $log; - }); return $this->view('forum.log')->with([ - 'logs' => $logs, - 'post' => $post, - 'forum' => $post->topic->forum, - 'topic' => $post->topic, + 'logs' => $this->postLogs($post->id), + 'post' => $post, + 'forum' => $forum, + 'topic' => $topic, + 'topicLink' => route('forum.topic', [$forum->slug, $topic->id, $topic->slug]) . '?p=' . $post->id . '#id' . $post->id, ]); } + + private function postById(int $id): ?Post + { + $post = Post::withTrashed()->find($id); + if ($post === null) { + return null; + } + if ($post->deleted_at === null) { + return $post; + } + if ($this->getGateFactory()->allows('delete', $post->topic->forum)) { + return $post; + } + return null; + } + + public function postLogs(int $postId): Eloquent\Collection + { + return Post\Log::query() + ->select(['post_log.id', 'post_log.*']) + ->where('post_id', $postId) + ->join('posts', 'posts.id', '=', 'post_id') + ->orderBy('post_log.id', 'DESC') + ->with('user') + ->get(); + } } diff --git a/app/Repositories/Contracts/PostRepositoryInterface.php b/app/Repositories/Contracts/PostRepositoryInterface.php index 420ab3934f..523c4ceb58 100644 --- a/app/Repositories/Contracts/PostRepositoryInterface.php +++ b/app/Repositories/Contracts/PostRepositoryInterface.php @@ -45,12 +45,6 @@ public function getFirstUnreadPostId($topicId, $markTime); */ public function merge($userId, $post); - /** - * @param int $postId - * @return mixed - */ - public function history(int $postId); - /** * @param int $userId * @return mixed diff --git a/app/Repositories/Eloquent/PostRepository.php b/app/Repositories/Eloquent/PostRepository.php index 18540a5bc4..9ebcbf0918 100644 --- a/app/Repositories/Eloquent/PostRepository.php +++ b/app/Repositories/Eloquent/PostRepository.php @@ -75,6 +75,7 @@ public function lengthAwarePagination(Topic $topic, int $page = 0, int $perPage */ public function getPage($postId, $topicId, $perPage = 10) { + /** @var int $count */ $count = $this->applyCriteria(function () use ($topicId, $postId) { return $this ->model @@ -147,23 +148,6 @@ public function merge($userId, $post) return $previous; } - /** - * @param int $postId - * @return mixed - */ - public function history(int $postId) - { - return Post\Log::select([ - 'post_log.id', - 'post_log.*' - ]) - ->where('post_id', $postId) - ->join('posts', 'posts.id', '=', 'post_id') - ->orderBy('post_log.id', 'DESC') - ->with('user') - ->get(); - } - /** * @param int $userId * @return mixed diff --git a/resources/js/components/forum/post-log.vue b/resources/js/components/forum/post-log.vue index 1dc3314392..bd5d113872 100644 --- a/resources/js/components/forum/post-log.vue +++ b/resources/js/components/forum/post-log.vue @@ -11,8 +11,9 @@
- - {{ log.title }} + + {{ log.title }} +
@@ -23,14 +24,14 @@