diff options
Diffstat (limited to 'app/models')
-rw-r--r-- | app/models/incoming_message.rb | 6 | ||||
-rw-r--r-- | app/models/user.rb | 23 |
2 files changed, 25 insertions, 4 deletions
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..59a84b7aa 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -61,7 +61,8 @@ class User < ActiveRecord::Base :values => [ [ :created_at_numeric, 1, "created_at", :number ] # for sorting ], - :terms => [ [ :variety, 'V', "variety" ] ] + :terms => [ [ :variety, 'V', "variety" ] ], + :if => :indexed_by_search? def created_at_numeric # format it here as no datetime support in Xapian's value ranges return self.created_at.strftime("%Y%m%d%H%M%S") @@ -264,6 +265,12 @@ class User < ActiveRecord::Base def User.view_hidden_requests?(user) !user.nil? && user.admin_level == 'super' end + + # Should the user be kept logged into their own account + # if they follow a /c/ redirect link belonging to another user? + def User.stay_logged_in_on_redirect?(user) + !user.nil? && user.admin_level == 'super' + end # Does the user get "(admin)" links on each page on the main site? def admin_page_links? @@ -288,6 +295,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 @@ -378,6 +395,10 @@ class User < ActiveRecord::Base def should_be_emailed? return (self.email_confirmed && self.email_bounced_at.nil?) end + + def indexed_by_search? + return self.email_confirmed + end ## Private instance methods private |