diff options
author | Robin Houston <robin.houston@gmail.com> | 2012-02-05 13:50:45 +0000 |
---|---|---|
committer | Robin Houston <robin.houston@gmail.com> | 2012-02-05 13:50:45 +0000 |
commit | 11782f45795dc8f57e5ca9666e8325976541120e (patch) | |
tree | ef17e09de87497e217b2aa3f9d89c53d1fdb81c6 /app/models/user.rb | |
parent | d64f9e16f43c3652ec281be3d2d99bb3508b6044 (diff) |
Change wording of rate-limited page
Include information about what the per-day limit is, and when the
user can next make a request. Fixes #412.
Diffstat (limited to 'app/models/user.rb')
-rw-r--r-- | app/models/user.rb | 10 |
1 files changed, 10 insertions, 0 deletions
diff --git a/app/models/user.rb b/app/models/user.rb index 8c4b35fe6..28d130c46 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -288,6 +288,16 @@ class User < ActiveRecord::Base return (recent_requests >= daily_limit) end + def next_request_permitted_at + return nil if self.no_limit + + daily_limit = MySociety::Config.get("MAX_REQUESTS_PER_USER_PER_DAY") + n_most_recent_requests = InfoRequest.all(:conditions => ["user_id = ? and created_at > now() - '1 day'::interval", self.id], :order => "created_at DESC", :limit => daily_limit) + return nil if n_most_recent_requests.size < daily_limit + + nth_most_recent_request = n_most_recent_requests[-1] + return nth_most_recent_request.created_at + 1.day + end def can_make_followup? self.ban_text.empty? end |