From 3811efa5e2da7d892ccb3057cd5aef95682e029d Mon Sep 17 00:00:00 2001 From: Robin Ward Date: Fri, 20 Jun 2014 15:03:02 -0400 Subject: [PATCH] Record when a post was hidden --- app/models/post_action.rb | 2 +- db/migrate/20140620184031_add_hidden_at_to_posts.rb | 5 +++++ lib/post_revisor.rb | 1 + spec/models/post_action_spec.rb | 7 +++++++ 4 files changed, 14 insertions(+), 1 deletion(-) create mode 100644 db/migrate/20140620184031_add_hidden_at_to_posts.rb diff --git a/app/models/post_action.rb b/app/models/post_action.rb index 86dcf78d81..ea49f3fe6f 100644 --- a/app/models/post_action.rb +++ b/app/models/post_action.rb @@ -307,7 +307,7 @@ class PostAction < ActiveRecord::Base reason = guess_hide_reason(old_flags) end - Post.where(id: post.id).update_all(["hidden = true, hidden_reason_id = COALESCE(hidden_reason_id, ?)", reason]) + Post.where(id: post.id).update_all(["hidden = true, hidden_at = CURRENT_TIMESTAMP, hidden_reason_id = COALESCE(hidden_reason_id, ?)", reason]) 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 }) diff --git a/db/migrate/20140620184031_add_hidden_at_to_posts.rb b/db/migrate/20140620184031_add_hidden_at_to_posts.rb new file mode 100644 index 0000000000..e22041be19 --- /dev/null +++ b/db/migrate/20140620184031_add_hidden_at_to_posts.rb @@ -0,0 +1,5 @@ +class AddHiddenAtToPosts < ActiveRecord::Migration + def change + add_column :posts, :hidden_at, :timestamp + end +end diff --git a/lib/post_revisor.rb b/lib/post_revisor.rb index 9bbd4444c1..dd3db0af10 100644 --- a/lib/post_revisor.rb +++ b/lib/post_revisor.rb @@ -100,6 +100,7 @@ class PostRevisor if @editor == @post.user && @post.hidden && @post.hidden_reason_id == Post.hidden_reasons[:flag_threshold_reached] @post.hidden = false @post.hidden_reason_id = nil + @post.hidden_at = nil @post.topic.update_attributes(visible: true) PostAction.clear_flags!(@post, -1) diff --git a/spec/models/post_action_spec.rb b/spec/models/post_action_spec.rb index 182963aa1a..d22e91931a 100644 --- a/spec/models/post_action_spec.rb +++ b/spec/models/post_action_spec.rb @@ -98,14 +98,17 @@ describe PostAction do admin = Fabricate(:admin) PostAction.act(codinghorror, post, PostActionType.types[:off_topic]) post.hidden.should be_false + post.hidden_at.should be_blank PostAction.defer_flags!(post, admin.id) PostAction.flagged_posts_count.should == 0 post.reload post.hidden.should be_false + post.hidden_at.should be_blank PostAction.hide_post!(post, PostActionType.types[:off_topic]) post.reload post.hidden.should be_true + post.hidden_at.should be_present end end @@ -253,6 +256,7 @@ describe PostAction do post.hidden.should.should be_true post.hidden_reason_id.should == Post.hidden_reasons[:flag_threshold_reached] + post.hidden_at.should be_present post.topic.visible.should be_false post.revise(post.user, post.raw + " ha I edited it ") @@ -260,6 +264,7 @@ describe PostAction do post.hidden.should be_false post.hidden_reason_id.should be_nil + post.hidden_at.should be_blank post.topic.visible.should be_true PostAction.act(u1, post, PostActionType.types[:spam]) @@ -269,12 +274,14 @@ describe PostAction do post.hidden.should be_true post.hidden_reason_id.should == Post.hidden_reasons[:flag_threshold_reached_again] + post.hidden_at.should be_true post.revise(post.user, post.raw + " ha I edited it again ") post.reload post.hidden.should be_true + post.hidden_at.should be_true post.hidden_reason_id.should == Post.hidden_reasons[:flag_threshold_reached_again] end