FIX: hidden posts that are edited by the author and unhidden could not be flagged by the same users again

This commit is contained in:
Neil Lalonde 2015-12-29 16:59:26 -05:00
parent c064dc1322
commit 007326d3bd
5 changed files with 18 additions and 13 deletions

View file

@ -346,7 +346,7 @@ class Post < ActiveRecord::Base
end
def unhide!
self.update_attributes(hidden: false, hidden_at: nil, hidden_reason_id: nil)
self.update_attributes(hidden: false)
self.topic.update_attributes(visible: true) if is_first_post?
save(validate: false)
publish_change_to_clients!(:acted)

View file

@ -483,7 +483,7 @@ SQL
old_flags, new_flags = PostAction.flag_counts_for(post.id)
if new_flags >= SiteSetting.flags_required_to_hide_post
hide_post!(post, post_action_type, guess_hide_reason(old_flags))
hide_post!(post, post_action_type, guess_hide_reason(post))
end
end
end
@ -492,11 +492,14 @@ SQL
return if post.hidden
unless reason
old_flags,_ = PostAction.flag_counts_for(post.id)
reason = guess_hide_reason(old_flags)
reason = guess_hide_reason(post)
end
Post.where(id: post.id).update_all(["hidden = true, hidden_at = ?, hidden_reason_id = COALESCE(hidden_reason_id, ?)", Time.now, reason])
post.hidden = true
post.hidden_at = Time.zone.now
post.hidden_reason_id = reason
post.save
Topic.where("id = :topic_id AND NOT EXISTS(SELECT 1 FROM POSTS WHERE topic_id = :topic_id AND NOT hidden)", topic_id: post.topic_id).update_all(visible: false)
# inform user
@ -510,8 +513,8 @@ SQL
end
end
def self.guess_hide_reason(old_flags)
old_flags > 0 ?
def self.guess_hide_reason(post)
post.hidden_at ?
Post.hidden_reasons[:flag_threshold_reached_again] :
Post.hidden_reasons[:flag_threshold_reached]
end

View file

@ -5,7 +5,7 @@
class PostDestroyer
def self.destroy_old_hidden_posts
Post.where(deleted_at: nil)
Post.where(deleted_at: nil, hidden: true)
.where("hidden_at < ?", 30.days.ago)
.find_each do |post|
PostDestroyer.new(Discourse.system_user, post).destroy

View file

@ -232,7 +232,7 @@ class PostRevisor
@post.word_count = @fields[:raw].scan(/\w+/).size if @fields.has_key?(:raw)
@post.self_edits += 1 if self_edit?
clear_flags_and_unhide_post
remove_flags_and_unhide_post
@post.extract_quoted_post_numbers
@ -269,9 +269,11 @@ class PostRevisor
@editor == @post.user
end
def clear_flags_and_unhide_post
def remove_flags_and_unhide_post
return unless editing_a_flagged_and_hidden_post?
PostAction.clear_flags!(@post, Discourse.system_user)
@post.post_actions.where(post_action_type_id: PostActionType.flag_types.values).each do |action|
action.remove_act!(Discourse.system_user)
end
@post.unhide!
end

View file

@ -345,8 +345,8 @@ describe PostAction do
post.reload
expect(post.hidden).to eq(false)
expect(post.hidden_reason_id).to eq(nil)
expect(post.hidden_at).to be_blank
expect(post.hidden_reason_id).to eq(Post.hidden_reasons[:flag_threshold_reached]) # keep most recent reason
expect(post.hidden_at).to be_present # keep the most recent hidden_at time
expect(post.topic.visible).to eq(true)
PostAction.act(eviltrout, post, PostActionType.types[:spam])