fixes #1350, better db:seed script

This commit is contained in:
r888888888 2013-04-16 20:23:02 -07:00
parent 9ce04fb5df
commit 2dfa616f33
9 changed files with 91 additions and 37 deletions

View File

@ -1,7 +1,7 @@
module Moderator
module Post
class PostsController < ApplicationController
before_filter :janitor_only, :only => [:delete, :undelete]
before_filter :janitor_only, :only => [:delete, :undelete, :ban, :unban, :confirm_delete, :confirm_ban]
before_filter :admin_only, :only => [:expunge]
rescue_from ::PostFlag::Error, :with => :rescue_exception
@ -27,6 +27,24 @@ module Moderator
@post = ::Post.find(params[:id])
@post.expunge!
end
def confirm_ban
@post = ::Post.find(params[:id])
end
def ban
@post = ::Post.find(params[:id])
if params[:commit] == "Ban"
@post.update_column(:is_banned, true)
end
redirect_to(post_path(@post), :notice => "Post was banned")
end
def unban
@post = ::Post.find(params[:id])
@post.update_attribute(:is_banned, false)
redirect_to(post_path(@post), :notice => "Post was unbanned")
end
end
end
end

View File

@ -1,6 +1,5 @@
class PostsController < ApplicationController
before_filter :member_only, :except => [:show, :show_seq, :index]
before_filter :janitor_only, :only => [:ban, :unban]
after_filter :save_recent_tags, :only => [:update]
respond_to :html, :xml, :json
rescue_from PostSets::SearchError, :with => :rescue_exception
@ -69,19 +68,6 @@ class PostsController < ApplicationController
end
end
def ban
@post = Post.find(params[:id])
@post.update_attribute(:is_banned, true)
redirect_to(post_path(@post), :notice => "Post was banned")
end
def unban
@post = Post.find(params[:id])
@post.update_attribute(:is_Banned, false)
redirect_to(post_path(@post), :notice => "Post was unbanned")
end
private
def tag_query
params[:tags] || (params[:post] && params[:post][:tags])

View File

@ -92,15 +92,14 @@ class Tag < ActiveRecord::Base
Danbooru.config.other_server_hosts.each do |host|
delay(:queue => host).update_category_cache
end
delay(:queue => "default").update_category_post_counts
end
def update_category_post_counts
Post.raw_tag_match(name).find_each do |post|
post.reload
post.set_tag_counts
Post.with_timeout(10_000, nil) do
Post.with_timeout(30_000, nil) do
Post.raw_tag_match(name).find_each do |post|
post.reload
post.set_tag_counts
post.update_column(:tag_count, post.tag_count)
post.update_column(:tag_count_general, post.tag_count_general)
post.update_column(:tag_count_artist, post.tag_count_artist)

View File

@ -0,0 +1,12 @@
<h1>Ban Post</h1>
<div>
<%= PostPresenter.preview(@post) %>
</div>
<%= form_tag(ban_moderator_post_post_path(@post), :style => "clear: both;", :class => "simple_form") do %>
<p>Banning a post will hide it from anyone without a gold level account or higher. You should only ban a post if an artist requested it.</p>
<%= submit_tag "Ban" %>
<%= submit_tag "Cancel" %>
<% end %>

View File

@ -34,7 +34,11 @@
Flagged
<% end %>
<% if !post.is_pending? && !post.is_deleted? %>
<% if post.is_banned? %>
Banned
<% end %>
<% if !post.is_pending? && !post.is_deleted? && !post.is_banned? %>
Active
<% end %>
</li>

View File

@ -6,7 +6,7 @@
</div>
<% end %>
<% if post.is_deleted? && post.flags.empty? %>
<% if (post.is_banned? || post.is_deleted?) && post.flags.empty? %>
<div class="ui-corner-all ui-state-highlight notice notice-deleted">
<% if post.is_banned? %>
This post was deleted because it was requested by the artist

View File

@ -35,9 +35,9 @@
<% end %>
<% if post.is_banned? %>
<li><%= link_to "Unban", unban_post_path(post), :method => :post %></li>
<li><%= link_to "Unban", unban_moderator_post_post_path(post), :method => :post %></li>
<% else %>
<li><%= link_to "Ban", ban_post_path(post), :method => :post %></li>
<li><%= link_to "Ban", confirm_ban_moderator_post_post_path(post) %></li>
<% end %>
<% if CurrentUser.is_admin? %>

