From 51796dd6afbaaa2248481f11823ccf6592058592 Mon Sep 17 00:00:00 2001 From: Nafies Luthfi Date: Sun, 5 Aug 2018 12:12:44 +0800 Subject: [PATCH] Apply commenting policy to comment actions --- app/Http/Controllers/Projects/CommentsController.php | 8 ++++++-- resources/views/projects/comments.blade.php | 6 ++++++ resources/views/projects/partials/comment-section.blade.php | 6 +++++- resources/views/projects/partials/nav-tabs.blade.php | 2 ++ 4 files changed, 19 insertions(+), 3 deletions(-) diff --git a/app/Http/Controllers/Projects/CommentsController.php b/app/Http/Controllers/Projects/CommentsController.php index 7fac242..dfe8a6c 100644 --- a/app/Http/Controllers/Projects/CommentsController.php +++ b/app/Http/Controllers/Projects/CommentsController.php @@ -17,8 +17,10 @@ class CommentsController extends Controller */ public function index(Project $project) { + $this->authorize('view-comments', $project); + $editableComment = null; - $comments = $project->comments()->latest()->paginate(); + $comments = $project->comments()->with('creator')->latest()->paginate(); if (request('action') == 'comment-edit' && request('comment_id') != null) { $editableComment = Comment::find(request('comment_id')); @@ -36,7 +38,7 @@ class CommentsController extends Controller */ public function store(Request $request, Project $project) { - $this->authorize('view', $project); + $this->authorize('comment-on', $project); $newComment = $request->validate([ 'body' => 'required|string|max:255', @@ -62,6 +64,8 @@ class CommentsController extends Controller */ public function update(Request $request, Project $project, Comment $comment) { + $this->authorize('update', $comment); + $commentData = $request->validate([ 'body' => 'required|string|max:255', ]); diff --git a/resources/views/projects/comments.blade.php b/resources/views/projects/comments.blade.php index d2ebabe..991bead 100755 --- a/resources/views/projects/comments.blade.php +++ b/resources/views/projects/comments.blade.php @@ -36,6 +36,12 @@ @endif @endsection +@section('ext_css') + +@endsection + @section('script')