A platform for community discussion. Free, open, simple.
FIX: Allow user actions to be saved even if the post has nil user
David Taylorf0abb4d09ab0
diff --git a/app/models/post_action.rb b/app/models/post_action.rbindex bda0d9f2231..b20d0650c4b 100644--- a/app/models/post_action.rb+++ b/app/models/post_action.rb@@ -575,11 +575,11 @@ class PostAction < ActiveRecord::Basedef self.auto_hide_if_needed(acting_user, post, post_action_type)return if post.hidden?- return if (!acting_user.staff?) && post.user.staff?+ return if (!acting_user.staff?) && post.user&.staff?if post_action_type == :spam &&acting_user.has_trust_level?(TrustLevel[3]) &&- post.user.trust_level == TrustLevel[0]+ post.user&.trust_level == TrustLevel[0]hide_post!(post, post_action_type, Post.hidden_reasons[:flagged_by_tl3_user])diff --git a/spec/models/post_action_spec.rb b/spec/models/post_action_spec.rbindex e616bd1eb13..c8f5d50f24f 100644--- a/spec/models/post_action_spec.rb+++ b/spec/models/post_action_spec.rb@@ -477,6 +477,15 @@ describe PostAction doexpect(post.topic.visible).to eq(false)end+ it "doesn't fail when post has nil user" do+ post = create_post+ post.update!(user: nil)++ PostAction.act(codinghorror, post, PostActionType.types[:spam], take_action: true)+ post.reload+ expect(post.hidden).to eq(true)+ end+it "hide tl0 posts that are flagged as spam by a tl3 user" donewuser = Fabricate(:newuser)post = create_post(user: newuser)