Merge branch 'master' of https://github.com/r888888888/danbooru
This commit is contained in:
@@ -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 + " -> " + job.payload_object.consequent_name
|
||||
'<strong>alias</strong>: ' + h(job.payload_object.antecedent_name) + " -> " + h(job.payload_object.consequent_name)
|
||||
|
||||
when "TagImplication#process!"
|
||||
'<strong>implication</strong>: ' + job.payload_object.antecedent_name + " -> " + job.payload_object.consequent_name
|
||||
'<strong>implication</strong>: ' + h(job.payload_object.antecedent_name) + " -> " + 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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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]
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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>
|
||||
|
||||
@@ -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.
|
||||
|
||||
@@ -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)
|
||||
@@ -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")
|
||||
|
||||
@@ -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"
|
||||
|
||||
Reference in New Issue
Block a user