From 4cf7895cda4d018e4e2af611054de9f35ae6c348 Mon Sep 17 00:00:00 2001 From: 17sushmita <17sushmita@gmail.com> Date: Wed, 24 Mar 2021 20:05:33 +0530 Subject: [PATCH 1/2] Hide replied comments which are spam or first time comment --- app/views/notes/_comment.html.erb | 15 +++++++++++++-- app/views/notes/_comments.html.erb | 1 + 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/app/views/notes/_comment.html.erb b/app/views/notes/_comment.html.erb index 3e2e35a6ca..702e8fee5c 100644 --- a/app/views/notes/_comment.html.erb +++ b/app/views/notes/_comment.html.erb @@ -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 %> -
Reply to this comment...
<%= comments.size %> <%= translation('notes._comments.comments') %>
<%= javascript_include_tag "editorToolbar" %> <%= javascript_include_tag "comment" %> From 01c9d0f087b2eb442597fc73e070c63a96e22e39 Mon Sep 17 00:00:00 2001 From: 17sushmita <17sushmita@gmail.com> Date: Sat, 27 Mar 2021 22:40:25 +0530 Subject: [PATCH 2/2] Added replied comment moderation tests --- test/fixtures/users.yml | 13 ++++++ test/system/comment_test.rb | 86 +++++++++++++++++++++++++++++++++++++ 2 files changed, 99 insertions(+) diff --git a/test/fixtures/users.yml b/test/fixtures/users.yml index c9c8db0bf7..e2179897e7 100644 --- a/test/fixtures/users.yml +++ b/test/fixtures/users.yml @@ -275,3 +275,16 @@ user_without_tag_subscriptions: bio: '' created_at: <%= Time.now %> updated_at: <%= Time.now %> + +sushmita: + username: sushmita + status: 1 + email: 17sushmita@gmail.com + 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 %> diff --git a/test/system/comment_test.rb b/test/system/comment_test.rb index ce38b88e50..d810f30761 100644 --- a/test/system/comment_test.rb +++ b/test/system/comment_test.rb @@ -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,