diff options
Diffstat (limited to 'app/models')
-rw-r--r-- | app/models/contact_validator.rb | 4 | ||||
-rw-r--r-- | app/models/incoming_message.rb | 23 | ||||
-rw-r--r-- | app/models/info_request.rb | 4 | ||||
-rw-r--r-- | app/models/info_request_event.rb | 15 | ||||
-rw-r--r-- | app/models/outgoing_message.rb | 4 | ||||
-rw-r--r-- | app/models/post_redirect.rb | 4 | ||||
-rw-r--r-- | app/models/public_body.rb | 4 | ||||
-rw-r--r-- | app/models/public_body_tag.rb | 4 | ||||
-rw-r--r-- | app/models/track_mailer.rb | 10 | ||||
-rw-r--r-- | app/models/track_thing.rb | 30 | ||||
-rw-r--r-- | app/models/track_things_sent_email.rb | 4 | ||||
-rw-r--r-- | app/models/user.rb | 4 | ||||
-rw-r--r-- | app/models/user_info_request_sent_alert.rb | 4 |
13 files changed, 72 insertions, 42 deletions
diff --git a/app/models/contact_validator.rb b/app/models/contact_validator.rb index 2738c9571..1e88fa8a7 100644 --- a/app/models/contact_validator.rb +++ b/app/models/contact_validator.rb @@ -1,5 +1,5 @@ # == Schema Information -# Schema version: 55 +# Schema version: 56 # # Table name: contact_validators # @@ -15,7 +15,7 @@ # Copyright (c) 2008 UK Citizens Online Democracy. All rights reserved. # Email: francis@mysociety.org; WWW: http://www.mysociety.org/ # -# $Id: contact_validator.rb,v 1.14 2008-05-19 12:01:22 francis Exp $ +# $Id: contact_validator.rb,v 1.15 2008-05-21 10:51:24 francis Exp $ class ContactValidator < ActiveRecord::BaseWithoutTable column :name, :string diff --git a/app/models/incoming_message.rb b/app/models/incoming_message.rb index 5d3c15f49..d4bc322f5 100644 --- a/app/models/incoming_message.rb +++ b/app/models/incoming_message.rb @@ -1,13 +1,14 @@ # == Schema Information -# Schema version: 55 +# Schema version: 56 # # Table name: incoming_messages # -# id :integer not null, primary key -# info_request_id :integer not null -# raw_data :text not null -# created_at :datetime not null -# updated_at :datetime not null +# id :integer not null, primary key +# info_request_id :integer not null +# raw_data :text not null +# created_at :datetime not null +# updated_at :datetime not null +# cached_attachment_text :text # # models/incoming_message.rb: @@ -17,7 +18,7 @@ # Copyright (c) 2007 UK Citizens Online Democracy. All rights reserved. # Email: francis@mysociety.org; WWW: http://www.mysociety.org/ # -# $Id: incoming_message.rb,v 1.102 2008-05-19 13:54:39 francis Exp $ +# $Id: incoming_message.rb,v 1.103 2008-05-21 10:51:24 francis Exp $ # TODO # Move some of the (e.g. quoting) functions here into rblib, as they feel @@ -566,6 +567,14 @@ text = IncomingMessage.mask_string_multicharset(text, 'request-144-a724c835@what # Returns text version of attachment text def get_attachment_text + if self.cached_attachment_text.nil? + attachment_text = self.get_attachment_text_internal + self.cached_attachment_text = attachment_text + self.save! + end + return self.cached_attachment_text + end + def get_attachment_text_internal text = '' attachments = self.get_attachments_for_display for attachment in attachments diff --git a/app/models/info_request.rb b/app/models/info_request.rb index 1f30c3cbb..ece806009 100644 --- a/app/models/info_request.rb +++ b/app/models/info_request.rb @@ -1,5 +1,5 @@ # == Schema Information -# Schema version: 55 +# Schema version: 56 # # Table name: info_requests # @@ -22,7 +22,7 @@ # Copyright (c) 2007 UK Citizens Online Democracy. All rights reserved. # Email: francis@mysociety.org; WWW: http://www.mysociety.org/ # -# $Id: info_request.rb,v 1.112 2008-05-19 12:01:22 francis Exp $ +# $Id: info_request.rb,v 1.113 2008-05-21 10:51:24 francis Exp $ require 'digest/sha1' require File.join(File.dirname(__FILE__),'../../vendor/plugins/acts_as_xapian/lib/acts_as_xapian') diff --git a/app/models/info_request_event.rb b/app/models/info_request_event.rb index 3926780c7..dfb930358 100644 --- a/app/models/info_request_event.rb +++ b/app/models/info_request_event.rb @@ -1,5 +1,5 @@ # == Schema Information -# Schema version: 55 +# Schema version: 56 # # Table name: info_request_events # @@ -20,7 +20,7 @@ # Copyright (c) 2007 UK Citizens Online Democracy. All rights reserved. # Email: francis@mysociety.org; WWW: http://www.mysociety.org/ # -# $Id: info_request_event.rb,v 1.45 2008-05-19 21:28:07 francis Exp $ +# $Id: info_request_event.rb,v 1.46 2008-05-21 10:51:24 francis Exp $ class InfoRequestEvent < ActiveRecord::Base belongs_to :info_request @@ -59,7 +59,7 @@ class InfoRequestEvent < ActiveRecord::Base # Full text search indexing acts_as_xapian :texts => [ :search_text_main, :title ], :values => [ [ :created_at, 0, "created_at", :date ], - [ :rss_at, 1, "rss_at", :number ], # XXX using number for lack of :datetime support in Xapian + [ :described_at_numeric, 1, "described_at", :number ], # XXX using :number for lack of :datetime support in Xapian values [ :request, 2, "request_collapse", :string ] ], :terms => [ [ :calculated_state, 'S', "status" ], @@ -79,13 +79,16 @@ class InfoRequestEvent < ActiveRecord::Base def request self.info_request.url_title end - def rss_at + def described_at # For responses, people might have RSS feeds on searches for type of # response (e.g. successful) in which case we want to date sort by # when the responses was described as being of the type. For other # types, just use the create at date. - date = self.last_described_at || self.created_at - return date.strftime("%Y%m%d%H%M%S") # format it here as no datetime support in Xapian's value ranges + return self.last_described_at || self.created_at + end + def described_at_numeric + # format it here as no datetime support in Xapian's value ranges + return self.described_at.strftime("%Y%m%d%H%M%S") end def search_text_main text = '' diff --git a/app/models/outgoing_message.rb b/app/models/outgoing_message.rb index cf906a1a1..75477706e 100644 --- a/app/models/outgoing_message.rb +++ b/app/models/outgoing_message.rb @@ -1,5 +1,5 @@ # == Schema Information -# Schema version: 55 +# Schema version: 56 # # Table name: outgoing_messages # @@ -21,7 +21,7 @@ # Copyright (c) 2007 UK Citizens Online Democracy. All rights reserved. # Email: francis@mysociety.org; WWW: http://www.mysociety.org/ # -# $Id: outgoing_message.rb,v 1.49 2008-05-19 12:01:22 francis Exp $ +# $Id: outgoing_message.rb,v 1.50 2008-05-21 10:51:24 francis Exp $ class OutgoingMessage < ActiveRecord::Base belongs_to :info_request diff --git a/app/models/post_redirect.rb b/app/models/post_redirect.rb index 5f732e36a..a2e94836f 100644 --- a/app/models/post_redirect.rb +++ b/app/models/post_redirect.rb @@ -1,5 +1,5 @@ # == Schema Information -# Schema version: 55 +# Schema version: 56 # # Table name: post_redirects # @@ -26,7 +26,7 @@ # Copyright (c) 2007 UK Citizens Online Democracy. All rights reserved. # Email: francis@mysociety.org; WWW: http://www.mysociety.org/ # -# $Id: post_redirect.rb,v 1.32 2008-05-19 12:01:22 francis Exp $ +# $Id: post_redirect.rb,v 1.33 2008-05-21 10:51:24 francis Exp $ require 'openssl' # for random bytes function diff --git a/app/models/public_body.rb b/app/models/public_body.rb index e5f5cd667..03e74f2b7 100644 --- a/app/models/public_body.rb +++ b/app/models/public_body.rb @@ -1,5 +1,5 @@ # == Schema Information -# Schema version: 55 +# Schema version: 56 # # Table name: public_bodies # @@ -21,7 +21,7 @@ # Copyright (c) 2007 UK Citizens Online Democracy. All rights reserved. # Email: francis@mysociety.org; WWW: http://www.mysociety.org/ # -# $Id: public_body.rb,v 1.70 2008-05-19 12:01:22 francis Exp $ +# $Id: public_body.rb,v 1.71 2008-05-21 10:51:24 francis Exp $ require 'csv' require 'set' diff --git a/app/models/public_body_tag.rb b/app/models/public_body_tag.rb index 2bad6778c..414b903fb 100644 --- a/app/models/public_body_tag.rb +++ b/app/models/public_body_tag.rb @@ -1,5 +1,5 @@ # == Schema Information -# Schema version: 55 +# Schema version: 56 # # Table name: public_body_tags # @@ -15,7 +15,7 @@ # Copyright (c) 2008 UK Citizens Online Democracy. All rights reserved. # Email: francis@mysociety.org; WWW: http://www.mysociety.org/ # -# $Id: public_body_tag.rb,v 1.12 2008-05-19 12:01:22 francis Exp $ +# $Id: public_body_tag.rb,v 1.13 2008-05-21 10:51:24 francis Exp $ class PublicBodyTag < ActiveRecord::Base validates_presence_of :public_body diff --git a/app/models/track_mailer.rb b/app/models/track_mailer.rb index f581abc3a..bf92655af 100644 --- a/app/models/track_mailer.rb +++ b/app/models/track_mailer.rb @@ -4,7 +4,7 @@ # Copyright (c) 2008 UK Citizens Online Democracy. All rights reserved. # Email: francis@mysociety.org; WWW: http://www.mysociety.org/ # -# $Id: track_mailer.rb,v 1.11 2008-05-18 21:57:42 francis Exp $ +# $Id: track_mailer.rb,v 1.12 2008-05-21 10:51:24 francis Exp $ class TrackMailer < ApplicationMailer def event_digest(user, email_about_things) @@ -40,14 +40,16 @@ class TrackMailer < ApplicationMailer end end - # Query for things in this track - xapian_object = InfoRequest.full_search([InfoRequestEvent], track_thing.track_query, 'created_at', false, nil, 100, 1) + # Query for things in this track. We use described_at for the + # ordering, so we catch anything new (before described), or + # anything whose new status has been described. + xapian_object = InfoRequest.full_search([InfoRequestEvent], track_thing.track_query, 'described_at', false, nil, 200, 1) # Go through looking for unalerted things alert_results = [] for result in xapian_object.results if result[:model].class.to_s == "InfoRequestEvent" - if not done_info_request_events.include?(result[:model].id) and track_thing.created_at < result[:model].created_at + if not done_info_request_events.include?(result[:model].id) and track_thing.created_at < result[:model].described_at # OK alert this one alert_results.push(result) end diff --git a/app/models/track_thing.rb b/app/models/track_thing.rb index 7fb72bff6..c63886071 100644 --- a/app/models/track_thing.rb +++ b/app/models/track_thing.rb @@ -1,5 +1,5 @@ # == Schema Information -# Schema version: 55 +# Schema version: 56 # # Table name: track_things # @@ -21,7 +21,7 @@ # Copyright (c) 2008 UK Citizens Online Democracy. All rights reserved. # Email: francis@mysociety.org; WWW: http://www.mysociety.org/ # -# $Id: track_thing.rb,v 1.22 2008-05-19 12:01:22 francis Exp $ +# $Id: track_thing.rb,v 1.23 2008-05-21 10:51:24 francis Exp $ class TrackThing < ActiveRecord::Base belongs_to :tracking_user, :class_name => 'User' @@ -111,6 +111,8 @@ class TrackThing < ActiveRecord::Base :web => "To follow updates to the request '" + CGI.escapeHTML(self.info_request.title) + "'", :email => "Then you will be emailed whenever the request '" + CGI.escapeHTML(self.info_request.title) + "' is updated.", :email_subject => "Confirm you want to follow updates to the request '" + CGI.escapeHTML(self.info_request.title) + "'", + # RSS sorting + :feed_sortby => 'newest' } elsif self.track_type == 'all_new_requests' @params = { @@ -126,6 +128,8 @@ class TrackThing < ActiveRecord::Base :web => "To be told about any new requests", :email => "Then you will be emailed whenever anyone makes a new FOI request", :email_subject => "Confirm you want to be emailed about new requests", + # RSS sorting + :feed_sortby => 'newest' } elsif self.track_type == 'all_successful_requests' @params = { @@ -141,6 +145,11 @@ class TrackThing < ActiveRecord::Base :web => "To be told about any successful requests", :email => "Then you will be emailed whenever an FOI request succeeds", :email_subject => "Confirm you want to be emailed when an FOI request succeeds", + # RSS sorting - used described date, as newest would give a + # date for responses possibly days before description, so + # wouldn't appear at top of list when description (known + # success) causes match. + :feed_sortby => 'described' } elsif self.track_type == 'public_body_updates' @params = { @@ -156,6 +165,8 @@ class TrackThing < ActiveRecord::Base :web => "To be told about new requests to the public authority '" + CGI.escapeHTML(self.public_body.name) + "'", :email => "Then you will be emailed whenever someone requests something from '" + CGI.escapeHTML(self.public_body.name) + "'.", :email_subject => "Confirm you want to be told about new requests to '" + CGI.escapeHTML(self.public_body.name) + "'", + # RSS sorting + :feed_sortby => 'newest' } elsif self.track_type == 'user_updates' @params = { @@ -171,6 +182,8 @@ class TrackThing < ActiveRecord::Base :web => "To be told about new requests by '" + CGI.escapeHTML(self.tracked_user.name) + "'", :email => "Then you will be emailed whenever '" + CGI.escapeHTML(self.tracked_user.name) + "' requests something", :email_subject => "Confirm you want to be told about new requests by '" + CGI.escapeHTML(self.tracked_user.name) + "'", + # RSS sorting + :feed_sortby => 'newest' } elsif self.track_type == 'search_query' @params = { @@ -186,15 +199,18 @@ class TrackThing < ActiveRecord::Base :web => "To follow requests and responses matching '" + CGI.escapeHTML(self.track_query) + "'", :email => "Then you will be emailed whenever a new request or response matches '" + CGI.escapeHTML(self.track_query) + "'.", :email_subject => "Confirm you want to be told about new requests or responses matching '" + CGI.escapeHTML(self.track_query) + "'", + # RSS sorting - XXX hmmm, we don't really know which to use + # here for sorting. Might be a query term (e.g. 'cctv'), in + # which case newest is good, or might be something like + # all rejected requests in which case want to sort by + # described (when we discover criteria is met). Rather + # conservatively am picking described, as that will make + # things appear in feed more than the should, rather than less. + :feed_sortby => 'described' } else raise "unknown tracking type " + self.track_type end - - # for RSS sort by described date, as newest would give a date for - # responses possibly days before description, so wouldn't appear at top - # of list when description causes match. - params[:feed_sortby] = 'described' end return @params end diff --git a/app/models/track_things_sent_email.rb b/app/models/track_things_sent_email.rb index eede4b5fc..850f64880 100644 --- a/app/models/track_things_sent_email.rb +++ b/app/models/track_things_sent_email.rb @@ -1,5 +1,5 @@ # == Schema Information -# Schema version: 55 +# Schema version: 56 # # Table name: track_things_sent_emails # @@ -18,7 +18,7 @@ # Copyright (c) 2008 UK Citizens Online Democracy. All rights reserved. # Email: francis@mysociety.org; WWW: http://www.mysociety.org/ # -# $Id: track_things_sent_email.rb,v 1.6 2008-05-19 12:01:22 francis Exp $ +# $Id: track_things_sent_email.rb,v 1.7 2008-05-21 10:51:24 francis Exp $ class TrackThingsSentEmail < ActiveRecord::Base belongs_to :info_request_event diff --git a/app/models/user.rb b/app/models/user.rb index ec34c8a6f..cb0b6b867 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -1,5 +1,5 @@ # == Schema Information -# Schema version: 55 +# Schema version: 56 # # Table name: users # @@ -21,7 +21,7 @@ # Copyright (c) 2007 UK Citizens Online Democracy. All rights reserved. # Email: francis@mysociety.org; WWW: http://www.mysociety.org/ # -# $Id: user.rb,v 1.55 2008-05-19 12:01:22 francis Exp $ +# $Id: user.rb,v 1.56 2008-05-21 10:51:24 francis Exp $ require 'digest/sha1' diff --git a/app/models/user_info_request_sent_alert.rb b/app/models/user_info_request_sent_alert.rb index 7af7a599a..872286c88 100644 --- a/app/models/user_info_request_sent_alert.rb +++ b/app/models/user_info_request_sent_alert.rb @@ -1,5 +1,5 @@ # == Schema Information -# Schema version: 55 +# Schema version: 56 # # Table name: user_info_request_sent_alerts # @@ -17,7 +17,7 @@ # Copyright (c) 2008 UK Citizens Online Democracy. All rights reserved. # Email: francis@mysociety.org; WWW: http://www.mysociety.org/ # -# $Id: user_info_request_sent_alert.rb,v 1.14 2008-05-19 12:01:22 francis Exp $ +# $Id: user_info_request_sent_alert.rb,v 1.15 2008-05-21 10:51:24 francis Exp $ class UserInfoRequestSentAlert < ActiveRecord::Base belongs_to :user |