This commit is contained in:
r888888888
2013-07-25 14:32:15 -07:00
parent 303d6ce821
commit c4bf6a9192
6 changed files with 52 additions and 37 deletions

View File

@@ -46,6 +46,14 @@ class CurrentUser
Thread.current[:safe_mode] Thread.current[:safe_mode]
end end
def self.without_safe_mode
prev = Thread.current[:safe_mode]
Thread.current[:safe_mode] = false
yield
ensure
Thread.current[:safe_mode] = prev
end
def self.set_safe_mode(req) def self.set_safe_mode(req)
if req.host =~ /safe/ if req.host =~ /safe/
Thread.current[:safe_mode] = true Thread.current[:safe_mode] = true

View File

@@ -10,6 +10,7 @@ module Moderator
updater = User.find(updater_id) updater = User.find(updater_id)
CurrentUser.without_safe_mode do
CurrentUser.scoped(updater, updater_ip_addr) do CurrentUser.scoped(updater, updater_ip_addr) do
::Post.tag_match(antecedent).each do |post| ::Post.tag_match(antecedent).each do |post|
tags = (post.tag_array - normalized_antecedent + normalized_consequent).join(" ") tags = (post.tag_array - normalized_antecedent + normalized_consequent).join(" ")
@@ -19,3 +20,4 @@ module Moderator
end end
end end
end end
end

View File

@@ -114,7 +114,6 @@ class PostQueryBuilder
if CurrentUser.safe_mode? if CurrentUser.safe_mode?
relation = relation.where(:rating => "s") relation = relation.where(:rating => "s")
# relation = relation.where("created_at <= ?", 3.months.ago)
end end
relation = add_range_relation(q[:post_id], "posts.id", relation) relation = add_range_relation(q[:post_id], "posts.id", relation)

View File

@@ -182,6 +182,7 @@ class Artist < ActiveRecord::Base
module BanMethods module BanMethods
def ban! def ban!
Post.transaction do Post.transaction do
CurrentUser.without_safe_mode do
begin begin
Post.tag_match(name).each do |post| Post.tag_match(name).each do |post|
begin begin
@@ -205,6 +206,7 @@ class Artist < ActiveRecord::Base
end end
end end
end end
end
module SearchMethods module SearchMethods
def active def active

View File

@@ -126,6 +126,7 @@ class TagAlias < ActiveRecord::Base
end end
def update_posts def update_posts
CurrentUser.without_safe_mode do
Post.raw_tag_match(antecedent_name).find_each do |post| Post.raw_tag_match(antecedent_name).find_each do |post|
escaped_antecedent_name = Regexp.escape(antecedent_name) escaped_antecedent_name = Regexp.escape(antecedent_name)
fixed_tags = post.tag_string.sub(/(?:\A| )#{escaped_antecedent_name}(?:\Z| )/, " #{consequent_name} ").strip fixed_tags = post.tag_string.sub(/(?:\A| )#{escaped_antecedent_name}(?:\Z| )/, " #{consequent_name} ").strip
@@ -139,6 +140,7 @@ class TagAlias < ActiveRecord::Base
antecedent_tag.fix_post_count if antecedent_tag antecedent_tag.fix_post_count if antecedent_tag
consequent_tag.fix_post_count if consequent_tag consequent_tag.fix_post_count if consequent_tag
end end
end
def rename_wiki_and_artist def rename_wiki_and_artist
antecedent_wiki = WikiPage.titled(antecedent_name).first antecedent_wiki = WikiPage.titled(antecedent_name).first

View File

@@ -126,6 +126,7 @@ class TagImplication < ActiveRecord::Base
end end
def update_posts def update_posts
CurrentUser.without_safe_mode do
Post.raw_tag_match(antecedent_name).find_each do |post| Post.raw_tag_match(antecedent_name).find_each do |post|
fixed_tags = "#{post.tag_string} #{descendant_names}".strip fixed_tags = "#{post.tag_string} #{descendant_names}".strip
CurrentUser.scoped(creator, creator_ip_addr) do CurrentUser.scoped(creator, creator_ip_addr) do
@@ -135,6 +136,7 @@ class TagImplication < ActiveRecord::Base
end end
end end
end end
end
def normalize_names def normalize_names
self.antecedent_name = antecedent_name.downcase.tr(" ", "_") self.antecedent_name = antecedent_name.downcase.tr(" ", "_")