From b2e6a8f0316af2570c21409ace7f31107f654acb Mon Sep 17 00:00:00 2001 From: r888888888 Date: Mon, 19 Sep 2016 16:47:55 -0700 Subject: [PATCH] add antivoters (no behavior yet) --- app/controllers/anti_voters_controller.rb | 8 +++++ app/logical/daily_maintenance.rb | 1 + app/models/anti_voter.rb | 34 +++++++++++++++++++ app/views/anti_voters/index.html.erb | 15 ++++++++ .../20160919234407_create_anti_voters.rb | 8 +++++ 5 files changed, 66 insertions(+) create mode 100644 app/controllers/anti_voters_controller.rb create mode 100644 app/models/anti_voter.rb create mode 100644 app/views/anti_voters/index.html.erb create mode 100644 db/migrate/20160919234407_create_anti_voters.rb 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

+ +
    + <% @anti_voters.each do |anti_voter| %> +
  • <%= link_to_if CurrentUser.user.is_janitor?, anti_voter.user.name, posts_path(tags: "upvote:#{anti_voter.user.name}") %>
  • + <% end %> +
+
+
+ +<% 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