fixes for #1865
This commit is contained in:
@@ -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
|
||||||
|
|||||||
@@ -10,10 +10,12 @@ module Moderator
|
|||||||
|
|
||||||
updater = User.find(updater_id)
|
updater = User.find(updater_id)
|
||||||
|
|
||||||
CurrentUser.scoped(updater, updater_ip_addr) do
|
CurrentUser.without_safe_mode do
|
||||||
::Post.tag_match(antecedent).each do |post|
|
CurrentUser.scoped(updater, updater_ip_addr) do
|
||||||
tags = (post.tag_array - normalized_antecedent + normalized_consequent).join(" ")
|
::Post.tag_match(antecedent).each do |post|
|
||||||
post.update_attributes(:tag_string => tags)
|
tags = (post.tag_array - normalized_antecedent + normalized_consequent).join(" ")
|
||||||
|
post.update_attributes(:tag_string => tags)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -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)
|
||||||
|
|||||||
@@ -182,26 +182,28 @@ class Artist < ActiveRecord::Base
|
|||||||
module BanMethods
|
module BanMethods
|
||||||
def ban!
|
def ban!
|
||||||
Post.transaction do
|
Post.transaction do
|
||||||
begin
|
CurrentUser.without_safe_mode do
|
||||||
Post.tag_match(name).each do |post|
|
begin
|
||||||
begin
|
Post.tag_match(name).each do |post|
|
||||||
post.flag!("Artist requested removal")
|
begin
|
||||||
rescue PostFlag::Error
|
post.flag!("Artist requested removal")
|
||||||
# swallow
|
rescue PostFlag::Error
|
||||||
|
# swallow
|
||||||
|
end
|
||||||
|
post.delete!(:ban => true)
|
||||||
end
|
end
|
||||||
post.delete!(:ban => true)
|
rescue Post::SearchError
|
||||||
|
# swallow
|
||||||
end
|
end
|
||||||
rescue Post::SearchError
|
|
||||||
# swallow
|
|
||||||
end
|
|
||||||
|
|
||||||
# potential race condition but unlikely
|
# potential race condition but unlikely
|
||||||
unless TagImplication.where(:antecedent_name => name, :consequent_name => "banned_artist").exists?
|
unless TagImplication.where(:antecedent_name => name, :consequent_name => "banned_artist").exists?
|
||||||
tag_implication = TagImplication.create(:antecedent_name => name, :consequent_name => "banned_artist")
|
tag_implication = TagImplication.create(:antecedent_name => name, :consequent_name => "banned_artist")
|
||||||
tag_implication.delay(:queue => "default").process!
|
tag_implication.delay(:queue => "default").process!
|
||||||
end
|
end
|
||||||
|
|
||||||
update_column(:is_banned, true)
|
update_column(:is_banned, true)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -126,18 +126,20 @@ class TagAlias < ActiveRecord::Base
|
|||||||
end
|
end
|
||||||
|
|
||||||
def update_posts
|
def update_posts
|
||||||
Post.raw_tag_match(antecedent_name).find_each do |post|
|
CurrentUser.without_safe_mode do
|
||||||
escaped_antecedent_name = Regexp.escape(antecedent_name)
|
Post.raw_tag_match(antecedent_name).find_each do |post|
|
||||||
fixed_tags = post.tag_string.sub(/(?:\A| )#{escaped_antecedent_name}(?:\Z| )/, " #{consequent_name} ").strip
|
escaped_antecedent_name = Regexp.escape(antecedent_name)
|
||||||
CurrentUser.scoped(creator, creator_ip_addr) do
|
fixed_tags = post.tag_string.sub(/(?:\A| )#{escaped_antecedent_name}(?:\Z| )/, " #{consequent_name} ").strip
|
||||||
post.update_attributes(
|
CurrentUser.scoped(creator, creator_ip_addr) do
|
||||||
:tag_string => fixed_tags
|
post.update_attributes(
|
||||||
)
|
:tag_string => fixed_tags
|
||||||
|
)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
|
||||||
|
|
||||||
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
|
||||||
|
|||||||
@@ -126,12 +126,14 @@ class TagImplication < ActiveRecord::Base
|
|||||||
end
|
end
|
||||||
|
|
||||||
def update_posts
|
def update_posts
|
||||||
Post.raw_tag_match(antecedent_name).find_each do |post|
|
CurrentUser.without_safe_mode do
|
||||||
fixed_tags = "#{post.tag_string} #{descendant_names}".strip
|
Post.raw_tag_match(antecedent_name).find_each do |post|
|
||||||
CurrentUser.scoped(creator, creator_ip_addr) do
|
fixed_tags = "#{post.tag_string} #{descendant_names}".strip
|
||||||
post.update_attributes(
|
CurrentUser.scoped(creator, creator_ip_addr) do
|
||||||
:tag_string => fixed_tags
|
post.update_attributes(
|
||||||
)
|
:tag_string => fixed_tags
|
||||||
|
)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
Reference in New Issue
Block a user