FIX: Allow user actions to be saved even if the post has nil user
This issue made it impossible to delete users if they had flagged a post with nil user
This commit is contained in:
parent
e6970151a6
commit
f0abb4d09a
|
@ -575,11 +575,11 @@ class PostAction < ActiveRecord::Base
|
|||
|
||||
def 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])
|
||||
|
||||
|
|
|
@ -477,6 +477,15 @@ describe PostAction do
|
|||
expect(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" do
|
||||
newuser = Fabricate(:newuser)
|
||||
post = create_post(user: newuser)
|
||||
|
|
Loading…
Reference in New Issue