Fix #4145: Unable to view deleted comments from post page.

Bug: if all the comments on a post were deleted then the deleted
comments wouldn't be visible to moderators.

This was because we assumed that if `last_commented_at` was nil it meant
that the post had no comments, but this was wrong. `last_commented_at`
only counts undeleted comments. It's reset to nil if all the commnets
have been deleted.
This commit is contained in:
evazion
2019-08-26 13:18:54 -05:00
parent fa37d7c156
commit a3d748e300
3 changed files with 53 additions and 3 deletions

View File

@@ -23,7 +23,7 @@ class PostsController < ApplicationController
def show
@post = Post.find(params[:id])
@comments = @post.last_commented_at.present? ? @post.comments : Comment.none
@comments = @post.comments
@comments = @comments.includes(:creator)
@comments = @comments.includes(:votes) if CurrentUser.is_member?
@comments = @comments.select { |c| c.visible_by?(CurrentUser.user) }