Fix #3534: Remove Janitor Trials.
This commit is contained in:
@@ -1,50 +0,0 @@
|
||||
class JanitorTrialsController < ApplicationController
|
||||
respond_to :html, :xml, :json
|
||||
before_action :moderator_only, :only => [:create, :promote, :demote]
|
||||
|
||||
def new
|
||||
@janitor_trial = JanitorTrial.new
|
||||
respond_with(@janitor_trial)
|
||||
end
|
||||
|
||||
def edit
|
||||
@janitor_trial = JanitorTrial.find(params[:id])
|
||||
respond_with(@janitor_trial)
|
||||
end
|
||||
|
||||
def index
|
||||
@janitor_trials = JanitorTrial.paginated_search(params)
|
||||
respond_with(@janitor_trials)
|
||||
end
|
||||
|
||||
def create
|
||||
@janitor_trial = JanitorTrial.create(janitor_trial_params)
|
||||
respond_with(@janitor_trial, :location => janitor_trials_path)
|
||||
end
|
||||
|
||||
def promote
|
||||
@janitor_trial = JanitorTrial.find(params[:id])
|
||||
@janitor_trial.promote!
|
||||
respond_with(@janitor_trial) do |format|
|
||||
format.js
|
||||
end
|
||||
end
|
||||
|
||||
def demote
|
||||
@janitor_trial = JanitorTrial.find(params[:id])
|
||||
@janitor_trial.demote!
|
||||
respond_with(@janitor_trial) do |format|
|
||||
format.js
|
||||
end
|
||||
end
|
||||
|
||||
def test
|
||||
@tester = JanitorTrialTester.new(params[:janitor_trial][:user_name])
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def janitor_trial_params
|
||||
params.require(:janitor_trial).permit(%i[user_id user_name])
|
||||
end
|
||||
end
|
||||
@@ -1,29 +0,0 @@
|
||||
let JanitorTrials = {};
|
||||
|
||||
JanitorTrials.initialize_all = function() {
|
||||
if ($("#c-janitor-trials").length) {
|
||||
$("input[value=Test]").on("click.danbooru", function(e) {
|
||||
$.ajax({
|
||||
type: "get",
|
||||
url: "/janitor_trials/test.json",
|
||||
data: {
|
||||
janitor_trial: {
|
||||
user_name: $("#janitor_trial_user_name").val()
|
||||
}
|
||||
},
|
||||
success: function(data) {
|
||||
$("#test-results").html(data);
|
||||
}
|
||||
});
|
||||
|
||||
e.preventDefault();
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
$(document).ready(function() {
|
||||
JanitorTrials.initialize_all();
|
||||
});
|
||||
|
||||
export default JanitorTrials
|
||||
@@ -13,14 +13,8 @@ module ApproverPruner
|
||||
CurrentUser.scoped(User.system, "127.0.0.1") do
|
||||
next if user.is_admin?
|
||||
|
||||
janitor_trial = JanitorTrial.where(user_id: user.id).first
|
||||
|
||||
if janitor_trial && user.can_approve_posts?
|
||||
janitor_trial.demote!
|
||||
else
|
||||
user.can_approve_posts = false
|
||||
user.save
|
||||
end
|
||||
user.update!(can_approve_posts: false)
|
||||
user.feedback.create(category: "neutral", body: "Lost approval privileges")
|
||||
|
||||
Dmail.create_automated(
|
||||
:to_id => user.id,
|
||||
|
||||
@@ -1,21 +0,0 @@
|
||||
class JanitorTrialTester
|
||||
attr_reader :user
|
||||
|
||||
def initialize(user_name)
|
||||
@user = User.find_by_name(user_name)
|
||||
end
|
||||
|
||||
def test
|
||||
if user.nil?
|
||||
"User not found"
|
||||
elsif user.created_at > 1.month.ago
|
||||
"User signed up within the past month"
|
||||
elsif user.favorites.count < 100
|
||||
"User has fewer than 100 favorites"
|
||||
elsif user.feedback.negative.count > 0
|
||||
"User has negative feedback"
|
||||
else
|
||||
"No issues found"
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -1,65 +0,0 @@
|
||||
class JanitorTrial < ApplicationRecord
|
||||
belongs_to :user
|
||||
after_create :send_dmail
|
||||
after_create :promote_user
|
||||
belongs_to_creator
|
||||
validates_inclusion_of :status, :in => %w(active inactive)
|
||||
before_validation :initialize_status
|
||||
validates_uniqueness_of :user_id
|
||||
|
||||
def self.search(params)
|
||||
q = super.where(status: "active")
|
||||
q = q.search_attributes(params, :user, :creator, :original_level)
|
||||
q.apply_default_order(params)
|
||||
end
|
||||
|
||||
def initialize_status
|
||||
self.status = "active"
|
||||
end
|
||||
|
||||
def user_name
|
||||
user.try(:name)
|
||||
end
|
||||
|
||||
def user_name=(name)
|
||||
self.user = User.find_by_name(name)
|
||||
end
|
||||
|
||||
def send_dmail
|
||||
body = "You have been selected as a test janitor. You can now approve pending posts and have access to the moderation interface. You should reacquaint yourself with the [[howto:upload]] guide to make sure you understand the site rules.\n\nOver the next several weeks your approvals will be monitored. If the majority of them are not quality uploads you will fail the trial period and lose your approval privileges. You will also receive a negative user record indicating you previously attempted and failed a test janitor trial.\n\nThere is a minimum quota of 1 approval a month to indicate that you are being active. Remember, the goal isn't to approve as much as possible. It's to filter out borderline-quality art."
|
||||
|
||||
Dmail.create_automated(:title => "Test Janitor Trial Period", :body => body, :to_id => user_id)
|
||||
end
|
||||
|
||||
def promote_user
|
||||
user.feedback.create(:category => "neutral", :body => "Gained approval privileges")
|
||||
user.can_approve_posts = true
|
||||
user.save
|
||||
end
|
||||
|
||||
def create_feedback
|
||||
user.feedback.create(
|
||||
:category => "neutral",
|
||||
:body => "Lost approval privileges"
|
||||
)
|
||||
end
|
||||
|
||||
def promote!
|
||||
update_attribute(:status, "inactive")
|
||||
end
|
||||
|
||||
def demote!
|
||||
user.can_approve_posts = false
|
||||
user.save
|
||||
update_attribute(:status, "inactive")
|
||||
self.create_feedback
|
||||
end
|
||||
|
||||
def active?
|
||||
status == "active"
|
||||
end
|
||||
|
||||
def inactive?
|
||||
status == "inactive"
|
||||
end
|
||||
end
|
||||
@@ -1,4 +0,0 @@
|
||||
<% content_for(:secondary_links) do %>
|
||||
<%= subnav_link_to "Listing", janitor_trials_path %>
|
||||
<%= subnav_link_to "New", new_janitor_trial_path %>
|
||||
<% end %>
|
||||
@@ -1 +0,0 @@
|
||||
location.reload();
|
||||
@@ -1,29 +0,0 @@
|
||||
<div id="c-janitor-trials">
|
||||
<div id="a-index">
|
||||
<h1>Janitor Trials</h1>
|
||||
|
||||
<table class="striped" width="100%">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>User</th>
|
||||
<th>Date</th>
|
||||
<td></td>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<% @janitor_trials.each do |janitor_trial| %>
|
||||
<tr>
|
||||
<td><%= link_to_user janitor_trial.user %></td>
|
||||
<td><%= compact_time janitor_trial.created_at %></td>
|
||||
<td>
|
||||
<%= link_to "Promote", promote_janitor_trial_path(janitor_trial), :remote => true, :method => :put %>
|
||||
| <%= link_to "Demote", demote_janitor_trial_path(janitor_trial), :remote => true, :method => :put %>
|
||||
</td>
|
||||
</tr>
|
||||
<% end %>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<%= render "secondary_links" %>
|
||||
@@ -1,17 +0,0 @@
|
||||
<div id="c-janitor-trials">
|
||||
<div id="a-new">
|
||||
<h1>New Janitor Trial</h1>
|
||||
|
||||
<%= error_messages_for :janitor_trial %>
|
||||
|
||||
<%= simple_form_for(@janitor_trial) do |f| %>
|
||||
<%= f.input :user_name, input_html: { data: { autocomplete: "user" } } %>
|
||||
<%= f.button :submit, "Submit" %>
|
||||
<%= f.button :submit, "Test" %>
|
||||
<% end %>
|
||||
|
||||
<p id="test-results"></p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<%= render "secondary_links" %>
|
||||
@@ -1 +0,0 @@
|
||||
location.reload();
|
||||
@@ -1 +0,0 @@
|
||||
<%= raw @tester.test.to_json %>
|
||||
@@ -151,7 +151,6 @@
|
||||
<li><%= link_to("Mod Actions", mod_actions_path) %></li>
|
||||
<li><%= link_to("Jobs", delayed_jobs_path) %></li>
|
||||
<li><%= link_to("Bulk Update Requests", bulk_update_requests_path) %></li>
|
||||
<li><%= link_to("Janitor Trials", janitor_trials_path) %></li>
|
||||
|
||||
<% if CurrentUser.is_member? %>
|
||||
<li><%= link_to("User Name Change Requests", user_name_change_requests_path) %></li>
|
||||
|
||||
@@ -162,15 +162,6 @@ Rails.application.routes.draw do
|
||||
get :check, to: redirect {|path_params, req| "/iqdb_queries?#{req.query_string}"}
|
||||
end
|
||||
end
|
||||
resources :janitor_trials do
|
||||
collection do
|
||||
get :test
|
||||
end
|
||||
member do
|
||||
put :promote
|
||||
put :demote
|
||||
end
|
||||
end
|
||||
resources :mod_actions
|
||||
resources :news_updates
|
||||
resources :notes do
|
||||
|
||||
7
db/migrate/20191117080647_drop_janitor_trials.rb
Normal file
7
db/migrate/20191117080647_drop_janitor_trials.rb
Normal file
@@ -0,0 +1,7 @@
|
||||
require_relative "20100309211553_create_janitor_trials"
|
||||
|
||||
class DropJanitorTrials < ActiveRecord::Migration[6.0]
|
||||
def change
|
||||
revert CreateJanitorTrials
|
||||
end
|
||||
end
|
||||
@@ -2379,40 +2379,6 @@ CREATE SEQUENCE public.ip_bans_id_seq
|
||||
ALTER SEQUENCE public.ip_bans_id_seq OWNED BY public.ip_bans.id;
|
||||
|
||||
|
||||
--
|
||||
-- Name: janitor_trials; Type: TABLE; Schema: public; Owner: -
|
||||
--
|
||||
|
||||
CREATE TABLE public.janitor_trials (
|
||||
id integer NOT NULL,
|
||||
creator_id integer NOT NULL,
|
||||
user_id integer NOT NULL,
|
||||
original_level integer,
|
||||
created_at timestamp without time zone NOT NULL,
|
||||
updated_at timestamp without time zone NOT NULL,
|
||||
status character varying DEFAULT 'active'::character varying NOT NULL
|
||||
);
|
||||
|
||||
|
||||
--
|
||||
-- Name: janitor_trials_id_seq; Type: SEQUENCE; Schema: public; Owner: -
|
||||
--
|
||||
|
||||
CREATE SEQUENCE public.janitor_trials_id_seq
|
||||
START WITH 1
|
||||
INCREMENT BY 1
|
||||
NO MINVALUE
|
||||
NO MAXVALUE
|
||||
CACHE 1;
|
||||
|
||||
|
||||
--
|
||||
-- Name: janitor_trials_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: -
|
||||
--
|
||||
|
||||
ALTER SEQUENCE public.janitor_trials_id_seq OWNED BY public.janitor_trials.id;
|
||||
|
||||
|
||||
--
|
||||
-- Name: mod_actions; Type: TABLE; Schema: public; Owner: -
|
||||
--
|
||||
@@ -4114,13 +4080,6 @@ ALTER TABLE ONLY public.forum_topics ALTER COLUMN id SET DEFAULT nextval('public
|
||||
ALTER TABLE ONLY public.ip_bans ALTER COLUMN id SET DEFAULT nextval('public.ip_bans_id_seq'::regclass);
|
||||
|
||||
|
||||
--
|
||||
-- Name: janitor_trials id; Type: DEFAULT; Schema: public; Owner: -
|
||||
--
|
||||
|
||||
ALTER TABLE ONLY public.janitor_trials ALTER COLUMN id SET DEFAULT nextval('public.janitor_trials_id_seq'::regclass);
|
||||
|
||||
|
||||
--
|
||||
-- Name: mod_actions id; Type: DEFAULT; Schema: public; Owner: -
|
||||
--
|
||||
@@ -4480,14 +4439,6 @@ ALTER TABLE ONLY public.ip_bans
|
||||
ADD CONSTRAINT ip_bans_pkey PRIMARY KEY (id);
|
||||
|
||||
|
||||
--
|
||||
-- Name: janitor_trials janitor_trials_pkey; Type: CONSTRAINT; Schema: public; Owner: -
|
||||
--
|
||||
|
||||
ALTER TABLE ONLY public.janitor_trials
|
||||
ADD CONSTRAINT janitor_trials_pkey PRIMARY KEY (id);
|
||||
|
||||
|
||||
--
|
||||
-- Name: mod_actions mod_actions_pkey; Type: CONSTRAINT; Schema: public; Owner: -
|
||||
--
|
||||
@@ -6542,13 +6493,6 @@ CREATE INDEX index_forum_topics_on_updated_at ON public.forum_topics USING btree
|
||||
CREATE INDEX index_ip_bans_on_ip_addr ON public.ip_bans USING btree (ip_addr);
|
||||
|
||||
|
||||
--
|
||||
-- Name: index_janitor_trials_on_user_id; Type: INDEX; Schema: public; Owner: -
|
||||
--
|
||||
|
||||
CREATE INDEX index_janitor_trials_on_user_id ON public.janitor_trials USING btree (user_id);
|
||||
|
||||
|
||||
--
|
||||
-- Name: index_mod_actions_on_created_at; Type: INDEX; Schema: public; Owner: -
|
||||
--
|
||||
@@ -7484,6 +7428,7 @@ INSERT INTO "schema_migrations" (version) VALUES
|
||||
('20191116001441'),
|
||||
('20191116021759'),
|
||||
('20191116224228'),
|
||||
('20191117074642');
|
||||
('20191117074642'),
|
||||
('20191117080647');
|
||||
|
||||
|
||||
|
||||
@@ -14,7 +14,6 @@ Disallow: /dmails
|
||||
Disallow: /favorite
|
||||
Disallow: /iqdb_queries
|
||||
Disallow: /ip_bans
|
||||
Disallow: /janitor_trials
|
||||
Disallow: /maintenance
|
||||
Disallow: /m/
|
||||
Disallow: /mod_actions
|
||||
|
||||
@@ -1,5 +0,0 @@
|
||||
FactoryBot.define do
|
||||
factory(:janitor_trial) do
|
||||
user
|
||||
end
|
||||
end
|
||||
@@ -1,77 +0,0 @@
|
||||
require 'test_helper'
|
||||
|
||||
class JanitorTrialsControllerTest < ActionDispatch::IntegrationTest
|
||||
context "The janitor trials controller" do
|
||||
setup do
|
||||
@admin = create(:admin_user)
|
||||
@user = create(:user)
|
||||
end
|
||||
|
||||
context "new action" do
|
||||
should "render" do
|
||||
get_auth new_janitor_trial_path, @admin
|
||||
assert_response :success
|
||||
end
|
||||
end
|
||||
|
||||
context "create action" do
|
||||
should "create a new janitor trial" do
|
||||
assert_difference("JanitorTrial.count", 1) do
|
||||
post_auth janitor_trials_path, @admin, params: {:janitor_trial => {:user_id => @user.id}}
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
context "promote action" do
|
||||
setup do
|
||||
as(@admin) do
|
||||
@janitor_trial = create(:janitor_trial, :user_id => @user.id)
|
||||
end
|
||||
end
|
||||
|
||||
should "promote the janitor trial" do
|
||||
put_auth promote_janitor_trial_path(@janitor_trial), @admin
|
||||
@user.reload
|
||||
assert(@user.can_approve_posts?)
|
||||
@janitor_trial.reload
|
||||
assert_equal(false, @janitor_trial.active?)
|
||||
end
|
||||
end
|
||||
|
||||
context "demote action" do
|
||||
setup do
|
||||
as(@admin) do
|
||||
@janitor_trial = create(:janitor_trial, :user_id => @user.id)
|
||||
end
|
||||
end
|
||||
|
||||
should "demote the janitor trial" do
|
||||
put_auth demote_janitor_trial_path(@janitor_trial), @admin
|
||||
@user.reload
|
||||
assert(!@user.can_approve_posts?)
|
||||
@janitor_trial.reload
|
||||
assert_equal(false, @janitor_trial.active?)
|
||||
end
|
||||
end
|
||||
|
||||
context "index action" do
|
||||
setup do
|
||||
as(@admin) do
|
||||
create(:janitor_trial)
|
||||
end
|
||||
end
|
||||
|
||||
should "render" do
|
||||
get_auth janitor_trials_path, @admin
|
||||
assert_response :success
|
||||
end
|
||||
|
||||
context "with search parameters" do
|
||||
should "render" do
|
||||
get_auth janitor_trials_path, @admin, params: {:search => {:user_name => @user.name}}
|
||||
assert_response :success
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -1,60 +0,0 @@
|
||||
require 'test_helper'
|
||||
|
||||
class JanitorTrialTest < ActiveSupport::TestCase
|
||||
context "A janitor trial" do
|
||||
setup do
|
||||
@admin = FactoryBot.create(:admin_user)
|
||||
@user = FactoryBot.create(:user)
|
||||
CurrentUser.user = @admin
|
||||
CurrentUser.ip_addr = "127.0.0.1"
|
||||
end
|
||||
|
||||
teardown do
|
||||
CurrentUser.user = nil
|
||||
CurrentUser.ip_addr = nil
|
||||
end
|
||||
|
||||
context "upon creation" do
|
||||
should "create a dmail when testing a new janitor" do
|
||||
assert_difference("Dmail.count", 2) do
|
||||
JanitorTrial.create(:user_id => @user.id)
|
||||
end
|
||||
end
|
||||
|
||||
should "toggle the can_approve_posts flag on the user" do
|
||||
janitor_trial = JanitorTrial.create(:user_id => @user.id)
|
||||
@user.reload
|
||||
assert(@user.can_approve_posts?)
|
||||
end
|
||||
end
|
||||
|
||||
context "upon demotion" do
|
||||
setup do
|
||||
@janitor_trial = FactoryBot.create(:janitor_trial, :user_id => @user.id)
|
||||
end
|
||||
|
||||
should "create a negative feedback record" do
|
||||
assert_difference("UserFeedback.count", 1) do
|
||||
@janitor_trial.demote!
|
||||
end
|
||||
end
|
||||
|
||||
should "revoke approval privileges" do
|
||||
@janitor_trial.demote!
|
||||
@user.reload
|
||||
assert_equal(false, @user.can_approve_posts?)
|
||||
end
|
||||
end
|
||||
|
||||
context "upon promotion" do
|
||||
setup do
|
||||
@janitor_trial = FactoryBot.create(:janitor_trial, :user_id => @user.id)
|
||||
end
|
||||
|
||||
should "destroy the trial object" do
|
||||
@janitor_trial.promote!
|
||||
assert_equal(false, @janitor_trial.active?)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user