diff --git a/app/controllers/janitor_trials_controller.rb b/app/controllers/janitor_trials_controller.rb deleted file mode 100644 index 0cac7913f..000000000 --- a/app/controllers/janitor_trials_controller.rb +++ /dev/null @@ -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 diff --git a/app/javascript/src/javascripts/janitor_trials.js b/app/javascript/src/javascripts/janitor_trials.js deleted file mode 100644 index 0976e7652..000000000 --- a/app/javascript/src/javascripts/janitor_trials.js +++ /dev/null @@ -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 diff --git a/app/logical/approver_pruner.rb b/app/logical/approver_pruner.rb index cd2e81ef7..c37586761 100644 --- a/app/logical/approver_pruner.rb +++ b/app/logical/approver_pruner.rb @@ -13,15 +13,9 @@ 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 + user.update!(can_approve_posts: false) + user.feedback.create(category: "neutral", body: "Lost approval privileges") - if janitor_trial && user.can_approve_posts? - janitor_trial.demote! - else - user.can_approve_posts = false - user.save - end - Dmail.create_automated( :to_id => user.id, :title => "Approver inactivity", diff --git a/app/logical/janitor_trial_tester.rb b/app/logical/janitor_trial_tester.rb deleted file mode 100644 index 37b402790..000000000 --- a/app/logical/janitor_trial_tester.rb +++ /dev/null @@ -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 diff --git a/app/models/janitor_trial.rb b/app/models/janitor_trial.rb deleted file mode 100644 index 430f6240c..000000000 --- a/app/models/janitor_trial.rb +++ /dev/null @@ -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 diff --git a/app/views/janitor_trials/_secondary_links.html.erb b/app/views/janitor_trials/_secondary_links.html.erb deleted file mode 100644 index e42fa5d95..000000000 --- a/app/views/janitor_trials/_secondary_links.html.erb +++ /dev/null @@ -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 %> diff --git a/app/views/janitor_trials/demote.js.erb b/app/views/janitor_trials/demote.js.erb deleted file mode 100644 index 345366b9b..000000000 --- a/app/views/janitor_trials/demote.js.erb +++ /dev/null @@ -1 +0,0 @@ -location.reload(); diff --git a/app/views/janitor_trials/index.html.erb b/app/views/janitor_trials/index.html.erb deleted file mode 100644 index bc053c072..000000000 --- a/app/views/janitor_trials/index.html.erb +++ /dev/null @@ -1,29 +0,0 @@ -
-
-

Janitor Trials

- - - - - - - - - - - <% @janitor_trials.each do |janitor_trial| %> - - - - - - <% end %> - -
UserDate
<%= link_to_user janitor_trial.user %><%= compact_time janitor_trial.created_at %> - <%= 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 %> -
-
-
- -<%= render "secondary_links" %> diff --git a/app/views/janitor_trials/new.html.erb b/app/views/janitor_trials/new.html.erb deleted file mode 100644 index be6989053..000000000 --- a/app/views/janitor_trials/new.html.erb +++ /dev/null @@ -1,17 +0,0 @@ -
-
-

New Janitor Trial

- - <%= 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 %> - -

-
-
- -<%= render "secondary_links" %> diff --git a/app/views/janitor_trials/promote.js.erb b/app/views/janitor_trials/promote.js.erb deleted file mode 100644 index 345366b9b..000000000 --- a/app/views/janitor_trials/promote.js.erb +++ /dev/null @@ -1 +0,0 @@ -location.reload(); diff --git a/app/views/janitor_trials/test.json.erb b/app/views/janitor_trials/test.json.erb deleted file mode 100644 index b6a98a878..000000000 --- a/app/views/janitor_trials/test.json.erb +++ /dev/null @@ -1 +0,0 @@ -<%= raw @tester.test.to_json %> diff --git a/app/views/static/site_map.html.erb b/app/views/static/site_map.html.erb index 0c8b306ab..65accf367 100644 --- a/app/views/static/site_map.html.erb +++ b/app/views/static/site_map.html.erb @@ -151,7 +151,6 @@
  • <%= link_to("Mod Actions", mod_actions_path) %>
  • <%= link_to("Jobs", delayed_jobs_path) %>
  • <%= link_to("Bulk Update Requests", bulk_update_requests_path) %>
  • -
  • <%= link_to("Janitor Trials", janitor_trials_path) %>
  • <% if CurrentUser.is_member? %>
  • <%= link_to("User Name Change Requests", user_name_change_requests_path) %>
  • diff --git a/config/routes.rb b/config/routes.rb index bef725617..5c8b4a42c 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -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 diff --git a/db/migrate/20191117080647_drop_janitor_trials.rb b/db/migrate/20191117080647_drop_janitor_trials.rb new file mode 100644 index 000000000..854e990c0 --- /dev/null +++ b/db/migrate/20191117080647_drop_janitor_trials.rb @@ -0,0 +1,7 @@ +require_relative "20100309211553_create_janitor_trials" + +class DropJanitorTrials < ActiveRecord::Migration[6.0] + def change + revert CreateJanitorTrials + end +end diff --git a/db/structure.sql b/db/structure.sql index 600022a51..099caa5af 100644 --- a/db/structure.sql +++ b/db/structure.sql @@ -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'); diff --git a/public/robots.txt b/public/robots.txt index 84e8d0635..8e267d4a2 100644 --- a/public/robots.txt +++ b/public/robots.txt @@ -14,7 +14,6 @@ Disallow: /dmails Disallow: /favorite Disallow: /iqdb_queries Disallow: /ip_bans -Disallow: /janitor_trials Disallow: /maintenance Disallow: /m/ Disallow: /mod_actions diff --git a/test/factories/janitor_trial.rb b/test/factories/janitor_trial.rb deleted file mode 100644 index 7864e4887..000000000 --- a/test/factories/janitor_trial.rb +++ /dev/null @@ -1,5 +0,0 @@ -FactoryBot.define do - factory(:janitor_trial) do - user - end -end diff --git a/test/functional/janitor_trials_controller_test.rb b/test/functional/janitor_trials_controller_test.rb deleted file mode 100644 index 49777c2b1..000000000 --- a/test/functional/janitor_trials_controller_test.rb +++ /dev/null @@ -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 diff --git a/test/unit/janitor_trial_test.rb b/test/unit/janitor_trial_test.rb deleted file mode 100644 index d4728514d..000000000 --- a/test/unit/janitor_trial_test.rb +++ /dev/null @@ -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