fixes #1350, better db:seed script
This commit is contained in:
@@ -1,7 +1,7 @@
|
|||||||
module Moderator
|
module Moderator
|
||||||
module Post
|
module Post
|
||||||
class PostsController < ApplicationController
|
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]
|
before_filter :admin_only, :only => [:expunge]
|
||||||
rescue_from ::PostFlag::Error, :with => :rescue_exception
|
rescue_from ::PostFlag::Error, :with => :rescue_exception
|
||||||
|
|
||||||
@@ -27,6 +27,24 @@ module Moderator
|
|||||||
@post = ::Post.find(params[:id])
|
@post = ::Post.find(params[:id])
|
||||||
@post.expunge!
|
@post.expunge!
|
||||||
end
|
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
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -1,6 +1,5 @@
|
|||||||
class PostsController < ApplicationController
|
class PostsController < ApplicationController
|
||||||
before_filter :member_only, :except => [:show, :show_seq, :index]
|
before_filter :member_only, :except => [:show, :show_seq, :index]
|
||||||
before_filter :janitor_only, :only => [:ban, :unban]
|
|
||||||
after_filter :save_recent_tags, :only => [:update]
|
after_filter :save_recent_tags, :only => [:update]
|
||||||
respond_to :html, :xml, :json
|
respond_to :html, :xml, :json
|
||||||
rescue_from PostSets::SearchError, :with => :rescue_exception
|
rescue_from PostSets::SearchError, :with => :rescue_exception
|
||||||
@@ -69,19 +68,6 @@ class PostsController < ApplicationController
|
|||||||
end
|
end
|
||||||
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
|
private
|
||||||
def tag_query
|
def tag_query
|
||||||
params[:tags] || (params[:post] && params[:post][:tags])
|
params[:tags] || (params[:post] && params[:post][:tags])
|
||||||
|
|||||||
@@ -92,15 +92,14 @@ class Tag < ActiveRecord::Base
|
|||||||
Danbooru.config.other_server_hosts.each do |host|
|
Danbooru.config.other_server_hosts.each do |host|
|
||||||
delay(:queue => host).update_category_cache
|
delay(:queue => host).update_category_cache
|
||||||
end
|
end
|
||||||
|
|
||||||
delay(:queue => "default").update_category_post_counts
|
delay(:queue => "default").update_category_post_counts
|
||||||
end
|
end
|
||||||
|
|
||||||
def update_category_post_counts
|
def update_category_post_counts
|
||||||
Post.raw_tag_match(name).find_each do |post|
|
Post.with_timeout(30_000, nil) do
|
||||||
post.reload
|
Post.raw_tag_match(name).find_each do |post|
|
||||||
post.set_tag_counts
|
post.reload
|
||||||
Post.with_timeout(10_000, nil) do
|
post.set_tag_counts
|
||||||
post.update_column(:tag_count, post.tag_count)
|
post.update_column(:tag_count, post.tag_count)
|
||||||
post.update_column(:tag_count_general, post.tag_count_general)
|
post.update_column(:tag_count_general, post.tag_count_general)
|
||||||
post.update_column(:tag_count_artist, post.tag_count_artist)
|
post.update_column(:tag_count_artist, post.tag_count_artist)
|
||||||
|
|||||||
12
app/views/moderator/post/posts/confirm_ban.html.erb
Normal file
12
app/views/moderator/post/posts/confirm_ban.html.erb
Normal 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 %>
|
||||||
@@ -34,7 +34,11 @@
|
|||||||
Flagged
|
Flagged
|
||||||
<% end %>
|
<% 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
|
Active
|
||||||
<% end %>
|
<% end %>
|
||||||
</li>
|
</li>
|
||||||
|
|||||||
@@ -6,7 +6,7 @@
|
|||||||
</div>
|
</div>
|
||||||
<% end %>
|
<% 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">
|
<div class="ui-corner-all ui-state-highlight notice notice-deleted">
|
||||||
<% if post.is_banned? %>
|
<% if post.is_banned? %>
|
||||||
This post was deleted because it was requested by the artist
|
This post was deleted because it was requested by the artist
|
||||||
|
|||||||
@@ -35,9 +35,9 @@
|
|||||||
<% end %>
|
<% end %>
|
||||||
|
|
||||||
<% if post.is_banned? %>
|
<% 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 %>
|
<% 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 %>
|
<% end %>
|
||||||
|
|
||||||
<% if CurrentUser.is_admin? %>
|
<% if CurrentUser.is_admin? %>
|
||||||
|
|||||||
@@ -22,6 +22,9 @@ Danbooru::Application.routes.draw do
|
|||||||
post :expunge
|
post :expunge
|
||||||
post :delete
|
post :delete
|
||||||
post :undelete
|
post :undelete
|
||||||
|
get :confirm_ban
|
||||||
|
post :ban
|
||||||
|
post :unban
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@@ -139,8 +142,6 @@ Danbooru::Application.routes.draw do
|
|||||||
member do
|
member do
|
||||||
put :revert
|
put :revert
|
||||||
get :show_seq
|
get :show_seq
|
||||||
post :ban
|
|
||||||
post :unban
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
resources :post_appeals, :only => [:new, :index, :create]
|
resources :post_appeals, :only => [:new, :index, :create]
|
||||||
|
|||||||
56
db/seeds.rb
56
db/seeds.rb
@@ -1,17 +1,51 @@
|
|||||||
|
require 'set'
|
||||||
|
|
||||||
CurrentUser.ip_addr = "127.0.0.1"
|
CurrentUser.ip_addr = "127.0.0.1"
|
||||||
Delayed::Worker.delay_jobs = false
|
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
|
if User.count == 0
|
||||||
puts "Creating users"
|
puts "Creating users"
|
||||||
user = User.create(
|
user = User.create(
|
||||||
:name => "albert",
|
:name => "admin",
|
||||||
:password => "password1",
|
:password => "password1",
|
||||||
:password_confirmation => "password1"
|
:password_confirmation => "password1"
|
||||||
)
|
)
|
||||||
|
|
||||||
0.upto(100) do |i|
|
0.upto(10) do |i|
|
||||||
User.create(
|
User.create(
|
||||||
:name => i.to_s * 5,
|
:name => rand_string(8),
|
||||||
:password => i.to_s * 5,
|
:password => i.to_s * 5,
|
||||||
:password_confirmation => i.to_s * 5
|
:password_confirmation => i.to_s * 5
|
||||||
)
|
)
|
||||||
@@ -31,7 +65,7 @@ if Upload.count == 0
|
|||||||
width = rand(2000) + 100
|
width = rand(2000) + 100
|
||||||
height = rand(2000) + 100
|
height = rand(2000) + 100
|
||||||
url = "http://ipsumimage.appspot.com/#{width}x#{height}"
|
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)
|
Upload.create(:source => url, :content_type => "image/gif", :rating => "q", :tag_string => tags, :server => Socket.gethostname)
|
||||||
end
|
end
|
||||||
@@ -52,7 +86,7 @@ if Comment.count == 0
|
|||||||
puts "Creating comments"
|
puts "Creating comments"
|
||||||
Post.all.each do |post|
|
Post.all.each do |post|
|
||||||
rand(30).times do
|
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
|
||||||
end
|
end
|
||||||
else
|
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)
|
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|
|
rand(30).times do |i|
|
||||||
note.update_attributes(:body => (i * i).to_s)
|
note.update_attributes(:body => rand_sentence(6))
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@@ -77,7 +111,7 @@ end
|
|||||||
if Artist.count == 0
|
if Artist.count == 0
|
||||||
puts "Creating artists"
|
puts "Creating artists"
|
||||||
0.upto(100) do |i|
|
0.upto(100) do |i|
|
||||||
Artist.create(:name => i.to_s)
|
Artist.create(:name => rand_string(6))
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
puts "Skipping artists"
|
puts "Skipping artists"
|
||||||
@@ -87,7 +121,7 @@ if TagAlias.count == 0
|
|||||||
puts "Creating tag aliases"
|
puts "Creating tag aliases"
|
||||||
|
|
||||||
100.upto(199) do |i|
|
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
|
end
|
||||||
else
|
else
|
||||||
puts "Skipping tag aliases"
|
puts "Skipping tag aliases"
|
||||||
@@ -97,7 +131,7 @@ if TagImplication.count == 0
|
|||||||
puts "Creating tag implictions"
|
puts "Creating tag implictions"
|
||||||
|
|
||||||
100_000.upto(100_100) do |i|
|
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
|
end
|
||||||
else
|
else
|
||||||
puts "Skipping tag implications"
|
puts "Skipping tag implications"
|
||||||
@@ -130,10 +164,10 @@ if ForumTopic.count == 0
|
|||||||
puts "Creating forum posts"
|
puts "Creating forum posts"
|
||||||
|
|
||||||
100.times do |i|
|
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|
|
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
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
Reference in New Issue
Block a user