diff options
-rw-r--r-- | app/controllers/application.rb | 39 | ||||
-rw-r--r-- | app/controllers/request_controller.rb | 15 | ||||
-rw-r--r-- | app/controllers/track_controller.rb | 22 | ||||
-rw-r--r-- | app/helpers/link_to_helper.rb | 12 | ||||
-rw-r--r-- | app/models/track_mailer.rb | 13 | ||||
-rw-r--r-- | app/models/track_thing.rb | 6 | ||||
-rw-r--r-- | app/views/layouts/default.atom.erb | 1 | ||||
-rw-r--r-- | app/views/request/_request_listing_via_event.rhtml | 4 | ||||
-rw-r--r-- | app/views/request/show.rhtml | 6 | ||||
-rw-r--r-- | app/views/track/atom_feed.atom.builder | 24 | ||||
-rw-r--r-- | app/views/track/track_set.rhtml | 6 | ||||
-rw-r--r-- | app/views/track_mailer/event_digest.rhtml | 4 | ||||
-rw-r--r-- | app/views/user/show.rhtml | 9 | ||||
-rw-r--r-- | config/routes.rb | 5 | ||||
-rw-r--r-- | todo.txt | 46 |
15 files changed, 158 insertions, 54 deletions
diff --git a/app/controllers/application.rb b/app/controllers/application.rb index 3b2b04d4f..39a676669 100644 --- a/app/controllers/application.rb +++ b/app/controllers/application.rb @@ -6,7 +6,7 @@ # Copyright (c) 2007 UK Citizens Online Democracy. All rights reserved. # Email: francis@mysociety.org; WWW: http://www.mysociety.org/ # -# $Id: application.rb,v 1.35 2008-04-03 15:29:50 francis Exp $ +# $Id: application.rb,v 1.36 2008-04-09 01:32:52 francis Exp $ class ApplicationController < ActionController::Base @@ -124,32 +124,41 @@ class ApplicationController < ActionController::Base end end + # Convert URL name for sort by order, to Lucene query + def order_to_sort_by(sortby) + if sortby.nil? + return nil + elsif sortby == 'newest' + return 'created_at desc' + elsif sortby == 'described' + return 'last_described_at desc' # use this for RSS + else + raise "Unknown sort order " + @sortby + end + end + # Function for search - def perform_search(query, sortby, per_page = 25) + def perform_search(query, sortby, per_page = 25, this_page = nil, html_highlight = true) @query = query @sortby = sortby # Work out sorting method - if @sortby.nil? - order = nil - elsif @sortby == 'newest' - order = 'created_at desc' - elsif @sortby == 'described' - order = 'last_described_at desc' # use this for RSS - else - raise "Unknown sort order " + @sortby - end + order = order_to_sort_by(@sortby) # Peform the search @per_page = per_page - @page = (params[:page] || "1").to_i + if this_page.nil? + @page = (params[:page] || "1").to_i + else + @page = this_page + end - # XXX remember to update in models/track_mailer.rb also + # XXX remove duplication with models/track_mailer.rb solr_object = InfoRequestEvent.multi_solr_search(@query, :models => [ PublicBody, User ], :limit => @per_page, :offset => (@page - 1) * @per_page, :highlight => { - :prefix => '<span class="highlight">', - :suffix => '</span>', + :prefix => html_highlight ? '<span class="highlight">' : "*", + :suffix => html_highlight ? '</span>' : "*", :fragsize => 250, :fields => ["solr_text_main", "title", # InfoRequestEvent "name", "short_name", # PublicBody diff --git a/app/controllers/request_controller.rb b/app/controllers/request_controller.rb index b16fc93cf..e14d3ae27 100644 --- a/app/controllers/request_controller.rb +++ b/app/controllers/request_controller.rb @@ -4,7 +4,7 @@ # Copyright (c) 2007 UK Citizens Online Democracy. All rights reserved. # Email: francis@mysociety.org; WWW: http://www.mysociety.org/ # -# $Id: request_controller.rb,v 1.72 2008-04-04 02:29:09 francis Exp $ +# $Id: request_controller.rb,v 1.73 2008-04-09 01:32:52 francis Exp $ class RequestController < ApplicationController @@ -227,6 +227,19 @@ class RequestController < ApplicationController end end + # Used for links from polymorphic URLs e.g. in Atom feeds - just redirect to + # proper URL for the message the event refers to + def show_request_event + @info_request_event = InfoRequestEvent.find(params[:info_request_event_id]) + if not @info_request_event.incoming_message.nil? + redirect_to incoming_message_url(@info_request_event.incoming_message) + elsif not @info_request_event.outgoing_message.nil? + redirect_to outgoing_message_url(@info_request_event.outgoing_message) + else + # XXX maybe there are better URLs for some events than this + redirect_to request_url(@info_request_event.info_request) + end + end # Show an individual incoming message, and allow followup def show_response diff --git a/app/controllers/track_controller.rb b/app/controllers/track_controller.rb index 0ea3376f5..f9d02111a 100644 --- a/app/controllers/track_controller.rb +++ b/app/controllers/track_controller.rb @@ -5,7 +5,9 @@ # Copyright (c) 2008 UK Citizens Online Democracy. All rights reserved. # Email: francis@mysociety.org; WWW: http://www.mysociety.org/ # -# $Id: track_controller.rb,v 1.4 2008-04-04 03:02:02 francis Exp $ +# $Id: track_controller.rb,v 1.5 2008-04-09 01:32:52 francis Exp $ + +require 'feedparser' class TrackController < ApplicationController @@ -15,8 +17,12 @@ class TrackController < ApplicationController @track_thing = TrackThing.create_track_for_request(@info_request) ret = self.track_set if ret - flash[:notice] = "You are " + ret + " tracking this request!" - redirect_to request_url(@info_request) + if @track_thing.track_medium == 'feed' + redirect_to :controller => 'track', :action => 'atom_feed', :track_id => @track_thing.id + else + flash[:notice] = "You are " + ret + " tracking this request!" + redirect_to request_url(@info_request) + end end end @@ -31,7 +37,7 @@ class TrackController < ApplicationController @track_thing.track_medium = 'email_daily' - @title = @track_thing.params[:title] + @title = @track_thing.params[:set_title] if params[:track_thing] @track_thing.track_medium = params[:track_thing][:track_medium] end @@ -51,6 +57,14 @@ class TrackController < ApplicationController return "now" end + # Atom feed (like RSS) for the track + def atom_feed + @track_thing = TrackThing.find(params[:track_id].to_i) + + perform_search(@track_thing.track_query, @track_thing.params[:feed_sortby], 25, 1) + respond_to :atom + end + # Delete a track def delete track_thing = TrackThing.find(params[:track_id].to_i) diff --git a/app/helpers/link_to_helper.rb b/app/helpers/link_to_helper.rb index 7e4b26be7..ab8915e5d 100644 --- a/app/helpers/link_to_helper.rb +++ b/app/helpers/link_to_helper.rb @@ -5,7 +5,7 @@ # Copyright (c) 2007 UK Citizens Online Democracy. All rights reserved. # Email: francis@mysociety.org; WWW: http://www.mysociety.org/ # -# $Id: link_to_helper.rb,v 1.24 2008-04-03 18:36:57 francis Exp $ +# $Id: link_to_helper.rb,v 1.25 2008-04-09 01:32:53 francis Exp $ module LinkToHelper @@ -24,7 +24,15 @@ module LinkToHelper def request_admin_link(info_request) link_to h(info_request.title), request_admin_url(info_request) end - + + # Incoming / outgoing messages + def incoming_message_url(incoming_message) + return request_url(incoming_message.info_request)+"#incoming-"+incoming_message.id.to_s + end + def outgoing_message_url(outgoing_message) + return request_url(outgoing_message.info_request)+"#outgoing-"+outgoing_message.id.to_s + end + # Public bodies def public_body_url(public_body) return show_public_body_url(:url_name => public_body.url_name, :only_path => true) diff --git a/app/models/track_mailer.rb b/app/models/track_mailer.rb index 20ca104a1..119654009 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.4 2008-04-04 14:50:51 francis Exp $ +# $Id: track_mailer.rb,v 1.5 2008-04-09 01:32:53 francis Exp $ class TrackMailer < ApplicationMailer def event_digest(user, email_about_things) @@ -28,7 +28,7 @@ class TrackMailer < ApplicationMailer #STDERR.puts "user " + user.url_name email_about_things = [] - track_things = TrackThing.find(:all, :conditions => [ "tracking_user_id = ?", user.id ]) + track_things = TrackThing.find(:all, :conditions => [ "tracking_user_id = ? and track_medium = ?", user.id, 'email_daily' ]) for track_thing in track_things #STDERR.puts " track " + track_thing.track_query @@ -41,16 +41,17 @@ class TrackMailer < ApplicationMailer end # Query for things in this track - # XXX remember to update in controllers/application.rb also + # XXX remove duplication with controllers/application.rb + #perform_search(track_thing.track_query, 'newest', 100, 1, false) solr_object = InfoRequestEvent.multi_solr_search(track_thing.track_query, :models => [ PublicBody, User ], - :limit => 100, :offset => 0, + :limit => 100, :offset => 0, :highlight => { - :prefix => '*', :suffix => '*', + :prefix => "*", :suffix => "*", :fragsize => 250, :fields => ["solr_text_main", "title", # InfoRequestEvent "name", "short_name", # PublicBody "name" # User - ]}, :order => "created_at desc" + ]}, :order => 'created_at desc' ) # Go through looking for unalerted things diff --git a/app/models/track_thing.rb b/app/models/track_thing.rb index 778252c53..2ee494b9d 100644 --- a/app/models/track_thing.rb +++ b/app/models/track_thing.rb @@ -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.7 2008-04-04 02:29:09 francis Exp $ +# $Id: track_thing.rb,v 1.8 2008-04-09 01:32:53 francis Exp $ class TrackThing < ActiveRecord::Base belongs_to :tracking_user, :class_name => 'User' @@ -40,6 +40,7 @@ class TrackThing < ActiveRecord::Base validates_inclusion_of :track_medium, :in => [ 'email_daily', + 'feed' ] def TrackThing.create_track_for_request(info_request) @@ -57,10 +58,11 @@ class TrackThing < ActiveRecord::Base if self.track_type == 'request_updates' @params = { # Website - :title => "Track the request '" + CGI.escapeHTML(self.info_request.title) + "'", + :set_title => "How would you like to track the request '" + CGI.escapeHTML(self.info_request.title) + "'?", :list_description => "'<a href=\"/request/" + CGI.escapeHTML(self.info_request.url_title) + "\">" + CGI.escapeHTML(self.info_request.title) + "</a>', a request", # XXX yeuch, sometimes I just want to call view helpers from the model, sorry! can't work out how # Email :title_in_email => "New updates for the request '" + self.info_request.title + "'", + :title_in_rss => "New updates for the request '" + CGI.escapeHTML(self.info_request.title) + "'", # Authentication :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.", diff --git a/app/views/layouts/default.atom.erb b/app/views/layouts/default.atom.erb new file mode 100644 index 000000000..37f0bddbd --- /dev/null +++ b/app/views/layouts/default.atom.erb @@ -0,0 +1 @@ +<%= yield %> diff --git a/app/views/request/_request_listing_via_event.rhtml b/app/views/request/_request_listing_via_event.rhtml index 8e673a142..79bbe0ef4 100644 --- a/app/views/request/_request_listing_via_event.rhtml +++ b/app/views/request/_request_listing_via_event.rhtml @@ -4,9 +4,9 @@ <%= link_to @highlighting['InfoRequestEvent'][event.id]["title"], request_url(info_request) %> <% @highlighting['InfoRequestEvent'][event.id].delete("title") %> <% elsif not event.incoming_message.nil? %> - <%= link_to "Response to '" + h(info_request.title) + "'", request_url(info_request)+"#incoming-"+event.incoming_message.id.to_s %> + <%= link_to "Response to '" + h(info_request.title) + "'", incoming_message_url(event.incoming_message) %> <% elsif not event.outgoing_message.nil? and event.event_type == 'followup_sent' %> - <%= link_to "Follow up message for '" + h(info_request.title) + "'", request_url(info_request)+"#outgoing-"+event.outgoing_message.id.to_s %> + <%= link_to "Follow up message for '" + h(info_request.title) + "'", outgoing_message_url(event.outgoing_message) %> <% else %> <%= link_to h(info_request.title), request_url(info_request) %> <% end %> diff --git a/app/views/request/show.rhtml b/app/views/request/show.rhtml index ff3330362..702a8c2e9 100644 --- a/app/views/request/show.rhtml +++ b/app/views/request/show.rhtml @@ -79,12 +79,12 @@ (<%= link_to "alter your subscriptions", user_url(@user) %>). <% else %> <%= link_to "Track updates to this request", track_request_url(:url_title => @info_request.url_title) %> - (by email or RSS) + (by email or RSS feed) <% end %> </p> <% else %> - <%= link_to "Track updates to this request", track_request_url(:url_title => @info_request.url_title) %> - (by email or RSS; be the first) + Be the first to <%= link_to "track updates to this request", track_request_url(:url_title => @info_request.url_title) %> + (by email or RSS feed) <% end %> <% if @info_requests_same_user_same_body.size > 0 %> diff --git a/app/views/track/atom_feed.atom.builder b/app/views/track/atom_feed.atom.builder new file mode 100644 index 000000000..627c53d11 --- /dev/null +++ b/app/views/track/atom_feed.atom.builder @@ -0,0 +1,24 @@ +atom_feed do |feed| + feed.title(@track_thing.params[:title_in_rss]) + + for search_result in @search_results + feed.entry(search_result) do |entry| + # Get the HTML content from the same partial template as website search does + content = '' + if search_result.class.to_s == 'InfoRequestEvent' + content += render :partial => 'request/request_listing_via_event', :locals => { :event => search_result, :info_request => search_result.info_request } + else + content = "<p><strong>Unknown search result type " + search_result.class.to_s + "</strong></p>" + end + # Pull out the heading as separate item, from the partial template + content.match(/(<a href="[^>]*">(.*)<\/a>\s+<br>)/) + heading = $1 + heading_text = $2 + content.sub!(heading, "") + # Render the atom + entry.title(heading_text, :type => 'html') + entry.content(content, :type => 'html') + end + end +end + diff --git a/app/views/track/track_set.rhtml b/app/views/track/track_set.rhtml index 47e4f59a1..90b767219 100644 --- a/app/views/track/track_set.rhtml +++ b/app/views/track/track_set.rhtml @@ -13,11 +13,9 @@ <br> --> <%= radio_button "track_thing", "track_medium", "email_daily" %> <label for="track_thing_track_medium_email_daily">Send me emails at most once a day</label> - <!-- <br> - <%= radio_button "track_thing", "track_medium", "rss" %> - <label for="track__thingtrack_medium_rss">Give me a feed to use in my news reader (RSS)</label> - --> + <%= radio_button "track_thing", "track_medium", "feed" %> + <label for="track_thing_track_medium_feed">Give me a feed to use in my news reader (RSS)</label> </div> <p class="form_note"> diff --git a/app/views/track_mailer/event_digest.rhtml b/app/views/track_mailer/event_digest.rhtml index f88a23bdf..9c8a5ad9a 100644 --- a/app/views/track_mailer/event_digest.rhtml +++ b/app/views/track_mailer/event_digest.rhtml @@ -20,10 +20,10 @@ extract.gsub!(/\s+/, ' ') if event.event_type == 'response' - url = main_url(request_url(event.info_request))+"#incoming-"+event.incoming_message.id.to_s + url = incoming_message_url(event.incoming_message) main_text += event.info_request.public_body.name + " sent a response to " + event.info_request.user.name elsif event.event_type == 'followup_sent' - url = main_url(request_url(event.info_request))+"#outgoing-"+event.outgoing_message.id.to_s + url = outgoing_message_url(event.outgoing_message) main_text += event.info_request.user.name + " sent a follow up message to " + event.info_request.public_body.name elsif event.event_type == 'sent' # this is unlikely to happen in real life, but happens in the test code diff --git a/app/views/user/show.rhtml b/app/views/user/show.rhtml index b80ab35f5..402ccf251 100644 --- a/app/views/user/show.rhtml +++ b/app/views/user/show.rhtml @@ -31,7 +31,14 @@ <% for track_thing in @display_user.track_things %> <li> <% form_tag :controller => 'track', :action => 'delete', :track_id => track_thing.id do %> - <%= track_thing.params[:list_description] %> + <%= track_thing.params[:list_description] %>, + <% if track_thing.track_medium == 'email_daily' %> + by email daily + <% elsif track_thing.track_medium == 'feed' %> + by <%= link_to "RSS feed", :controller => 'track', :action => 'atom_feed', :track_id => track_thing.id %> + <% else %> + <% raise "unknown track medium '" + track_thing.track_medium + "'" %> + <% end %> <!-- (<%= link_to "view latest updates", :controller => 'general', :action => 'search', :query => track_thing.track_query %>) --> <%= submit_tag "Delete" %> <% end %> diff --git a/config/routes.rb b/config/routes.rb index 26967bc8b..bbe0c6610 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -4,7 +4,7 @@ # Copyright (c) 2007 UK Citizens Online Democracy. All rights reserved. # Email: francis@mysociety.org; WWW: http://www.mysociety.org/ # -# $Id: routes.rb,v 1.51 2008-04-04 03:02:03 francis Exp $ +# $Id: routes.rb,v 1.52 2008-04-09 01:32:55 francis Exp $ ActionController::Routing::Routes.draw do |map| @@ -35,6 +35,8 @@ ActionController::Routing::Routes.draw do |map| request.show_response_no_followup '/request/:id/response', :action => 'show_response' request.show_response '/request/:id/response/:incoming_message_id', :action => 'show_response' request.get_attachment '/request/:id/response/:incoming_message_id/attach/:part/*file_name', :action => 'get_attachment' + + request.info_request_event '/request_event/:info_request_event_id', :action => 'show_request_event' end map.with_options :controller => 'user' do |user| @@ -56,6 +58,7 @@ ActionController::Routing::Routes.draw do |map| map.with_options :controller => 'track' do |track| track.track_request 'track/request/:url_title', :action => 'track_request' track.delete 'track/delete/:track_id', :action => 'delete' + track.atom_feed 'track/feed/:track_id', :action => 'atom_feed' end map.with_options :controller => 'help' do |help| @@ -1,6 +1,25 @@ +Atom: + +Add page to view responses from a specific track for RSS to link back to? + FOI requests to use to test it ============================== +http://www.whatdotheyknow.com/request/details_of_grant_awarded_to_vi_g_ + I received a reply on 4 April from Alison McCarthy to my request for +information about a development grant (SIC Code 7220) to Vero International +Software UK Limited which is unfortunately not satisfactory. + I requested all details about this grant in terms of its application and +any reports done afterwards. In order to facilitate my understanding as to the +degree of accountability regarding this grants, I need to see all documents +held by the Regional Development Agency which could possibly provide evidence +that the project outlined actually existed, and that the money wasn't simply +absorbed into shareholder profit. + It would be entirely fair to redact all trade secrets and confidential +information from the documents as they are disclosed, but I do not believe it +is reasonable to withhold disclosure of even their titles, dates and number of +pages. + Please send me all documentation relating to the decision to use results from the Oxford Economic Forecasting's report "The Economic Contribution of the Aviation Industry in the UK" in the "Air Transport White Paper Progress Report @@ -13,31 +32,31 @@ BAILII - relationship with law courts, robots.txt ? Next ==== -"Some other requets..." should have "more" link now - Fix search to deal with overdue message query that Tomski asks for And show status on the list of recent requests - is a pain not being able to see it. +Don't let people track their own requests? + +"Some other requests..." should have "more" link now + If you edit needs anim to waiting_response it doesn't edit the value in the event history, so screws up search stuff? https://secure.mysociety.org/admin/foi/request/show/37 https://secure.mysociety.org/admin/foi/request/show/137 +Show history of recent changes done by admins +GUI for uploading changed CSV files + Search and replace text "FOI" and "Freedom of Information" out the way more - but put it in the title tag "public body" --> "public authority"? -Adam's woes: -http://foi.mysociety.org/request/18/response/31 - - No doubt leaks email address via download.bin :( - -Tom's request to Parliament: - http://foi.mysociety.org/request/8 - -Consider removing login links from notifications of new responses - Later ===== +Get Atom highlighting to include stylesheet for yellow somehow +Does Atom infer base URLs from included HTML or do we need to be explicit? +Add RSS icons + Michael Turner's name has a space in it - strip them automatically (can see on the write message to page) Now that we have LinkToHelper in mailer *objects* (not classes) call out to it @@ -69,6 +88,10 @@ Holding pen with comments - new requests don't get sent straight away, but are Change email address - easier to do now with post_redirect.circumstance? +Consider showing Subject: of email somewhere + e.g. for http://www.whatdotheyknow.com/request/172/response/234 +the subject has all the content + One of the PDFs on live site has: Error: PDF version 1.6 -- xpdf supports version 1.5 (continuing anyway) Need to upgrade to poppler-utils? @@ -122,6 +145,7 @@ Blog posts / Wikipedia articles about this request Remember me box This can't possible be the best way, it is too depressing: http://onrails.org/articles/2006/02/18/auto-login +Then consider removing login links from notifications of new responses Screen scrape this and add link to it on the public body page http://www.ico.gov.uk/Home/tools_and_resources/decision_notices.aspx |