diff --git a/app/controllers/comments_controller.rb b/app/controllers/comments_controller.rb index 545fc383d..ae3d64a0f 100644 --- a/app/controllers/comments_controller.rb +++ b/app/controllers/comments_controller.rb @@ -9,6 +9,8 @@ class CommentsController < ApplicationController # GET /comments # GET /comments.json + # rubocop:disable Metrics/CyclomaticComplexity + # rubocop:disable Metrics/PerceivedComplexity def index skip_authorization @comment = Comment.new @@ -19,8 +21,9 @@ class CommentsController < ApplicationController if @root_comment # 404 for all low-quality for not signed in not_found if @root_comment.score < Comment::LOW_QUALITY_THRESHOLD && !user_signed_in? - # 404 only for < -400 w/o children for signed in - not_found if @root_comment.score < Comment::HIDE_THRESHOLD && !@root_comment.has_children? + set_admin_access + # 404 only for < -400 w/o children for all except admins + not_found if !@is_admin && @root_comment.score < Comment::HIDE_THRESHOLD && !@root_comment.has_children? end if @podcast @@ -37,6 +40,9 @@ class CommentsController < ApplicationController set_surrogate_key_header "comments-for-#{@commentable.id}-#{@commentable_type}" if @commentable end + # rubocop:enable Metrics/CyclomaticComplexity + # rubocop:enable Metrics/PerceivedComplexity + # GET /comments/1 # GET /comments/1.json # GET /comments/1/edit @@ -269,6 +275,15 @@ class CommentsController < ApplicationController private + # for spam content we need to remove cache control headers to access current_user to check admin access + # so that admins could have access to spam articles, profiles and comments (by direct url) + def set_admin_access + return unless user_signed_in? + + unset_cache_control_headers + @is_admin = current_user&.any_admin? + end + def comment_should_be_visible? if @article @article.published? diff --git a/app/helpers/comments_helper.rb b/app/helpers/comments_helper.rb index 6fee321ea..f81b48b7d 100644 --- a/app/helpers/comments_helper.rb +++ b/app/helpers/comments_helper.rb @@ -93,13 +93,18 @@ module CommentsHelper private - def nested_comments(tree:, commentable:, is_view_root: false) + def nested_comments(tree:, commentable:, is_view_root: false, is_admin: false) comments = tree.filter_map do |comment, sub_comments| is_childless = sub_comments.empty? - unless comment.decorate.super_low_quality && is_childless + # hide childless comments with score below hide threshold (but show for admins) + hide = comment.decorate.super_low_quality && is_childless + if is_admin || !hide render("comments/comment", comment: comment, commentable: commentable, is_view_root: is_view_root, is_childless: is_childless, - subtree_html: nested_comments(tree: sub_comments, commentable: commentable)) + is_admin: is_admin, + subtree_html: nested_comments(tree: sub_comments, + commentable: commentable, + is_admin: is_admin)) end end safe_join(comments) diff --git a/app/views/comments/_comment.html.erb b/app/views/comments/_comment.html.erb index 1d4261c35..924ceceb4 100644 --- a/app/views/comments/_comment.html.erb +++ b/app/views/comments/_comment.html.erb @@ -30,6 +30,7 @@ commentable: commentable, is_view_root: is_view_root, is_childless: is_childless, + is_admin: is_admin, subtree_html: subtree_html) %> <% if comment.depth < 3 %> diff --git a/app/views/comments/_comment_proper.html.erb b/app/views/comments/_comment_proper.html.erb index d7e6a544c..c475b5303 100644 --- a/app/views/comments/_comment_proper.html.erb +++ b/app/views/comments/_comment_proper.html.erb @@ -5,7 +5,7 @@
(<%= t("views.comments.quality.superlow") %>)
+ <% end %>