Allow comments from deleted articles to be viewed (#5199) [deploy]

This commit is contained in:
Spencer 2020-01-24 08:06:52 -08:00 committed by Molly Struve
parent a4fe7d78e8
commit 49474d516e
3 changed files with 95 additions and 6 deletions

View file

@ -16,21 +16,23 @@ class CommentsController < ApplicationController
if @podcast
@user = @podcast
(@commentable = @user.podcast_episodes.find_by(slug: params[:slug])) || not_found
@commentable = @user.podcast_episodes.find_by(slug: params[:slug]) if @user.podcast_episodes
else
@user = User.find_by(username: params[:username]) ||
Organization.find_by(slug: params[:username]) ||
not_found
@commentable = @root_comment&.commentable ||
@user.articles.find_by(slug: params[:slug]) ||
not_found
@user.articles.find_by(slug: params[:slug]) || nil
@article = @commentable
not_found unless @commentable.published
not_found if @commentable && !@commentable.published
end
@commentable_type = @commentable.class.name
@commentable_type = @commentable.class.name if @commentable
set_surrogate_key_header "comments-for-#{@commentable.id}-#{@commentable_type}"
set_surrogate_key_header "comments-for-#{@commentable.id}-#{@commentable_type}" if @commentable
render :deleted_commentable_comment unless @commentable
end
# GET /comments/1

View file

@ -0,0 +1,63 @@
<div class="single-comment-header"></div>
<div class="comments-container">
<h3>Comment from a deleted article or podcast</h3>
<div class="single-comment-node root">
<% @user ||= @root_comment.user %>
<% if @root_comment.deleted %>
<div class="inner-comment">
<div class="body">
[deleted]
</div>
</div>
<% else %>
<div class="inner-comment">
<% decorated_comment = @root_comment.decorate %>
<% if decorated_comment.low_quality %>
<div class="low-quality-comment-marker">
<%= image_tag(cl_image_path(asset_path("/assets/sloan.png"),
type: "fetch",
width: 50,
height: 50,
crop: "imagga_scale",
quality: "auto",
flags: "progressive",
fetch_format: "auto",
sign_url: true), class: "sloan", alt: "Sloan, the sloth mascot", loading: "lazy") %>
Comment marked as low quality/non-constructive by the community
<a href="/code-of-conduct">View code of conduct</a>
</div>
<% end %>
<div class="details <%= "low-quality-comment" if decorated_comment.low_quality %>">
<a href="/<%= @user.username %>">
<img class="profile-pic" src="<%= ProfileImage.new(@user).get(50) %>" alt="<%= @user.username %> profile image" />
<span class="comment-username">
<span class="comment-username-inner">
<%= @user.name %>
</span>
</span>
</a>
<% if @user.twitter_username.present? %>
<a href="https://twitter.com/<%= @user.twitter_username %>" rel="noopener noreferrer" target="_blank">
<%= image_tag("twitter-logo.svg", class: "icon-img", alt: "twitter logo") %></a>
<% end %>
<% if @user.github_username.present? %>
<a href="https://github.com/<%= @user.github_username %>" rel="noopener noreferrer" target="_blank">
<%= image_tag("github-logo.svg", class: "icon-img", alt: "github logo") %>
</a>
<% end %>
<%= render "comments/comment_date", decorated_comment: decorated_comment %>
</div>
<div class="body <%= "low-quality-comment" if decorated_comment.low_quality %>">
<%= sanitize @root_comment.processed_html %>
<button class="reaction-button reacted" disabled>
<img class="voted-heart" src="<%= asset_path("emoji/emoji-one-heart.png") %>" alt="Favorite heart button" />
<span class="reactions-count"><%= @root_comment.reactions_count %></span>
</button>
</div>
<div class="actions"></div>
</div>
<% end %>
</div>
</div>

View file

@ -171,6 +171,30 @@ RSpec.describe "Comments", type: :request do
expect { get comment.path }.to raise_error("Not Found")
end
end
context "when the article is deleted" do
before do
comment
article.destroy
get comment.path
end
it "renders deleted article comment view" do
expect(response.body).to include("Comment from a deleted article or podcast")
end
end
context "when the podcast is deleted" do
before do
podcast_comment
podcast_episode.destroy
get podcast_comment.path
end
it "renders deleted article comment view" do
expect(response.body).to include("Comment from a deleted article or podcast")
end
end
end
describe "GET /:username/:slug/comments/:id_code/edit" do