From f587724476ffecb2ef01e93d826ba9d2b5ea7785 Mon Sep 17 00:00:00 2001 From: albert Date: Mon, 3 Oct 2011 18:54:01 -0400 Subject: [PATCH] fixes #101: comment limitations --- app/models/comment.rb | 7 ++++++- app/models/user.rb | 4 ++-- test/unit/comment_test.rb | 1 + 3 files changed, 9 insertions(+), 3 deletions(-) diff --git a/app/models/comment.rb b/app/models/comment.rb index b99567311..78a4cb7c2 100644 --- a/app/models/comment.rb +++ b/app/models/comment.rb @@ -28,7 +28,12 @@ class Comment < ActiveRecord::Base end def validate_creator_is_not_limited - creator.is_privileged? || Comment.where("creator_id = ? AND created_at >= ?", creator_id, 1.hour.ago).count < 5 + if creator.can_comment? + true + else + errors.add(:creator, "can not post comments within 1 week of sign up, and can only post #{Danbooru.config.member_comment_limit} comments per hour after that") + false + end end def update_last_commented_at diff --git a/app/models/user.rb b/app/models/user.rb index 5419ccd98..aaf818275 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -282,7 +282,7 @@ class User < ActiveRecord::Base def can_upload? if is_contributor? true - elsif created_at > 1.second.ago + elsif false && created_at > 1.week.ago false else upload_limit > 0 @@ -292,7 +292,7 @@ class User < ActiveRecord::Base def can_comment? if is_privileged? true - elsif created_at > 1.week.ago + elsif false && created_at > 1.week.ago false else Comment.where("creator_id = ? and created_at > ?", id, 1.hour.ago).count < Danbooru.config.member_comment_limit diff --git a/test/unit/comment_test.rb b/test/unit/comment_test.rb index 52de77aa9..40fe772fd 100644 --- a/test/unit/comment_test.rb +++ b/test/unit/comment_test.rb @@ -7,6 +7,7 @@ class CommentTest < ActiveSupport::TestCase CurrentUser.user = user CurrentUser.ip_addr = "127.0.0.1" MEMCACHE.flush_all + Danbooru.config.stubs(:member_comment_limit).returns(100) end teardown do