This commit is contained in:
Toks
2013-05-30 15:14:16 -04:00
8 changed files with 27 additions and 50 deletions

View File

@@ -2,31 +2,31 @@ module DelayedJobsHelper
def print_handler(job)
case job.name
when "Class#expire_cache"
"<strong>expire post count cache</strong>: " + job.payload_object.args.flatten.join(" ")
"<strong>expire post count cache</strong>: " + h(job.payload_object.args.flatten.join(" "))
when "Upload#process!"
'<strong>upload post</strong>: <a href="/uploads/' + job.payload_object.object.id.to_s + '">record</a>'
when "Tag#update_related"
"<strong>update related tags</strong>: " + job.payload_object.name
"<strong>update related tags</strong>: " + h(job.payload_object.name)
when "TagAlias#process!"
'<strong>alias</strong>: ' + job.payload_object.antecedent_name + " -&gt; " + job.payload_object.consequent_name
'<strong>alias</strong>: ' + h(job.payload_object.antecedent_name) + " -&gt; " + h(job.payload_object.consequent_name)
when "TagImplication#process!"
'<strong>implication</strong>: ' + job.payload_object.antecedent_name + " -&gt; " + job.payload_object.consequent_name
'<strong>implication</strong>: ' + h(job.payload_object.antecedent_name) + " -&gt; " + h(job.payload_object.consequent_name)
when "Class#clear_cache_for"
"<strong>expire tag alias cache</strong>: " + job.payload_object.args.flatten.join(" ")
"<strong>expire tag alias cache</strong>: " + h(job.payload_object.args.flatten.join(" "))
when "Tag#update_category_cache"
"<strong>update tag category cache</strong>: " + job.payload_object.name
"<strong>update tag category cache</strong>: " + h(job.payload_object.name)
when "Tag#update_category_post_counts"
"<strong>update category post counts</strong>: " + job.payload_object.name
"<strong>update category post counts</strong>: " + h(job.payload_object.name)
else
job.handler
h(job.handler)
end
end
end

View File

@@ -3,6 +3,13 @@ class UserDeletion
attr_reader :user, :password
def self.remove_favorites_for(user_name, user_id)
user = User.find(user_id)
Post.tag_match("fav:#{user_name}").find_each do |post|
Favorite.remove(post, user)
end
end
def initialize(user, password)
@user = user
@password = password
@@ -12,6 +19,7 @@ class UserDeletion
validate
clear_user_settings
remove_favorites
clear_tag_subscriptions
rename
reset_password
create_mod_action
@@ -23,6 +31,9 @@ private
ModAction.create(:description => "user ##{user.id} deleted")
end
def clear_tag_subscriptions
TagSubscription.where(:creator_id => user.id).destroy_all
end
def clear_user_settings
user.email = nil
@@ -45,9 +56,7 @@ private
end
def remove_favorites
Post.tag_match("fav:#{user.name}").find_each do |post|
Favorite.remove(post, user)
end
UserDeletion.delay.remove_favorites_for(user.name, user.id)
end
def rename

View File

@@ -30,7 +30,6 @@ class Post < ActiveRecord::Base
has_many :children, :class_name => "Post", :foreign_key => "parent_id", :order => "posts.id"
has_many :disapprovals, :class_name => "PostDisapproval", :dependent => :destroy
validates_uniqueness_of :md5
validates_presence_of :parent, :if => lambda {|rec| !rec.parent_id.nil?}
validate :post_is_not_its_own_parent
attr_accessible :source, :rating, :tag_string, :old_tag_string, :last_noted_at, :parent_id, :as => [:member, :builder, :gold, :platinum, :contributor, :janitor, :moderator, :admin, :default]
attr_accessible :is_rating_locked, :is_note_locked, :as => [:builder, :contributor, :janitor, :moderator, :admin]

View File

@@ -2,7 +2,6 @@ class TagImplication < ActiveRecord::Base
before_save :update_descendant_names
after_save :update_descendant_names_for_parent
after_destroy :update_descendant_names_for_parent
after_destroy :update_posts_for_destroy
belongs_to :creator, :class_name => "User"
before_validation :initialize_creator, :on => :create
before_validation :normalize_names
@@ -100,32 +99,9 @@ class TagImplication < ActiveRecord::Base
end
end
module DeletionMethods
extend ActiveSupport::Concern
module ClassMethods
def update_posts_for_destroy(creator_id, creator_ip_addr, tag_name)
Post.tag_match("#{tag_name} status:any").find_each do |post|
escaped_tag_name = Regexp.escape(tag_name)
fixed_tags = post.tag_string.sub(/(?:\A| )#{escaped_tag_name}(?:\Z| )/, " ").strip
CurrentUser.scoped(User.find(creator_id), creator_ip_addr) do
post.update_attributes(
:tag_string => fixed_tags
)
end
end
end
end
def update_posts_for_destroy
TagImplication.delay(:queue => "default").update_posts_for_destroy(CurrentUser.user.id, CurrentUser.ip_addr, consequent_name)
end
end
include DescendantMethods
include ParentMethods
extend SearchMethods
include DeletionMethods
def initialize_creator
self.creator_id = CurrentUser.user.id

View File

@@ -25,7 +25,7 @@
<td>
<%= link_to artist_version.name, artist_versions_path(:search => {:artist_id => artist_version.artist_id}) %>
</td>
<td><%= link_to "artist", artist_path(artist_version.artist) %></td>
<td><%= link_to "artist", artist_path(artist_version.artist_id) %></td>
<td><%= artist_version_other_names_diff(artist_version) %></td>
<td><%= artist_version.group_name %></td>
<td><%= compact_time artist_version.created_at %></td>