mirror of
https://github.com/discourse/discourse.git
synced 2024-11-26 02:40:53 -06:00
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:
parent
23ed5e0851
commit
359d59242e
@ -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
|
||||
|
@ -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)
|
||||
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user