From a5f1a6bad1ce058861c703fbfcf5add856c34229 Mon Sep 17 00:00:00 2001 From: Toks Date: Tue, 2 Apr 2013 13:31:57 -0400 Subject: [PATCH] better comment creation errors --- app/logical/anonymous_user.rb | 4 ++++ app/models/comment.rb | 7 +++++-- app/models/user.rb | 10 ++++++++-- 3 files changed, 17 insertions(+), 4 deletions(-) diff --git a/app/logical/anonymous_user.rb b/app/logical/anonymous_user.rb index eafd3f2fe..057337633 100644 --- a/app/logical/anonymous_user.rb +++ b/app/logical/anonymous_user.rb @@ -96,6 +96,10 @@ class AnonymousUser false end + def is_comment_limited? + true + end + def can_remove_from_pools? false end diff --git a/app/models/comment.rb b/app/models/comment.rb index 6c4fd6faa..295104869 100644 --- a/app/models/comment.rb +++ b/app/models/comment.rb @@ -86,10 +86,13 @@ class Comment < ActiveRecord::Base end def validate_creator_is_not_limited - if creator.can_comment? + if creator.is_comment_limited? + errors.add(:base, "You can only post #{Danbooru.config.member_comment_limit} comments per hour") + false + elsif 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") + errors.add(:base, "You can not post comments within 1 week of sign up") false end end diff --git a/app/models/user.rb b/app/models/user.rb index 239c93004..3cbb9c694 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -424,10 +424,16 @@ class User < ActiveRecord::Base def can_comment? if is_privileged? true - elsif created_at > Danbooru.config.member_comment_time_threshold + else + created_at <= Danbooru.config.member_comment_time_threshold + end + end + + def is_comment_limited? + if is_privileged? false else - Comment.where("creator_id = ? and created_at > ?", id, 1.hour.ago).count < Danbooru.config.member_comment_limit + Comment.where("creator_id = ? and created_at > ?", id, 1.hour.ago).count >= Danbooru.config.member_comment_limit end end