diff options
Diffstat (limited to 'app')
-rw-r--r-- | app/controllers/request_controller.rb | 2 | ||||
-rw-r--r-- | app/controllers/track_controller.rb | 1 | ||||
-rw-r--r-- | app/models/incoming_message.rb | 6 | ||||
-rw-r--r-- | app/models/user.rb | 10 | ||||
-rw-r--r-- | app/views/user/rate_limited.rhtml | 6 |
5 files changed, 18 insertions, 7 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/controllers/track_controller.rb b/app/controllers/track_controller.rb index e39a0489d..d858ab233 100644 --- a/app/controllers/track_controller.rb +++ b/app/controllers/track_controller.rb @@ -66,6 +66,7 @@ class TrackController < ApplicationController # Track a user def track_user @track_user = User.find_by_url_name(params[:url_name]) + raise ActiveRecord::RecordNotFound.new("No such user") if @track_user.nil? @track_thing = TrackThing.create_track_for_user(@track_user) return atom_feed_internal if params[:feed] == 'feed' diff --git a/app/models/incoming_message.rb b/app/models/incoming_message.rb index 131970ba6..cbbcf5aa6 100644 --- a/app/models/incoming_message.rb +++ b/app/models/incoming_message.rb @@ -57,7 +57,7 @@ class IncomingMessage < ActiveRecord::Base validates_presence_of :raw_email has_many :outgoing_message_followups, :foreign_key => 'incoming_message_followup_id', :class_name => 'OutgoingMessage' - has_many :foi_attachments + has_many :foi_attachments, :order => 'id' has_many :info_request_events # never really has many, but could in theory belongs_to :raw_email @@ -773,12 +773,12 @@ class IncomingMessage < ActiveRecord::Base # which is really messy. ensure_parts_counted attachments = [] - for leaf in leaves + for leaf in leaves body = leaf.body # As leaf.body causes MIME decoding which uses lots of RAM, do garbage collection here # to prevent excess memory use. XXX not really sure if this helps reduce # peak RAM use overall. Anyway, maybe there is something better to do than this. - GC.start + GC.start if leaf.within_rfc822_attachment within_rfc822_subject = leaf.within_rfc822_attachment.subject # Test to see if we are in the first part of the attached 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> |