expose bulk revert interface

This commit is contained in:
r888888888
2017-03-21 14:40:06 -07:00
parent 91c21b1bac
commit 022d9ede7f
4 changed files with 31 additions and 12 deletions

View File

@@ -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

View File

@@ -23,11 +23,13 @@
<div class="input" id="added-tags-input">
<label>Added Tags</label>
<%= text_field :constraints, :added_tags, :value => @constraints[:added_tags] %>
<p class="hint">You must specify a user to add tags</p>
</div>
<div class="input" id="removed-tags-input">
<label>Removed Tags</label>
<%= text_field :constraints, :removed_tags, :value => @constraints[:removed_tags] %>
<p class="hint">You must specify a user to add tags</p>
</div>
<%= 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);
}
});
});

View File

@@ -120,6 +120,7 @@
<% if CurrentUser.is_moderator? %>
<li><%= link_to("IP Bans", ip_bans_path) %></li>
<li><%= link_to("Bulk Revert", new_moderator_bulk_revert_path) %></li>
<% end %>
<% if CurrentUser.is_admin? %>

View File

@@ -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