Remove mod-only user revert system (#4178).

The mass undo system from #4178 replaces this system.

Followup to f2dccf8cf.
This commit is contained in:
evazion
2019-09-27 21:48:49 -05:00
parent 3b75dbf64f
commit a39b67b901
9 changed files with 1 additions and 118 deletions

View File

@@ -1,15 +0,0 @@
class UserRevertsController < ApplicationController
before_action :moderator_only
def new
@user = User.find(params[:user_id])
end
def create
user = User.find(params[:user_id])
revert = UserRevert.new(user.id)
revert.process
redirect_to(user_path(user.id))
end
end

View File

@@ -1,32 +0,0 @@
# reverts all changes made by a user
class UserRevert
THRESHOLD = 1_000
class TooManyChangesError < RuntimeError ; end
attr_reader :user_id
def initialize(user_id)
@user_id = user_id
end
def process
validate!
revert_post_changes
end
def validate!
if PostArchive.where(updater_id: user_id).count > THRESHOLD
raise TooManyChangesError.new("This user has too many changes to be reverted")
end
end
def revert_post_changes
PostArchive.where(updater_id: user_id).find_each do |x|
x.undo!
end
end
def self.can_revert?(user)
user.post_update_count <= THRESHOLD
end
end

View File

@@ -101,7 +101,7 @@ class UserPresenter
end
def post_version_count(template)
template.link_to(user.post_update_count, template.post_versions_path(:lr => user.id, :search => {:updater_id => user.id}))
template.link_to(user.post_update_count, template.post_versions_path(:search => {:updater_id => user.id}))
end
def note_version_count(template)

View File

@@ -13,10 +13,6 @@
<%= render "standard_listing" %>
<% end %>
<% if params[:lr] && CurrentUser.is_moderator? %>
<p><%= link_to "Revert this user's changes", new_user_revert_path(:user_id => params[:lr]) %></p>
<% end %>
<%= numbered_paginator(@post_versions) %>
<% end %>
</div>

View File

@@ -78,7 +78,6 @@
<% if Danbooru.config.reportbooru_server %>
<li><%= link_to("Top Searches", searches_explore_posts_path) %></li>
<li><%= link_to("Missed Searches", missed_searches_explore_posts_path) %></li>
<li><%= link_to("Post Changes", reports_post_versions_path) %></li>
<% end %>
</ul>
</section>

View File

@@ -1,15 +0,0 @@
<div id="c-user-reverts">
<div id="a-new">
<h1>Revert Changes</h1>
<p>You are about to revert all changes made by <%= link_to_user @user %>. Continue?</p>
<%= form_tag(user_revert_path) do %>
<%= hidden_field_tag :user_id, params[:user_id] %>
<%= submit_tag "Yes" %>
<% end %>
</div>
</div>
<%= render "users/secondary_links" %>

View File

@@ -94,9 +94,6 @@
<th>Post Changes</th>
<td>
<%= presenter.post_version_count(self) %>
<% if CurrentUser.is_moderator? && UserRevert.can_revert?(user)%>
(<%= link_to "revert all", new_user_revert_path(user_id: user.id) %>)
<% end %>
<% if CurrentUser.id == user.id %>
(<%= link_to "refresh", new_maintenance_user_count_fixes_path %>)
<% end %>

View File

@@ -244,8 +244,6 @@ Rails.application.routes.draw do
resource :related_tag, :only => [:show, :update]
get "reports/uploads" => "reports#uploads"
get "reports/upload_tags" => "reports#upload_tags"
get "reports/post_versions" => "reports#post_versions"
post "reports/post_versions_create" => "reports#post_versions_create"
get "reports/down_voting_post" => "reports#down_voting_post"
post "reports/down_voting_post_create" => "reports#down_voting_post_create"
resource :recommended_posts, only: [:show]
@@ -300,7 +298,6 @@ Rails.application.routes.draw do
end
end
resources :user_name_change_requests, only: [:new, :create, :show, :index]
resource :user_revert, :only => [:new, :create]
resources :wiki_pages do
member do
put :revert

View File

@@ -1,44 +0,0 @@
require 'test_helper'
class UserRevertTest < ActiveSupport::TestCase
context "Reverting a user's changes" do
setup do
@creator = create(:user)
@user = create(:user)
CurrentUser.scoped(@creator) do
@parent = create(:post)
@post = create(:post, :tag_string => "aaa bbb ccc", :rating => "q", :source => "xyz")
end
@post.stubs(:merge_version?).returns(false)
CurrentUser.scoped(@user) do
@post.update(:tag_string => "bbb ccc xxx", :source => "", :rating => "e")
end
end
subject { UserRevert.new(@user.id) }
should "have the correct data" do
assert_equal("bbb ccc xxx", @post.tag_string)
assert_equal("", @post.source)
assert_equal("e", @post.rating)
end
context "when processed" do
setup do
CurrentUser.as(@user) do
subject.process
end
@post.reload
end
should "revert the user's changes" do
assert_equal("aaa bbb ccc", @post.tag_string)
assert_equal("xyz", @post.source)
assert_equal("q", @post.rating)
end
end
end
end