View File

@ -22,6 +22,9 @@ Danbooru::Application.routes.draw do
post :expunge
post :delete
post :undelete
get :confirm_ban
post :ban
post :unban
end
end
end
@ -139,8 +142,6 @@ Danbooru::Application.routes.draw do
member do
put :revert
get :show_seq
post :ban
post :unban
end
end
resources :post_appeals, :only => [:new, :index, :create]

View File

@ -1,17 +1,51 @@
require 'set'
CurrentUser.ip_addr = "127.0.0.1"
Delayed::Worker.delay_jobs = false
$used_names = Set.new([""])
def rand_string(n)
string = ""
n = rand(n) + 1
while $used_names.include?(string)
consonants = "bcdfghjklmnpqrstvwxz".scan(/./)
vowels = "aeiouy".scan(/./)
string = ""
n.times do
string << consonants[rand(consonants.size)]
string << vowels[rand(vowels.size)]
end
end
$used_names.add(string)
string
end
def rand_sentence(n)
(0..n).map {rand_string(6)}.join(" ") + "."
end
def rand_paragraph(n)
(0..n).map {rand_sentence(6)}.join(" ")
end
def rand_document(n)
(0..n).map {rand_pargraph(6)}.join("\n\n")
end
if User.count == 0
puts "Creating users"
user = User.create(
:name => "albert",
:name => "admin",
:password => "password1",
:password_confirmation => "password1"
)
0.upto(100) do |i|
0.upto(10) do |i|
User.create(
:name => i.to_s * 5,
:name => rand_string(8),
:password => i.to_s * 5,
:password_confirmation => i.to_s * 5
)
@ -31,7 +65,7 @@ if Upload.count == 0
width = rand(2000) + 100
height = rand(2000) + 100
url = "http://ipsumimage.appspot.com/#{width}x#{height}"
tags = (i * i * i).to_s.scan(/./).uniq.join(" ")
tags = rand_sentence(6).scan(/[a-z]+/).join(" ")
Upload.create(:source => url, :content_type => "image/gif", :rating => "q", :tag_string => tags, :server => Socket.gethostname)
end
@ -52,7 +86,7 @@ if Comment.count == 0
puts "Creating comments"
Post.all.each do |post|
rand(30).times do
Comment.create(:post_id => post.id, :body => Time.now.to_f.to_s)
Comment.create(:post_id => post.id, :body => rand_paragraph(6))
end
end
else
@ -66,7 +100,7 @@ if Note.count == 0
note = Note.create(:post_id => post.id, :x => 0, :y => 0, :width => 100, :height => 100, :body => Time.now.to_f.to_s)
rand(30).times do |i|
note.update_attributes(:body => (i * i).to_s)
note.update_attributes(:body => rand_sentence(6))
end
end
end
@ -77,7 +111,7 @@ end
if Artist.count == 0
puts "Creating artists"
0.upto(100) do |i|
Artist.create(:name => i.to_s)
Artist.create(:name => rand_string(6))
end
else
puts "Skipping artists"
@ -87,7 +121,7 @@ if TagAlias.count == 0
puts "Creating tag aliases"
100.upto(199) do |i|
TagAlias.create(:antecedent_name => i.to_s, :consequent_name => (i * 100).to_s)
TagAlias.create(:antecedent_name => rand_string(6), :consequent_name => rand_string(6))
end
else
puts "Skipping tag aliases"
@ -97,7 +131,7 @@ if TagImplication.count == 0
puts "Creating tag implictions"
100_000.upto(100_100) do |i|
TagImplication.create(:antecedent_name => i.to_s, :consequent_name => (i * 100).to_s)
TagImplication.create(:antecedent_name => rand_string(6), :consequent_name => rand_string(6))
end
else
puts "Skipping tag implications"
@ -130,10 +164,10 @@ if ForumTopic.count == 0
puts "Creating forum posts"
100.times do |i|
topic = ForumTopic.create(:title => Time.now.to_f.to_s)
topic = ForumTopic.create(:title => rand_sentence(6))
rand(100).times do |j|
post = ForumPost.create(:topic_id => topic.id, :body => Time.now.to_f.to_s)
post = ForumPost.create(:topic_id => topic.id, :body => rand_document(6))
end
end
end