aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--app/controllers/request_controller.rb2
-rw-r--r--app/models/user.rb10
-rw-r--r--app/views/user/rate_limited.rhtml6
3 files changed, 14 insertions, 4 deletions
diff --git a/app/controllers/request_controller.rb b/app/controllers/request_controller.rb
index 2295d6718..313a57d7d 100644
--- a/app/controllers/request_controller.rb
+++ b/app/controllers/request_controller.rb
@@ -220,6 +220,8 @@ class RequestController < ApplicationController
render :template => 'user/banned'
return
end
+ # User did exceed limit
+ @next_request_permitted_at = authenticated_user.next_request_permitted_at
end
# First time we get to the page, just display it
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
diff --git a/app/views/user/rate_limited.rhtml b/app/views/user/rate_limited.rhtml
index c1e8f360e..2a770d62e 100644
--- a/app/views/user/rate_limited.rhtml
+++ b/app/views/user/rate_limited.rhtml
@@ -2,11 +2,9 @@
<h1><%=@title%></h1>
-<p><%= _("There is a limit on the number of requests that you can make in any one day. You can make more requests tomorrow.")%></p>
+<p><%= _("You have hit the rate limit on new requests. Users are ordinarily limited to {{max_requests_per_user_per_day}} requests in any rolling 24-hour period. You will be able to make another request in {{can_make_another_request}}.", :max_requests_per_user_per_day => MySociety::Config.get("MAX_REQUESTS_PER_USER_PER_DAY"), :can_make_another_request => distance_of_time_in_words(Time.now, @next_request_permitted_at))%></p>
-<!-- Insert explanation of why we have a limit -->
-
-<p><%= _("If you need to make more requests than this, <a href='%s'>get in touch</a> and we’ll consider it.") % [help_contact_path] %></p>
+<p><%= _("There is a limit on the number of requests you can make in a day, because we don’t want public authorities to be bombarded with large numbers of inappropriate requests. If you feel you have a good reason to ask for the limit to be lifted in your case, please <a href='{{help_contact_path}}'>get in touch</a>.", :help_contact_path => help_contact_path) %></p>
<% if @info_request %>
<p><%= _("Here is the message you wrote, in case you would like to copy the text and save it for later.") %></p>