diff --git a/app/controllers/moderator/post/posts_controller.rb b/app/controllers/moderator/post/posts_controller.rb
index def840222..160e4cebd 100644
--- a/app/controllers/moderator/post/posts_controller.rb
+++ b/app/controllers/moderator/post/posts_controller.rb
@@ -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
diff --git a/app/controllers/posts_controller.rb b/app/controllers/posts_controller.rb
index 369d7d45a..45a7b8dd7 100644
--- a/app/controllers/posts_controller.rb
+++ b/app/controllers/posts_controller.rb
@@ -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])
diff --git a/app/models/tag.rb b/app/models/tag.rb
index a5172d6f8..67273b5bd 100644
--- a/app/models/tag.rb
+++ b/app/models/tag.rb
@@ -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)
diff --git a/app/views/moderator/post/posts/confirm_ban.html.erb b/app/views/moderator/post/posts/confirm_ban.html.erb
new file mode 100644
index 000000000..cf3f06834
--- /dev/null
+++ b/app/views/moderator/post/posts/confirm_ban.html.erb
@@ -0,0 +1,12 @@
+
Ban Post
+
+
+ <%= PostPresenter.preview(@post) %>
+
+
+<%= form_tag(ban_moderator_post_post_path(@post), :style => "clear: both;", :class => "simple_form") do %>
+ 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.
+
+ <%= submit_tag "Ban" %>
+ <%= submit_tag "Cancel" %>
+<% end %>
\ No newline at end of file
diff --git a/app/views/posts/partials/show/_information.html.erb b/app/views/posts/partials/show/_information.html.erb
index bf01f250f..0c15837e4 100644
--- a/app/views/posts/partials/show/_information.html.erb
+++ b/app/views/posts/partials/show/_information.html.erb
@@ -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 %>
diff --git a/app/views/posts/partials/show/_notices.html.erb b/app/views/posts/partials/show/_notices.html.erb
index 9067ac628..2da5be108 100644
--- a/app/views/posts/partials/show/_notices.html.erb
+++ b/app/views/posts/partials/show/_notices.html.erb
@@ -6,7 +6,7 @@
<% end %>
-<% if post.is_deleted? && post.flags.empty? %>
+<% if (post.is_banned? || post.is_deleted?) && post.flags.empty? %>
<% if post.is_banned? %>
This post was deleted because it was requested by the artist
diff --git a/app/views/posts/partials/show/_options.html.erb b/app/views/posts/partials/show/_options.html.erb
index 267a7c1c2..d39aeda4c 100644
--- a/app/views/posts/partials/show/_options.html.erb
+++ b/app/views/posts/partials/show/_options.html.erb
@@ -35,9 +35,9 @@
<% end %>
<% if post.is_banned? %>
-
<%= link_to "Unban", unban_post_path(post), :method => :post %>
+ <%= link_to "Unban", unban_moderator_post_post_path(post), :method => :post %>
<% else %>
- <%= link_to "Ban", ban_post_path(post), :method => :post %>
+ <%= link_to "Ban", confirm_ban_moderator_post_post_path(post) %>
<% end %>
<% if CurrentUser.is_admin? %>
diff --git a/config/routes.rb b/config/routes.rb
index fa4c5da95..1d0d41584 100644
--- a/config/routes.rb
+++ b/config/routes.rb
@@ -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]
diff --git a/db/seeds.rb b/db/seeds.rb
index 2007ef34c..fc53086df 100644
--- a/db/seeds.rb
+++ b/db/seeds.rb
@@ -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