Browse Source

User can delete issue comments

pull/37/head
Nafies Luthfi 7 years ago
parent
commit
27f77dcb2e
  1. 25
      app/Http/Controllers/Issues/CommentController.php
  2. 8
      resources/views/projects/issues/partials/comment-section.blade.php
  3. 1
      routes/web/projects.php
  4. 22
      tests/Feature/Projects/IssueCommentsTest.php

25
app/Http/Controllers/Issues/CommentController.php

@ -54,4 +54,29 @@ class CommentController extends Controller
return redirect()->route('projects.issues.show', [$issue->project, $issue]);
}
/**
* Remove the specified comment.
*
* @param \App\Entities\Projects\Issue $issue
* @param \\App\Entities\Projects\Comment $comment
* @return \Illuminate\Routing\Redirector
*/
public function destroy(Issue $issue, Comment $comment)
{
$this->authorize('delete', $comment);
request()->validate([
'comment_id' => 'required|exists:comments,id',
]);
if (request('comment_id') == $comment->id && $comment->delete()) {
flash(__('comment.deleted'), 'warning');
return redirect()->route('projects.issues.show', [$issue->project, $issue]);
}
flash(__('comment.undeleted'), 'error');
return back();
}
}

8
resources/views/projects/issues/partials/comment-section.blade.php

@ -8,6 +8,14 @@
@can('update', $comment)
{{ link_to_route('projects.issues.show', __('app.edit'), [$project, $issue, 'action' => 'comment-edit', 'comment_id' => $comment->id], ['id' => 'edit-comment-'.$comment->id, 'class' => 'small', 'title' => __('comment.edit')]) }}
@endcan
@can('delete', $comment)
{!! FormField::delete(
['route' => ['issues.comments.destroy', $issue, $comment], 'class' => ''],
'×',
['class' => 'btn-link', 'id' => 'delete-comment-'.$comment->id],
['comment_id' => $comment->id]
) !!}
@endcan
</div>
{!! nl2br($comment->body) !!}
</div>

1
routes/web/projects.php

@ -111,3 +111,4 @@ Route::patch('issues/{issue}/options', 'Issues\OptionController@update')->name('
*/
Route::post('issues/{issue}/comments', 'Issues\CommentController@store')->name('issues.comments.store');
Route::patch('issues/{issue}/comments/{comment}', 'Issues\CommentController@update')->name('issues.comments.update');
Route::delete('issues/{issue}/comments/{comment}', 'Issues\CommentController@destroy')->name('issues.comments.destroy');

22
tests/Feature/Projects/IssueCommentsTest.php

@ -81,4 +81,26 @@ class IssueCommentsTest extends TestCase
]);
}
/** @test */
public function user_can_delete_an_issue_comment()
{
$this->adminUserSigningIn();
$issue = factory(Issue::class)->create();
$comment = factory(Comment::class)->create([
'commentable_type' => 'issues',
'commentable_id' => $issue->id,
'body' => 'This is issue comment.',
]);
$this->visitRoute('projects.issues.show', [$issue->project, $issue]);
$this->seeElement('button', ['id' => 'delete-comment-'.$comment->id]);
$this->press('delete-comment-'.$comment->id);
$this->seePageIs(route('projects.issues.show', [$issue->project, $issue]));
$this->see(__('comment.deleted'));
$this->dontSeeInDatabase('comments', [
'id' => $comment->id,
]);
}
}
Loading…
Cancel
Save