[Posts]: Hide disabled comments info better (#507)

* [Posts]: Hide disabled comments info better

* use method, remove nullable check, remove from api

* I hate rubocop so much

* missed these two
This commit is contained in:
Donovan Daniels 2023-05-10 11:39:38 -05:00 committed by GitHub
parent 6d6282ab91
commit 6100f8f0d0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 15 additions and 5 deletions

View File

@ -72,7 +72,7 @@ class PostsDecorator < ApplicationDecorator
post_score_icon = "#{"&uarr;" if post.score > 0}#{"&darr;" if post.score < 0}#{"&varr;" if post.score == 0}"
score = t.tag.span("#{post_score_icon}#{post.score}".html_safe, class: "post-score-score " + score_class(post.score))
favs = t.tag.span("&hearts;#{post.fav_count}".html_safe, class: 'post-score-faves')
comments = t.tag.span "C#{post.comment_count}", class: 'post-score-comments'
comments = t.tag.span "C#{post.visible_comment_count(CurrentUser)}", class: 'post-score-comments'
rating = t.tag.span(post.rating.upcase, class: "post-score-rating")
status = t.tag.span(status_flags.join(''), class: 'post-score-extras')
t.tag.div score + favs + comments + rating + status, class: 'post-score', id: "post-score-#{post.id}"

View File

@ -91,7 +91,7 @@ module PostsHelper
post_score_icon = "#{"&uarr;" if post.score > 0}#{"&darr;" if post.score < 0}#{"&varr;" if post.score == 0}"
score = tag.span("#{post_score_icon}#{post.score}".html_safe, class: "post-score-score " + score_class(post.score))
favs = tag.span("&hearts;#{post.fav_count}".html_safe, class: 'post-score-faves')
comments = tag.span "C#{post.comment_count}", class: 'post-score-comments'
comments = tag.span "C#{post.visible_comment_count(CurrentUser)}", class: 'post-score-comments'
rating = tag.span(post.rating.upcase, class: "post-score-rating")
status = tag.span(status_flags.join(''), class: 'post-score-extras')
tag.div score + favs + comments + rating + status, class: 'post-score', id: "post-score-#{post.id}"

View File

@ -1772,6 +1772,10 @@ class Post < ApplicationRecord
def flaggable_for_guidelines?
return true if is_pending?
return true if CurrentUser.is_privileged? && !has_tag?("grandfathered_content") && created_at.after?("2015-01-01")
return false
false
end
def visible_comment_count(user)
user.is_moderator? || !is_comment_disabled ? comment_count : 0
end
end

View File

@ -48,6 +48,9 @@ class PostEvent < ApplicationRecord
def self.search(params)
q = super
unless CurrentUser.is_moderator?
q = q.where.not(action: [actions[:comment_disabled], actions[:comment_enabled]])
end
if params[:post_id].present?
q = q.where("post_id = ?", params[:post_id].to_i)
end

View File

@ -169,7 +169,7 @@ class PostPresenter < Presenter
created_at: post.created_at,
updated_at: post.updated_at,
fav_count: post.fav_count,
comment_count: post.comment_count,
comment_count: post.visible_comment_count(CurrentUser),
change_seq: post.change_seq,
uploader_id: post.uploader_id,
description: post.description,

View File

@ -99,7 +99,6 @@ class PostSerializer < ActiveModel::Serializer
note_locked: nullable_to_truthy(object.is_note_locked),
status_locked: nullable_to_truthy(object.is_status_locked),
rating_locked: nullable_to_truthy(object.is_rating_locked),
comment_disabled: nullable_to_truthy(object.is_comment_disabled),
deleted: object.is_deleted
}
end
@ -137,6 +136,10 @@ class PostSerializer < ActiveModel::Serializer
object.duration ? object.duration.to_f : nil
end
def comment_count
object.visible_comment_count(CurrentUser)
end
attributes :id, :created_at, :updated_at, :file, :preview, :sample, :score, :tags, :locked_tags, :change_seq, :flags,
:rating, :fav_count, :sources, :pools, :relationships, :approver_id, :uploader_id, :description,
:comment_count, :is_favorited, :has_notes, :duration