Merge pull request #3063 from evazion/fix-post-delete

Fix flagging cooldown preventing manual deletions.
This commit is contained in:
Albert Yi
2017-05-18 13:44:27 -07:00
committed by GitHub
5 changed files with 39 additions and 33 deletions

View File

@@ -1355,7 +1355,7 @@ class Post < ActiveRecord::Base
end
ModAction.log("permanently deleted post ##{id}")
delete!(:without_mod_action => true)
delete!("Permanently deleted post ##{id}", :without_mod_action => true)
Post.without_timeout do
give_favorites_to_parent
update_children_on_destroy
@@ -1377,13 +1377,15 @@ class Post < ActiveRecord::Base
ModAction.log("unbanned post ##{id}")
end
def delete!(options = {})
def delete!(reason, options = {})
if is_status_locked?
self.errors.add(:is_status_locked, "; cannot delete post")
return false
end
Post.transaction do
flag!(reason, is_deletion: true)
self.is_deleted = true
self.is_pending = false
self.is_flagged = false
@@ -1398,11 +1400,7 @@ class Post < ActiveRecord::Base
update_parent_on_save
unless options[:without_mod_action]
if options[:reason]
ModAction.log("deleted post ##{id}, reason: #{options[:reason]}")
else
ModAction.log("deleted post ##{id}")
end
ModAction.log("deleted post ##{id}, reason: #{reason}")
end
end
end

View File

@@ -139,10 +139,10 @@ class PostFlag < ActiveRecord::Base
end
def validate_creator_is_not_limited
return if is_deletion
if CurrentUser.can_approve_posts?
# do nothing
elsif User.system.present? && CurrentUser.id == User.system.id
# do nothing
elsif creator.created_at > 1.week.ago
errors[:creator] << "cannot flag within the first week of sign up"
elsif creator.is_gold? && flag_count_for_creator >= 10
@@ -150,11 +150,6 @@ class PostFlag < ActiveRecord::Base
elsif !creator.is_gold? && flag_count_for_creator >= 1
errors[:creator] << "can flag 1 post a day"
end
end
def validate_post
errors[:post] << "is locked and cannot be flagged" if post.is_status_locked?
errors[:post] << "is deleted" if post.is_deleted?
flag = post.flags.in_cooldown.last
if flag.present?
@@ -162,6 +157,11 @@ class PostFlag < ActiveRecord::Base
end
end
def validate_post
errors[:post] << "is locked and cannot be flagged" if post.is_status_locked?
errors[:post] << "is deleted" if post.is_deleted?
end
def initialize_creator
self.creator_id ||= CurrentUser.id
self.creator_ip_addr ||= CurrentUser.ip_addr