Files
danbooru/app/models/ip_ban.rb
albert 23656e3fa9 * Continued work on improving post view templates
* Added statistics-based estimator for related tag calculator
* Fleshed out IpBan class based on changes to Danbooru 1.xx
2010-04-29 17:32:15 -04:00

30 lines
1000 B
Ruby

class IpBan < ActiveRecord::Base
belongs_to :creator, :class_name => "User"
validates_presence_of :reason
validates_uniqueness_of :ip_addr
def self.is_banned?(ip_addr)
exists?(["ip_addr = ?", ip_addr])
end
def self.search(user_ids)
comments = count_by_ip_addr("comments", user_ids, "creator_id")
posts = count_by_ip_addr("post_versions", user_ids, "updater_id")
notes = count_by_ip_addr("note_versions", user_ids, "updater_id")
pools = count_by_ip_addr("pool_updates", user_ids, "updater_id")
wiki_pages = count_by_ip_addr("wiki_page_versions", user_ids, "updater_id")
return {
"comments" => comments,
"posts" => posts,
"notes" => notes,
"pools" => pools,
"wiki_pages" => wiki_pages
}
end
def self.count_by_ip_addr(table, user_ids, user_id_field = "user_id")
select_all_sql("SELECT ip_addr, count(*) FROM #{table} WHERE #{user_id_field} IN (?) GROUP BY ip_addr ORDER BY count(*) DESC", user_ids)
end
end