diff --git a/app/controllers/anti_voters_controller.rb b/app/controllers/anti_voters_controller.rb new file mode 100644 index 000000000..597b459d3 --- /dev/null +++ b/app/controllers/anti_voters_controller.rb @@ -0,0 +1,8 @@ +class AntiVotersController < ApplicationController + before_filter :member_only + + def index + @anti_voters = AntiVoter.all + end +end + diff --git a/app/logical/daily_maintenance.rb b/app/logical/daily_maintenance.rb index e212a161b..e503f52f8 100644 --- a/app/logical/daily_maintenance.rb +++ b/app/logical/daily_maintenance.rb @@ -16,5 +16,6 @@ class DailyMaintenance PostDisapproval.dmail_messages! Tag.clean_up_negative_post_counts! SuperVoter.init! + AntiVote.init! end end diff --git a/app/models/anti_voter.rb b/app/models/anti_voter.rb new file mode 100644 index 000000000..3b900aef7 --- /dev/null +++ b/app/models/anti_voter.rb @@ -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 diff --git a/app/views/anti_voters/index.html.erb b/app/views/anti_voters/index.html.erb new file mode 100644 index 000000000..3c2f96d54 --- /dev/null +++ b/app/views/anti_voters/index.html.erb @@ -0,0 +1,15 @@ +
+
+

Anti Voters

+ + +
+
+ +<% content_for(:page_title) do %> + Anti Voters - <%= Danbooru.config.app_name %> +<% end %> diff --git a/db/migrate/20160919234407_create_anti_voters.rb b/db/migrate/20160919234407_create_anti_voters.rb new file mode 100644 index 000000000..030cb5793 --- /dev/null +++ b/db/migrate/20160919234407_create_anti_voters.rb @@ -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