If a new user receives a mention, quote or response to their post, allow

them to continue posting in a topic.
This commit is contained in:
Robin Ward 2014-04-29 12:59:14 -04:00
parent 23ed5e0851
commit 359d59242e
3 changed files with 24 additions and 3 deletions

View File

@ -386,10 +386,16 @@ class User < ActiveRecord::Base
def posted_too_much_in_topic?(topic_id)
# Does not apply to staff or your own topics
return false if staff? || Topic.where(id: topic_id, user_id: id).exists?
# Does not apply to staff, non-new members or your own topics
return false if staff? ||
(trust_level != TrustLevel.levels[:newuser]) ||
Topic.where(id: topic_id, user_id: id).exists?
trust_level == TrustLevel.levels[:newuser] && (Post.where(topic_id: topic_id, user_id: id).count >= SiteSetting.newuser_max_replies_per_topic)
last_action_in_topic = UserAction.last_action_in_topic(id, topic_id)
since_reply = Post.where(user_id: id, topic_id: topic_id)
since_reply = since_reply.where('id > ?', last_action_in_topic) if last_action_in_topic
(since_reply.count >= SiteSetting.newuser_max_replies_per_topic)
end
def bio_excerpt

View File

@ -41,6 +41,11 @@ class UserAction < ActiveRecord::Base
include ActiveModel::SerializerSupport
end
def self.last_action_in_topic(user_id, topic_id)
UserAction.where(user_id: user_id,
target_topic_id: topic_id,
action_type: [RESPONSE, MENTION, QUOTE]).order('created_at DESC').pluck(:target_post_id).first
end
def self.stats(user_id, guardian)

View File

@ -935,6 +935,16 @@ describe User do
it "returns true when the user has posted too much" do
user.posted_too_much_in_topic?(topic.id).should be_true
end
context "with a reply" do
before do
PostCreator.new(Fabricate(:user), raw: 'whatever this is a raw post', topic_id: topic.id, reply_to_post_number: post.post_number).create
end
it "resets the `posted_too_much` threshold" do
user.posted_too_much_in_topic?(topic.id).should be_false
end
end
end
it "returns false for a user who created the topic" do