forked from e621ng/e621ng
[Cleanup] Remove janitor trials
This commit is contained in:
parent
2263501b88
commit
e01ab43577
@ -1,46 +0,0 @@
|
||||
class JanitorTrialsController < ApplicationController
|
||||
respond_to :html, :json
|
||||
before_action :admin_only
|
||||
|
||||
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.search(search_params).paginate(params[:page], :limit => params[:limit])
|
||||
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, location: janitor_trials_path)
|
||||
end
|
||||
|
||||
def demote
|
||||
@janitor_trial = JanitorTrial.find(params[:id])
|
||||
@janitor_trial.demote!
|
||||
respond_with(@janitor_trial, location: janitor_trials_path)
|
||||
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
|
@ -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,74 +0,0 @@
|
||||
class JanitorTrial < ApplicationRecord
|
||||
belongs_to :user
|
||||
after_create :send_dmail
|
||||
after_create :promote_user
|
||||
validates :user, presence: true
|
||||
belongs_to_creator
|
||||
validates :status, inclusion: { :in => %w(active inactive) }
|
||||
before_validation :initialize_status
|
||||
validates :user_id, uniqueness: true
|
||||
|
||||
def self.search(params)
|
||||
q = super.where(status: "active")
|
||||
|
||||
if params[:user_name]
|
||||
q = q.where("user_id = (select _.id from users _ where lower(_.name) = ?)", params[:user_name].mb_chars.downcase)
|
||||
end
|
||||
|
||||
if params[:user_id]
|
||||
q = q.where("user_id = ?", params[:user_id].to_i)
|
||||
end
|
||||
|
||||
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_id = User.name_to_id(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,6 +0,0 @@
|
||||
<% content_for(:secondary_links) do %>
|
||||
<menu>
|
||||
<%= subnav_link_to "Listing", janitor_trials_path %>
|
||||
<%= subnav_link_to "New", new_janitor_trial_path %>
|
||||
</menu>
|
||||
<% end %>
|
@ -1 +0,0 @@
|
||||
location.reload();
|
@ -1,33 +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), :method => :put %>
|
||||
| <%= link_to "Demote", demote_janitor_trial_path(janitor_trial), :method => :put %>
|
||||
</td>
|
||||
</tr>
|
||||
<% end %>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<%= render "secondary_links" %>
|
||||
|
||||
<% content_for(:page_title) do %>
|
||||
Janitor Trials
|
||||
<% end %>
|
@ -1,20 +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" %>
|
||||
<% content_for(:page_title) do %>
|
||||
New Janitor
|
||||
<% end %>
|
@ -1 +0,0 @@
|
||||
location.reload();
|
@ -1 +0,0 @@
|
||||
<%= raw @tester.test.to_json %>
|
@ -200,15 +200,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
|
||||
|
@ -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
|
Loading…
Reference in New Issue
Block a user