expose bulk revert interface
This commit is contained in:
@@ -4,12 +4,10 @@ class BulkRevert
|
|||||||
|
|
||||||
class ConstraintTooGeneralError < Exception ; end
|
class ConstraintTooGeneralError < Exception ; end
|
||||||
|
|
||||||
def self.process(constraints)
|
def process
|
||||||
obj = BulkRevert.new(constraints)
|
|
||||||
|
|
||||||
ModAction.log("#{CurrentUser.name} processed bulk revert for #{constraints.inspect}")
|
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!
|
version.undo!
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -23,11 +23,13 @@
|
|||||||
<div class="input" id="added-tags-input">
|
<div class="input" id="added-tags-input">
|
||||||
<label>Added Tags</label>
|
<label>Added Tags</label>
|
||||||
<%= text_field :constraints, :added_tags, :value => @constraints[:added_tags] %>
|
<%= text_field :constraints, :added_tags, :value => @constraints[:added_tags] %>
|
||||||
|
<p class="hint">You must specify a user to add tags</p>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="input" id="removed-tags-input">
|
<div class="input" id="removed-tags-input">
|
||||||
<label>Removed Tags</label>
|
<label>Removed Tags</label>
|
||||||
<%= text_field :constraints, :removed_tags, :value => @constraints[:removed_tags] %>
|
<%= text_field :constraints, :removed_tags, :value => @constraints[:removed_tags] %>
|
||||||
|
<p class="hint">You must specify a user to add tags</p>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<%= submit_tag "Test" %>
|
<%= submit_tag "Test" %>
|
||||||
@@ -78,18 +80,18 @@
|
|||||||
<% content_for(:html_header) do %>
|
<% content_for(:html_header) do %>
|
||||||
<%= javascript_tag do %>
|
<%= javascript_tag do %>
|
||||||
$(function() {
|
$(function() {
|
||||||
if ($("#constraints_user_name").val().length === 0) {
|
if (!$("#constraints_user_name").val().length) {
|
||||||
$("#added-tags-input").hide();
|
$("#added-tags-input input").prop("disabled", true);
|
||||||
$("#removed-tags-input").hide();
|
$("#removed-tags-input input").prop("disabled", true);
|
||||||
}
|
}
|
||||||
|
|
||||||
$("#constraints_user_name").keyup(function() {
|
$("#constraints_user_name").keyup(function() {
|
||||||
if ($("#constraints_user_name").val().length > 0) {
|
if ($("#constraints_user_name").val().length) {
|
||||||
$("#added-tags-input").show();
|
$("#added-tags-input input").prop("disabled", false);
|
||||||
$("#removed-tags-input").show();
|
$("#removed-tags-input input").prop("disabled", false);
|
||||||
} else {
|
} else {
|
||||||
$("#added-tags-input").hide();
|
$("#added-tags-input input").prop("disabled", true);
|
||||||
$("#removed-tags-input").hide();
|
$("#removed-tags-input input").prop("disabled", true);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -120,6 +120,7 @@
|
|||||||
|
|
||||||
<% if CurrentUser.is_moderator? %>
|
<% if CurrentUser.is_moderator? %>
|
||||||
<li><%= link_to("IP Bans", ip_bans_path) %></li>
|
<li><%= link_to("IP Bans", ip_bans_path) %></li>
|
||||||
|
<li><%= link_to("Bulk Revert", new_moderator_bulk_revert_path) %></li>
|
||||||
<% end %>
|
<% end %>
|
||||||
|
|
||||||
<% if CurrentUser.is_admin? %>
|
<% if CurrentUser.is_admin? %>
|
||||||
|
|||||||
18
test/unit/bulk_revert_test.rb
Normal file
18
test/unit/bulk_revert_test.rb
Normal 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
|
||||||
Reference in New Issue
Block a user