From d79c906aa008b1d97a16250327dcd4be0e492125 Mon Sep 17 00:00:00 2001 From: r888888888 Date: Wed, 29 May 2013 16:26:00 -0700 Subject: [PATCH 1/9] fixes #1683 --- app/models/tag_implication.rb | 8 ++++---- test/unit/tag_implication_test.rb | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/app/models/tag_implication.rb b/app/models/tag_implication.rb index 865081b1a..7607526fd 100644 --- a/app/models/tag_implication.rb +++ b/app/models/tag_implication.rb @@ -104,9 +104,9 @@ class TagImplication < ActiveRecord::Base 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) + def update_posts_for_destroy(creator_id, creator_ip_addr, antecedent_name, consequent_name) + Post.tag_match("#{antecedent_name} #{consequent_name} status:any").find_each do |post| + escaped_tag_name = Regexp.escape(consequent_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( @@ -118,7 +118,7 @@ class TagImplication < ActiveRecord::Base end def update_posts_for_destroy - TagImplication.delay(:queue => "default").update_posts_for_destroy(CurrentUser.user.id, CurrentUser.ip_addr, consequent_name) + TagImplication.delay(:queue => "default").update_posts_for_destroy(CurrentUser.user.id, CurrentUser.ip_addr, antecedent_name, consequent_name) end end diff --git a/test/unit/tag_implication_test.rb b/test/unit/tag_implication_test.rb index f1418677b..da202f2a5 100644 --- a/test/unit/tag_implication_test.rb +++ b/test/unit/tag_implication_test.rb @@ -3,7 +3,7 @@ require 'test_helper' class TagImplicationTest < ActiveSupport::TestCase context "A tag implication" do setup do - user = FactoryGirl.create(:user) + user = FactoryGirl.create(:admin_user) CurrentUser.user = user CurrentUser.ip_addr = "127.0.0.1" @user = FactoryGirl.create(:user) From 92f4ea4b7d949077aabd7fe161b48e9d03e2cc78 Mon Sep 17 00:00:00 2001 From: r888888888 Date: Wed, 29 May 2013 16:28:49 -0700 Subject: [PATCH 2/9] fixes #1683 --- app/models/tag_implication.rb | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/app/models/tag_implication.rb b/app/models/tag_implication.rb index 7607526fd..d1f1f805e 100644 --- a/app/models/tag_implication.rb +++ b/app/models/tag_implication.rb @@ -105,10 +105,10 @@ class TagImplication < ActiveRecord::Base module ClassMethods def update_posts_for_destroy(creator_id, creator_ip_addr, antecedent_name, consequent_name) - Post.tag_match("#{antecedent_name} #{consequent_name} status:any").find_each do |post| - escaped_tag_name = Regexp.escape(consequent_name) - fixed_tags = post.tag_string.sub(/(?:\A| )#{escaped_tag_name}(?:\Z| )/, " ").strip - CurrentUser.scoped(User.find(creator_id), creator_ip_addr) do + CurrentUser.scoped(User.find(creator_id), creator_ip_addr) do + Post.tag_match("#{antecedent_name} #{consequent_name} status:any").find_each do |post| + escaped_tag_name = Regexp.escape(consequent_name) + fixed_tags = post.tag_string.sub(/(?:\A| )#{escaped_tag_name}(?:\Z| )/, " ").strip post.update_attributes( :tag_string => fixed_tags ) From 5efdc55d796293ed08e3707dfb45d2f5cd616043 Mon Sep 17 00:00:00 2001 From: r888888888 Date: Wed, 29 May 2013 16:31:46 -0700 Subject: [PATCH 3/9] fixes #1685 --- app/helpers/delayed_jobs_helper.rb | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/app/helpers/delayed_jobs_helper.rb b/app/helpers/delayed_jobs_helper.rb index 3667e228e..165673d84 100644 --- a/app/helpers/delayed_jobs_helper.rb +++ b/app/helpers/delayed_jobs_helper.rb @@ -2,31 +2,31 @@ module DelayedJobsHelper def print_handler(job) case job.name when "Class#expire_cache" - "expire post count cache: " + job.payload_object.args.flatten.join(" ") + "expire post count cache: " + h(job.payload_object.args.flatten.join(" ")) when "Upload#process!" 'upload post: record' when "Tag#update_related" - "update related tags: " + job.payload_object.name + "update related tags: " + h(job.payload_object.name) when "TagAlias#process!" - 'alias: ' + job.payload_object.antecedent_name + " -> " + job.payload_object.consequent_name + 'alias: ' + h(job.payload_object.antecedent_name) + " -> " + h(job.payload_object.consequent_name) when "TagImplication#process!" - 'implication: ' + job.payload_object.antecedent_name + " -> " + job.payload_object.consequent_name + 'implication: ' + h(job.payload_object.antecedent_name) + " -> " + h(job.payload_object.consequent_name) when "Class#clear_cache_for" - "expire tag alias cache: " + job.payload_object.args.flatten.join(" ") + "expire tag alias cache: " + h(job.payload_object.args.flatten.join(" ")) when "Tag#update_category_cache" - "update tag category cache: " + job.payload_object.name + "update tag category cache: " + h(job.payload_object.name) when "Tag#update_category_post_counts" - "update category post counts: " + job.payload_object.name + "update category post counts: " + h(job.payload_object.name) else - job.handler + h(job.handler) end end end From 2d0a3f5dcb6f867d4624a05491743f8612cbf222 Mon Sep 17 00:00:00 2001 From: r888888888 Date: Wed, 29 May 2013 16:34:21 -0700 Subject: [PATCH 4/9] update version --- config/danbooru_default_config.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/config/danbooru_default_config.rb b/config/danbooru_default_config.rb index b3c6e849f..7cd164f09 100644 --- a/config/danbooru_default_config.rb +++ b/config/danbooru_default_config.rb @@ -4,7 +4,7 @@ module Danbooru class Configuration # The version of this Danbooru. def version - "2.13.0" + "2.14.0" end # The name of this Danbooru. From 178035b8e259414b01a422caaf78f8833e0eaecd Mon Sep 17 00:00:00 2001 From: r888888888 Date: Wed, 29 May 2013 16:39:43 -0700 Subject: [PATCH 5/9] fixes #1679 --- app/logical/user_deletion.rb | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/app/logical/user_deletion.rb b/app/logical/user_deletion.rb index 87920bff4..f32093505 100644 --- a/app/logical/user_deletion.rb +++ b/app/logical/user_deletion.rb @@ -12,6 +12,7 @@ class UserDeletion validate clear_user_settings remove_favorites + clear_tag_subscriptions rename reset_password create_mod_action @@ -23,6 +24,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 From 074d1260183375d2cc212cdfb516e2408d77276e Mon Sep 17 00:00:00 2001 From: r888888888 Date: Wed, 29 May 2013 17:01:57 -0700 Subject: [PATCH 6/9] fixes #1694 --- app/models/tag_implication.rb | 24 ------------------------ test/unit/tag_implication_test.rb | 11 ----------- 2 files changed, 35 deletions(-) diff --git a/app/models/tag_implication.rb b/app/models/tag_implication.rb index d1f1f805e..414d14e34 100644 --- a/app/models/tag_implication.rb +++ b/app/models/tag_implication.rb @@ -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, antecedent_name, consequent_name) - CurrentUser.scoped(User.find(creator_id), creator_ip_addr) do - Post.tag_match("#{antecedent_name} #{consequent_name} status:any").find_each do |post| - escaped_tag_name = Regexp.escape(consequent_name) - fixed_tags = post.tag_string.sub(/(?:\A| )#{escaped_tag_name}(?:\Z| )/, " ").strip - 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, antecedent_name, consequent_name) - end - end - include DescendantMethods include ParentMethods extend SearchMethods - include DeletionMethods def initialize_creator self.creator_id = CurrentUser.user.id diff --git a/test/unit/tag_implication_test.rb b/test/unit/tag_implication_test.rb index da202f2a5..4ae1f708e 100644 --- a/test/unit/tag_implication_test.rb +++ b/test/unit/tag_implication_test.rb @@ -111,17 +111,6 @@ class TagImplicationTest < ActiveSupport::TestCase assert_equal("eee", ti4.descendant_names) end - should "update any affected post upon destroy" do - ti1 = FactoryGirl.create(:tag_implication, :antecedent_name => "aaa", :consequent_name => "bbb") - ti2 = FactoryGirl.create(:tag_implication, :antecedent_name => "bbb", :consequent_name => "ccc") - ti3 = FactoryGirl.create(:tag_implication, :antecedent_name => "ccc", :consequent_name => "ddd") - p1 = FactoryGirl.create(:post, :tag_string => "aaa") - assert_equal("aaa bbb ccc ddd", p1.tag_string) - ti2.destroy - p1.reload - assert_equal("aaa bbb ddd", p1.tag_string) - end - should "update any affected post upon save" do p1 = FactoryGirl.create(:post, :tag_string => "aaa bbb ccc") ti1 = FactoryGirl.create(:tag_implication, :antecedent_name => "aaa", :consequent_name => "xxx") From 537be266903ad0463490be8b46c0d70e56bf0dc1 Mon Sep 17 00:00:00 2001 From: r888888888 Date: Wed, 29 May 2013 17:24:51 -0700 Subject: [PATCH 7/9] when deleting users, make the favorites removal asynchronoous --- app/logical/user_deletion.rb | 11 ++++++++--- test/unit/user_deletion_test.rb | 4 ++++ 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/app/logical/user_deletion.rb b/app/logical/user_deletion.rb index f32093505..9dfffa4b1 100644 --- a/app/logical/user_deletion.rb +++ b/app/logical/user_deletion.rb @@ -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 @@ -49,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 diff --git a/test/unit/user_deletion_test.rb b/test/unit/user_deletion_test.rb index 3fd9b2bda..1a6db0811 100644 --- a/test/unit/user_deletion_test.rb +++ b/test/unit/user_deletion_test.rb @@ -4,6 +4,7 @@ class UserDeletionTest < ActiveSupport::TestCase context "an invalid user deletion" do context "for an invalid password" do setup do + Delayed::Worker.delay_jobs = false @user = FactoryGirl.create(:user) CurrentUser.user = @user CurrentUser.ip_addr = "127.0.0.1" @@ -19,6 +20,7 @@ class UserDeletionTest < ActiveSupport::TestCase context "for an admin" do setup do + Delayed::Worker.delay_jobs = false @user = FactoryGirl.create(:admin_user) CurrentUser.user = @user CurrentUser.ip_addr = "127.0.0.1" @@ -35,6 +37,8 @@ class UserDeletionTest < ActiveSupport::TestCase context "a valid user deletion" do setup do + Delayed::Worker.delay_jobs = false + @user = FactoryGirl.create(:user) CurrentUser.user = @user CurrentUser.ip_addr = "127.0.0.1" From 2e0d4dcae9706b5ed91861430b0c8d7e6a7c2f97 Mon Sep 17 00:00:00 2001 From: r888888888 Date: Wed, 29 May 2013 17:27:08 -0700 Subject: [PATCH 8/9] fixes #1688 --- app/models/post.rb | 1 - 1 file changed, 1 deletion(-) diff --git a/app/models/post.rb b/app/models/post.rb index 8b63b976c..8aa59f457 100644 --- a/app/models/post.rb +++ b/app/models/post.rb @@ -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] From 6ef50f7a7f17a99c0bfe7a431026c558fa524533 Mon Sep 17 00:00:00 2001 From: r888888888 Date: Wed, 29 May 2013 18:13:13 -0700 Subject: [PATCH 9/9] potential fix for #993 --- app/views/artist_versions/index.html.erb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/views/artist_versions/index.html.erb b/app/views/artist_versions/index.html.erb index c2e8aee25..478a0d71c 100644 --- a/app/views/artist_versions/index.html.erb +++ b/app/views/artist_versions/index.html.erb @@ -25,7 +25,7 @@ <%= link_to artist_version.name, artist_versions_path(:search => {:artist_id => artist_version.artist_id}) %> - <%= link_to "artist", artist_path(artist_version.artist) %> + <%= link_to "artist", artist_path(artist_version.artist_id) %> <%= artist_version_other_names_diff(artist_version) %> <%= artist_version.group_name %> <%= compact_time artist_version.created_at %>