From 022d9ede7f2281d4cf09176311f5111a5a501041 Mon Sep 17 00:00:00 2001 From: r888888888 Date: Tue, 21 Mar 2017 14:40:06 -0700 Subject: [PATCH] expose bulk revert interface --- app/logical/bulk_revert.rb | 6 ++---- app/views/moderator/bulk_reverts/new.html.erb | 18 ++++++++++-------- app/views/static/site_map.html.erb | 1 + test/unit/bulk_revert_test.rb | 18 ++++++++++++++++++ 4 files changed, 31 insertions(+), 12 deletions(-) create mode 100644 test/unit/bulk_revert_test.rb diff --git a/app/logical/bulk_revert.rb b/app/logical/bulk_revert.rb index b5929ab2c..446231487 100644 --- a/app/logical/bulk_revert.rb +++ b/app/logical/bulk_revert.rb @@ -4,12 +4,10 @@ class BulkRevert class ConstraintTooGeneralError < Exception ; end - def self.process(constraints) - obj = BulkRevert.new(constraints) - + def process ModAction.log("#{CurrentUser.name} processed bulk revert for #{constraints.inspect}") - obj.find_post_versions.order("updated_at, id").each do |version| + find_post_versions.order("updated_at, id").each do |version| version.undo! end end diff --git a/app/views/moderator/bulk_reverts/new.html.erb b/app/views/moderator/bulk_reverts/new.html.erb index a968b6b6c..2d87e13d0 100644 --- a/app/views/moderator/bulk_reverts/new.html.erb +++ b/app/views/moderator/bulk_reverts/new.html.erb @@ -23,11 +23,13 @@
<%= text_field :constraints, :added_tags, :value => @constraints[:added_tags] %> +

You must specify a user to add tags

<%= text_field :constraints, :removed_tags, :value => @constraints[:removed_tags] %> +

You must specify a user to add tags

<%= submit_tag "Test" %> @@ -78,18 +80,18 @@ <% content_for(:html_header) do %> <%= javascript_tag do %> $(function() { - if ($("#constraints_user_name").val().length === 0) { - $("#added-tags-input").hide(); - $("#removed-tags-input").hide(); + if (!$("#constraints_user_name").val().length) { + $("#added-tags-input input").prop("disabled", true); + $("#removed-tags-input input").prop("disabled", true); } $("#constraints_user_name").keyup(function() { - if ($("#constraints_user_name").val().length > 0) { - $("#added-tags-input").show(); - $("#removed-tags-input").show(); + if ($("#constraints_user_name").val().length) { + $("#added-tags-input input").prop("disabled", false); + $("#removed-tags-input input").prop("disabled", false); } else { - $("#added-tags-input").hide(); - $("#removed-tags-input").hide(); + $("#added-tags-input input").prop("disabled", true); + $("#removed-tags-input input").prop("disabled", true); } }); }); diff --git a/app/views/static/site_map.html.erb b/app/views/static/site_map.html.erb index 4bf2dd6e4..0aee3d891 100644 --- a/app/views/static/site_map.html.erb +++ b/app/views/static/site_map.html.erb @@ -120,6 +120,7 @@ <% if CurrentUser.is_moderator? %>
  • <%= link_to("IP Bans", ip_bans_path) %>
  • +
  • <%= link_to("Bulk Revert", new_moderator_bulk_revert_path) %>
  • <% end %> <% if CurrentUser.is_admin? %> diff --git a/test/unit/bulk_revert_test.rb b/test/unit/bulk_revert_test.rb new file mode 100644 index 000000000..a3ab57eb0 --- /dev/null +++ b/test/unit/bulk_revert_test.rb @@ -0,0 +1,18 @@ +require 'test_helper' + +class BulkRevertTest < ActiveSupport::TestCase + context "#find_post_versions" do + subject do + BulkRevert.new(added_tags: "hoge") + end + + setup do + subject.expects(:query_gbq).returns([1,2,3]) + end + + should "revert all changes found in a search" do + q = subject.find_post_versions + assert_match(/post_versions\.id in \(1,2,3\)/, q.to_sql) + end + end +end