Skip to content

Commit

Permalink
Hide first-time or spam replied-comments (#9381)
Browse files Browse the repository at this point in the history
* Hide replied comments which are spam or first time comment

* Added replied comment moderation tests
  • Loading branch information
17sushmita authored Mar 30, 2021
1 parent cc753d5 commit 9ba8f6d
Show file tree
Hide file tree
Showing 4 changed files with 113 additions and 2 deletions.
15 changes: 13 additions & 2 deletions app/views/notes/_comment.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -160,9 +160,20 @@
<% if comment.reply_to.nil? %>
<% comment.replied_comments.order("timestamp ASC").each do |replied_comment| %>
<%= render :partial => "notes/comment", :locals => {:comment => replied_comment} %>
<% if logged_in_as(['admin','moderator'])%>
<% if replied_comment.status == 4 || replied_comment.status == 1 %>
<%= render :partial => "notes/comment", :locals => {:comment => replied_comment} %>
<% end %>
<% elsif current_user && current_user.id = replied_comment.author.id %>
<% if replied_comment.status == 1 || (replied_comment.status == 4 && replied_comment.uid = current_user.id) %>
<%= render :partial => "notes/comment", :locals => {:comment => replied_comment} %>
<% end %>
<% else %>
<% if replied_comment.status == 1 %>
<%= render :partial => "notes/comment", :locals => {:comment => replied_comment} %>
<% end %>
<% end %>
<% end %>

<p style="color: #006dcc; cursor: pointer; user-select: none;" id="comment-<%= comment.cid %>-reply-toggle">Reply to this comment...</p>
<div id="comment-<%= comment.cid %>-reply" style="margin-top: 30px;display: none;">
<div id="comment-<%= comment.cid %>-reply-section">
Expand Down
1 change: 1 addition & 0 deletions app/views/notes/_comments.html.erb
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<div class="row">
<div id="comments" class="col-lg-10 comments">
<% comments = @node.comments_viewable_by(current_user) %>
<% comments = comments.where('reply_to IS NULL OR reply_to IN (?)', Array.wrap(comments.pluck(:cid)))%>
<h3><span id="comment-count"><%= comments.size %></span> <%= translation('notes._comments.comments') %></h3>
<%= javascript_include_tag "editorToolbar" %>
<%= javascript_include_tag "comment" %>
Expand Down
13 changes: 13 additions & 0 deletions test/fixtures/users.yml
Original file line number Diff line number Diff line change
Expand Up @@ -275,3 +275,16 @@ user_without_tag_subscriptions:
bio: ''
created_at: <%= Time.now %>
updated_at: <%= Time.now %>

sushmita:
username: sushmita
status: 1
email: [email protected]
id: 23
last_request_at: <%= Time.now %>
password_salt: <%= salt = Authlogic::Random.hex_token %>
crypted_password: <%= Authlogic::CryptoProviders::Sha512.encrypt("secretive" + salt) %>
persistence_token: <%= Authlogic::Random.hex_token %>
bio: ''
created_at: <%= Time.now %>
updated_at: <%= Time.now %>
86 changes: 86 additions & 0 deletions test/system/comment_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -491,6 +491,92 @@ def get_path(page_type, path)
assert_selector("#{edit_preview_id} img", count: 1)
end

test "#{page_type_string}: should list first time replied comment to moderator" do
comment = nodes(node_name).add_comment({
uid: 19,
body: "This is a first time reply",
status: 4,
reply_to: 1,
})
visit get_path(page_type, nodes(node_name).path)
page.find("#c#{comment.id}")
assert_equal comment.status, 4
assert_selector("#c#{comment.id} div p", text: "Moderate first-time comment:")
end

test "#{page_type_string}: should not list first time replied comment to non-registered user" do
comment = nodes(node_name).add_comment({
uid: 19,
body: "This is a first time reply",
status: 4,
reply_to: 1,
})
visit '/logout'
visit get_path(page_type, nodes(node_name).path)
assert_selector("#c#{comment.id}", count: 0)
end

test "#{page_type_string}: should not list first time replied comment to other user" do
comment = nodes(node_name).add_comment({
uid: 19,
body: "This is a first time reply",
status: 4,
reply_to: 1,
})
visit '/logout'
visit '/'

find(".nav-link.loginToggle").click()
fill_in("username-login", with: "sushmita")
fill_in("password-signup", with: "secretive")

find(".login-modal-form #login-button").click()
visit get_path(page_type, nodes(node_name).path)
assert_selector("#c#{comment.id}", count: 0)
end

test "#{page_type_string}: should not list spam replied comment to moderator" do
comment = nodes(node_name).add_comment({
uid: 5,
body: "This is a spam reply",
reply_to: 1,
})
visit "/admin/mark_comment_spam/#{comment.id}"
visit get_path(page_type, nodes(node_name).path)
assert_selector("#c#{comment.id}", count: 0)
end

test "#{page_type_string}: should not list spam replied comment to non-registered user" do
comment = nodes(node_name).add_comment({
uid: 5,
body: "This is a spam reply",
reply_to: 1,
})
visit "/admin/mark_comment_spam/#{comment.id}"
visit '/logout'
visit get_path(page_type, nodes(node_name).path)
assert_selector("#c#{comment.id}", count: 0)
end

test "#{page_type_string}: should not list spam replied comment to registered user" do
comment = nodes(node_name).add_comment({
uid: 5,
body: "This is a spam reply",
reply_to: 1,
})
visit "/admin/mark_comment_spam/#{comment.id}"
visit '/logout'
visit '/'

find(".nav-link.loginToggle").click()
fill_in("username-login", with: "sushmita")
fill_in("password-signup", with: "secretive")

find(".login-modal-form #login-button").click()
visit get_path(page_type, nodes(node_name).path)
assert_selector("#c#{comment.id}", count: 0)
end

test "#{page_type_string}: IMMEDIATE image SELECT upload into REPLY comment form" do
nodes(node_name).add_comment({
uid: 5,
Expand Down

0 comments on commit 9ba8f6d

Please sign in to comment.