add antivoters (no behavior yet)

This commit is contained in:
r888888888 2016-09-19 16:47:55 -07:00
parent bf2246f895
commit b2e6a8f031
5 changed files with 66 additions and 0 deletions

View File

@ -0,0 +1,8 @@
class AntiVotersController < ApplicationController
before_filter :member_only
def index
@anti_voters = AntiVoter.all
end
end

View File

@ -16,5 +16,6 @@ class DailyMaintenance
PostDisapproval.dmail_messages!
Tag.clean_up_negative_post_counts!
SuperVoter.init!
AntiVote.init!
end
end

34
app/models/anti_voter.rb Normal file
View File

@ -0,0 +1,34 @@
class AntiVoter < ActiveRecord::Base
MAGNITUDE = 3
DURATION = 1.week
belongs_to :user
validates_uniqueness_of :user_id
# after_create :update_user_on_create
# after_destroy :update_user_on_destroy
def self.prune!
where("created_at < ?", DURATION.ago).destroy_all
end
def self.init!
prune!
report = PostVoteSimilarity.new(User.admins.first.id)
report.calculate_negative.each do |element|
unless where("user_id = ?", element.user_id).exists?
create(:user_id => element.user_id)
end
end
end
# def update_user_on_create
# user.is_super_voter = true
# user.save
# end
# def update_user_on_destroy
# user.is_super_voter = false
# user.save
# end
end

View File

@ -0,0 +1,15 @@
<div id="c-super-voters">
<div id="a-index">
<h1>Anti Voters</h1>
<ul>
<% @anti_voters.each do |anti_voter| %>
<li><%= link_to_if CurrentUser.user.is_janitor?, anti_voter.user.name, posts_path(tags: "upvote:#{anti_voter.user.name}") %></li>
<% end %>
</ul>
</div>
</div>
<% content_for(:page_title) do %>
Anti Voters - <%= Danbooru.config.app_name %>
<% end %>

View File

@ -0,0 +1,8 @@
class CreateAntiVoters < ActiveRecord::Migration
def change
create_table :anti_voters do |t|
t.integer :user_id
t.timestamps null: false
end
end
end