Don't employ the "too many replies" if the user is staff, or if they created the topic.

See: http://meta.discourse.org/t/what-is-the-point-of-limiting-new-users-to-three-replies-per-topic/11696
This commit is contained in:
Robin Ward 2014-01-02 12:57:40 -05:00
parent aefad6ae85
commit f145060315
2 changed files with 34 additions and 0 deletions

View file

@ -354,6 +354,10 @@ class User < ActiveRecord::Base
end
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?
trust_level == TrustLevel.levels[:newuser] && (Post.where(topic_id: topic_id, user_id: id).count >= SiteSetting.newuser_max_replies_per_topic)
end

View file

@ -903,6 +903,36 @@ describe User do
end
describe "posted too much in topic" do
let!(:user) { Fabricate(:user, trust_level: TrustLevel.levels[:newuser]) }
let!(:topic) { Fabricate(:post).topic }
before do
# To make testing easier, say 1 reply is too much
SiteSetting.stubs(:newuser_max_replies_per_topic).returns(1)
end
context "for a user who didn't create the topic" do
let!(:post) { Fabricate(:post, topic: topic, user: user) }
it "does not return true for staff" do
user.stubs(:staff?).returns(true)
user.posted_too_much_in_topic?(topic.id).should be_false
end
it "returns true when the user has posted too much" do
user.posted_too_much_in_topic?(topic.id).should be_true
end
end
it "returns false for a user who created the topic" do
topic_user = topic.user
topic_user.trust_level = TrustLevel.levels[:newuser]
topic.user.posted_too_much_in_topic?(topic.id).should be_false
end
end
describe "#find_email" do
let(:user) { Fabricate(:user, email: "bob@example.com") }