mirror of
https://github.com/codeninjasllc/discourse.git
synced 2024-11-23 15:48:43 -05:00
If flagging a topic with only one post, flag the post instead
This commit is contained in:
parent
1a8ebb710e
commit
997a7c676e
2 changed files with 21 additions and 1 deletions
|
@ -124,13 +124,18 @@ class PostAction < ActiveRecord::Base
|
|||
|
||||
related_post_id = create_message_for_post_action(user,post,post_action_type_id,opts)
|
||||
|
||||
targets_topic = if opts[:flag_topic] and post.topic
|
||||
post.topic.reload
|
||||
post.topic.posts_count != 1
|
||||
end
|
||||
|
||||
create( post_id: post.id,
|
||||
user_id: user.id,
|
||||
post_action_type_id: post_action_type_id,
|
||||
message: opts[:message],
|
||||
staff_took_action: opts[:take_action] || false,
|
||||
related_post_id: related_post_id,
|
||||
targets_topic: !!opts[:flag_topic] )
|
||||
targets_topic: !!targets_topic )
|
||||
rescue ActiveRecord::RecordNotUnique
|
||||
# can happen despite being .create
|
||||
# since already bookmarked
|
||||
|
|
|
@ -269,6 +269,21 @@ describe PostAction do
|
|||
post.hidden.should be_true
|
||||
post.hidden_reason_id.should == Post.hidden_reasons[:flag_threshold_reached_again]
|
||||
end
|
||||
|
||||
it "can flag the topic instead of a post" do
|
||||
post1 = create_post
|
||||
post2 = create_post(topic: post1.topic)
|
||||
post_action = PostAction.act(Fabricate(:user), post1, PostActionType.types[:spam], {flag_topic: true})
|
||||
post_action.targets_topic.should == true
|
||||
end
|
||||
|
||||
it "will flag the first post if you flag a topic but there is only one post in the topic" do
|
||||
post = create_post
|
||||
post_action = PostAction.act(Fabricate(:user), post, PostActionType.types[:spam], {flag_topic: true})
|
||||
post_action.targets_topic.should == false
|
||||
post_action.post_id.should == post.id
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
it "prevents user to act twice at the same time" do
|
||||
|
|
Loading…
Reference in a new issue