aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--app/controllers/application.rb10
-rw-r--r--app/controllers/track_controller.rb10
-rw-r--r--app/helpers/application_helper.rb7
-rw-r--r--app/models/application_mailer.rb7
-rw-r--r--app/models/track_mailer.rb96
-rw-r--r--app/models/track_thing.rb39
-rw-r--r--app/models/user.rb3
-rw-r--r--app/views/track/track_set.rhtml4
-rw-r--r--app/views/track_mailer/event_digest.rhtml57
-rw-r--r--app/views/user/show.rhtml17
-rw-r--r--config/crontab.ugly3
-rw-r--r--db/migrate/050_improve_track_things.rb25
-rw-r--r--db/schema.rb44
-rwxr-xr-xscript/alert-tracks7
-rw-r--r--spec/controllers/track_controller_spec.rb72
-rw-r--r--spec/fixtures/track_things.yml11
-rw-r--r--todo.txt11
17 files changed, 375 insertions, 48 deletions
diff --git a/app/controllers/application.rb b/app/controllers/application.rb
index a7ed76772..3b2b04d4f 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.34 2008-04-01 05:43:40 francis Exp $
+# $Id: application.rb,v 1.35 2008-04-03 15:29:50 francis Exp $
class ApplicationController < ActionController::Base
@@ -30,7 +30,7 @@ class ApplicationController < ActionController::Base
# Called from test code, is a mimic of User.confirm, for use in following email
# links when in controller tests (since we don't have full integration tests that
- # can work over multiple controllers)0
+ # can work over multiple controllers)
def test_code_redirect_by_email_token(token, controller_example_group)
post_redirect = PostRedirect.find_by_email_token(token)
if post_redirect.nil?
@@ -144,6 +144,7 @@ class ApplicationController < ActionController::Base
@per_page = per_page
@page = (params[:page] || "1").to_i
+ # XXX remember to update in models/track_mailer.rb also
solr_object = InfoRequestEvent.multi_solr_search(@query, :models => [ PublicBody, User ],
:limit => @per_page, :offset => (@page - 1) * @per_page,
:highlight => {
@@ -167,8 +168,9 @@ class ApplicationController < ActionController::Base
@highlighting = solr_object.highlights
end
- # URL generating functions are needed by all controllers (for redirects)
- # and views (for links), so include them into all of both.
+ # URL generating functions are needed by all controllers (for redirects),
+ # views (for links) and mailers (for use in emails), so include them into
+ # all of all.
include LinkToHelper
end
diff --git a/app/controllers/track_controller.rb b/app/controllers/track_controller.rb
index 0ad3ae740..37283d0d9 100644
--- a/app/controllers/track_controller.rb
+++ b/app/controllers/track_controller.rb
@@ -5,7 +5,7 @@
# 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.1 2008-04-01 16:40:37 francis Exp $
+# $Id: track_controller.rb,v 1.2 2008-04-03 15:29:50 francis Exp $
class TrackController < ApplicationController
@@ -21,10 +21,14 @@ class TrackController < ApplicationController
# Generic request tracker - set @track_thing before calling
def track_set
+ @track_thing.track_medium = 'email_daily'
+
@title = @track_thing.params[:title]
- @track_thing.track_medium = params[:track_thing][:track_medium]
+ if params[:track_thing]
+ @track_thing.track_medium = params[:track_thing][:track_medium]
+ end
- if not params[:submitted_track_request] or not @track_thing.valid?
+ if not params[:submitted_track] or not @track_thing.valid?
render :template => 'track/track_set'
return false
end
diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb
index b6513155d..f655209ef 100644
--- a/app/helpers/application_helper.rb
+++ b/app/helpers/application_helper.rb
@@ -5,11 +5,12 @@
# Copyright (c) 2007 UK Citizens Online Democracy. All rights reserved.
# Email: francis@mysociety.org; WWW: http://www.mysociety.org/
#
-# $Id: application_helper.rb,v 1.18 2008-03-19 05:46:52 francis Exp $
+# $Id: application_helper.rb,v 1.19 2008-04-03 15:29:51 francis Exp $
module ApplicationHelper
- # URL generating functions are needed by all controllers (for redirects)
- # views (for links), so include them into all of both.
+ # URL generating functions are needed by all controllers (for redirects),
+ # views (for links) and mailers (for use in emails), so include them into
+ # all of all.
include LinkToHelper
# Contact email address
diff --git a/app/models/application_mailer.rb b/app/models/application_mailer.rb
index d41c68dfc..32c6ced26 100644
--- a/app/models/application_mailer.rb
+++ b/app/models/application_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: application_mailer.rb,v 1.6 2008-02-28 14:25:51 francis Exp $
+# $Id: application_mailer.rb,v 1.7 2008-04-03 15:29:51 francis Exp $
class ApplicationMailer < ActionMailer::Base
# Include all the functions views get, as emails call similar things.
@@ -17,5 +17,10 @@ class ApplicationMailer < ActionMailer::Base
def contact_from_name_and_email
"WhatDoTheyKnow <"+MySociety::Config.get("CONTACT_EMAIL", 'contact@localhost')+">"
end
+
+ # URL generating functions are needed by all controllers (for redirects),
+ # views (for links) and mailers (for use in emails), so include them into
+ # all of all.
+ include LinkToHelper
end
diff --git a/app/models/track_mailer.rb b/app/models/track_mailer.rb
new file mode 100644
index 000000000..0a7800ee6
--- /dev/null
+++ b/app/models/track_mailer.rb
@@ -0,0 +1,96 @@
+# models/track_mailer.rb:
+# Emails which go to users who are tracking things.
+#
+# 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.1 2008-04-03 15:29:51 francis Exp $
+
+class TrackMailer < ApplicationMailer
+ def event_digest(user, email_about_things)
+ post_redirect = PostRedirect.new(
+ :uri => main_url(user_url(user)),
+ :user_id => user.id)
+ post_redirect.save!
+ unsubscribe_url = confirm_url(:email_token => post_redirect.email_token)
+
+ @from = contact_from_name_and_email
+ @recipients = user.name_and_email
+ @subject = "Your WhatDoTheyKnow.com email alert"
+ @body = { :user => user, :email_about_things => email_about_things, :unsubscribe_url => unsubscribe_url }
+ end
+
+ # Send email alerts for tracked things
+ def self.alert_tracks
+ now = Time.now()
+ users = User.find(:all, :conditions => [ "last_daily_track_email < ?", now - 1.day ])
+ for user in users
+ #STDERR.puts "user " + user.url_name
+
+ email_about_things = []
+ track_things = TrackThing.find(:all, :conditions => [ "tracking_user_id = ?", user.id ])
+ for track_thing in track_things
+ #STDERR.puts " track " + track_thing.track_query
+
+ # What have we alerted on already?
+ done_info_request_events = {}
+ for t in track_thing.track_things_sent_emails
+ if not t.info_request_event_id.nil?
+ done_info_request_events[t.info_request_event_id] = 1
+ end
+ end
+
+ # Query for things in this track
+ # XXX remember to update in controllers/application.rb also
+ solr_object = InfoRequestEvent.multi_solr_search(track_thing.track_query, :models => [ PublicBody, User ],
+ :limit => 100, :offset => 0,
+ :highlight => {
+ :prefix => '*', :suffix => '*',
+ :fragsize => 250,
+ :fields => ["solr_text_main", "title", # InfoRequestEvent
+ "name", "short_name", # PublicBody
+ "name" # User
+ ]}, :order => "created_at desc"
+ )
+
+ # Go through looking for unalerted things
+ alert_results = []
+ for result in solr_object.results
+ if result.class.to_s == "InfoRequestEvent"
+ if not done_info_request_events.include?(result.id) and track_thing.created_at < result.created_at
+ # OK alert this one
+ alert_results.push(result)
+ end
+ else
+ raise "need to add other types to TrackMailer.alert_tracks"
+ end
+ end
+ # If there were more alerts for this track, then store them
+ if alert_results.size > 0
+ email_about_things.push([track_thing, alert_results])
+ end
+ end
+
+ # If we have anything to send, then send everything for the user in one mail
+ if email_about_things.size > 0
+ STDERR.puts "sending alert for user " + user.url_name
+ TrackMailer.deliver_event_digest(user, email_about_things)
+ end
+
+ # Record that we've now sent those alerts to that user
+ for track_thing, alert_results in email_about_things
+ for result in alert_results
+ track_things_sent_email = TrackThingsSentEmail.new
+ track_things_sent_email.track_thing_id = track_thing.id
+ track_things_sent_email.info_request_event_id = result.id
+ track_things_sent_email.save!
+ end
+ end
+ user.last_daily_track_email = now
+ user.save!
+ end
+ end
+
+end
+
+
diff --git a/app/models/track_thing.rb b/app/models/track_thing.rb
index 35f384e5c..deb391423 100644
--- a/app/models/track_thing.rb
+++ b/app/models/track_thing.rb
@@ -18,37 +18,54 @@
# 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.1 2008-04-01 16:40:37 francis Exp $
+# $Id: track_thing.rb,v 1.2 2008-04-03 15:29:51 francis Exp $
class TrackThing < ActiveRecord::Base
belongs_to :user, :foreign_key => 'tracking_user_id'
validates_presence_of :track_query
+ validates_presence_of :track_type
belongs_to :info_request
belongs_to :public_body
belongs_to :user, :foreign_key => 'tracked_user_id'
+ has_many :track_things_sent_emails
+
+ validates_inclusion_of :track_type, :in => [
+ 'request_updates',
+ ]
+
validates_inclusion_of :track_medium, :in => [
'email_daily',
]
- attr_accessor :params
-
def TrackThing.create_track_for_request(info_request)
track_thing = TrackThing.new
+ track_thing.track_type = 'request_updates'
track_thing.info_request = info_request
- track_thing.params = {
- :title => "Track the request '" + CGI.escapeHTML(info_request.title) + "'",
- :feed_sortby => 'described',
-
- :web => "To follow updates to the request '" + CGI.escapeHTML(info_request.title) + "'",
- :email => "Then you will be emailed whenever the request '" + CGI.escapeHTML(info_request.title) + "' is updated.",
- :email_subject => "Confirm you want to follow updates to the request '" + CGI.escapeHTML(info_request.title) + "'",
- }
track_thing.track_query = "request:" + info_request.url_title
return track_thing
end
+ # Return hash of text parameters describing the request etc.
+ def params
+ if @params.nil?
+ if self.track_type == 'request_updates'
+ @params = {
+ :title => "Track the request '" + CGI.escapeHTML(self.info_request.title) + "'",
+ :describe => "The request '" + CGI.escapeHTML(self.info_request.title) + "'",
+ :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) + "'",
+ :feed_sortby => 'described', # for RSS, as newest would give a date for responses possibly days before description
+ }
+ else
+ raise "unknown tracking type " + self.track_type
+ end
+ end
+ return @params
+ end
+
end
diff --git a/app/models/user.rb b/app/models/user.rb
index 28b1e5b28..1efe0ad24 100644
--- a/app/models/user.rb
+++ b/app/models/user.rb
@@ -20,7 +20,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.44 2008-04-01 16:40:37 francis Exp $
+# $Id: user.rb,v 1.45 2008-04-03 15:29:51 francis Exp $
require 'digest/sha1'
@@ -35,6 +35,7 @@ class User < ActiveRecord::Base
has_many :info_requests
has_many :user_info_request_sent_alerts
has_many :post_redirects
+ has_many :track_things, :foreign_key => 'tracking_user_id'
attr_accessor :password_confirmation
validates_confirmation_of :password, :message =>"^Please enter the same password twice"
diff --git a/app/views/track/track_set.rhtml b/app/views/track/track_set.rhtml
index 380d1dd64..7f89e98db 100644
--- a/app/views/track/track_set.rhtml
+++ b/app/views/track/track_set.rhtml
@@ -12,7 +12,7 @@
<label for="track_track_medium_email">Send me emails shortly after there are updates</label>
<br> -->
<%= radio_button "track_thing", "track_medium", "email_daily" %>
- <label for="track_thing_track_medium_email">Send me emails at most once a day</label>
+ <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" %>
@@ -26,7 +26,7 @@
</p>
<div class="form_button">
- <%= hidden_field_tag 'submitted_track_request', 1 %>
+ <%= hidden_field_tag 'submitted_track', 1 %>
<%= submit_tag "Subscribe" %>
</div>
<% end %>
diff --git a/app/views/track_mailer/event_digest.rhtml b/app/views/track_mailer/event_digest.rhtml
new file mode 100644
index 000000000..856fdfb52
--- /dev/null
+++ b/app/views/track_mailer/event_digest.rhtml
@@ -0,0 +1,57 @@
+<%
+ # Construct the main text of the mail
+ main_text = ''
+ for track_thing, alert_results in @email_about_things
+ main_text += track_thing.params[:describe] + "\n"
+ main_text += ("=" * track_thing.params[:describe].size) + "\n\n"
+ for result in alert_results.reverse
+ if result.class.to_s == "InfoRequestEvent"
+ event = result
+
+ if not @highlighting.nil? and @highlighting['InfoRequestEvent'][event.id].size > 0
+ extract = @highlighting['InfoRequestEvent'][event.id].values.join(" ")
+ elsif not event.outgoing_message.nil?
+ extract = excerpt(event.outgoing_message.body_without_salutation, "", 150)
+ elsif not event.incoming_message.nil?
+ extract = excerpt(event.incoming_message.get_body_for_quoting, "", 150)
+ else
+ extract = excerpt(info_request.initial_request_text, "", 150)
+ end
+ extract.gsub!(/\s+/, ' ')
+
+ if event.event_type == 'response'
+ url = main_url(request_url(event.info_request))+"#incoming-"+event.incoming_message.id.to_s
+ 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
+ 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
+ url = main_url(request_url(event.info_request))+"#outgoing-"+event.outgoing_message.id.to_s
+ main_text += event.info_request.user.name + " sent a request to " + event.info_request.public_body.name
+ else
+ raise "unknown type in event_digest " + event.event_type
+ end
+ main_text += " (" + simple_date(event.created_at) + ")\n"
+ main_text += MySociety::Format.wrap_email_body('"' + extract + '"').gsub(/\n+$/, "") + "\n"
+ main_text += url + "\n"
+
+ main_text += "\n"
+ else
+ raise "need to add other types to TrackMailer.event_digest"
+ end
+ end
+ main_text += "\n"
+ end
+
+ #STDERR.puts main_text
+ #STDERR.puts @unsubscribe_url
+%><%=main_text%>Alter your subscription
+=======================
+
+Please click on the link below to cancel or alter these emails.
+<%=@unsubscribe_url%>
+
+-- the WhatDoTheyKnow team
+
+
diff --git a/app/views/user/show.rhtml b/app/views/user/show.rhtml
index 3585f345f..be89d3899 100644
--- a/app/views/user/show.rhtml
+++ b/app/views/user/show.rhtml
@@ -21,6 +21,19 @@
<% end %>
</p>
+ <% if not @display_user.track_things.empty? %>
+ <h2>
+ <%= @is_you ? 'You are' : 'This person is' %> tracking
+ <%=pluralize(@display_user.track_things.size, "thing") %>
+ </h2>
+
+ <ul>
+ <% for track_thing in @display_user.track_things %>
+ <li><%= track_thing.params[:describe] %></li>
+ <% end %>
+ </ul>
+ <% end %>
+
<% if @display_user.info_requests.empty? %>
<h2>Freedom of Information requests made by <%= @is_you ? 'you' : 'this person' %></h2>
<p><%= @is_you ? 'You have' : 'This person has' %>
@@ -28,8 +41,8 @@
<% else %>
<h2>
- <%=pluralize(@display_user.info_requests.size, "Freedom of Information request") %>
- made by <%= @is_you ? 'you' : 'this person' %>
+ <%= @is_you ? 'You have' : 'This person has' %>
+ made <%=pluralize(@display_user.info_requests.size, "Freedom of Information request") %>
</h2>
<%= render :partial => 'request/request_listing', :locals => { :info_requests => @display_user.info_requests.sort { |a,b| b.created_at <=> a.created_at } } %>
diff --git a/config/crontab.ugly b/config/crontab.ugly
index 4f6e4d4ab..842c75c05 100644
--- a/config/crontab.ugly
+++ b/config/crontab.ugly
@@ -4,13 +4,14 @@
# Copyright (c) 2008 UK Citizens Online Democracy. All rights reserved.
# Email: francis@mysociety.org. WWW: http://www.mysociety.org/
#
-# $Id: crontab.ugly,v 1.8 2008-03-24 09:35:24 francis Exp $
+# $Id: crontab.ugly,v 1.9 2008-04-03 15:29:52 francis Exp $
PATH=/usr/local/bin:/usr/bin:/bin
MAILTO=team@whatdotheyknow.com
# Every 10 minutes
*/10 * * * * !!(*= $user *)!! run-with-lockfile -n /data/vhost/!!(*= $vhost *)!!/update-solr-index.lock /data/vhost/!!(*= $vhost *)!!/mysociety/foi/script/update-solr-index || echo "stalled?"
+5,15,25,35,45,55 * * * * !!(*= $user *)!! run-with-lockfile -n /data/vhost/!!(*= $vhost *)!!/alert-tracks.lock /data/vhost/!!(*= $vhost *)!!/mysociety/foi/script/alert-tracks || echo "stalled?"
# Once an hour
39 * * * * !!(*= $user *)!! run-with-lockfile -n /data/vhost/!!(*= $vhost *)!!/alert-overdue-requests.lock /data/vhost/!!(*= $vhost *)!!/mysociety/foi/script/alert-overdue-requests || echo "stalled?"
diff --git a/db/migrate/050_improve_track_things.rb b/db/migrate/050_improve_track_things.rb
new file mode 100644
index 000000000..7750dcf14
--- /dev/null
+++ b/db/migrate/050_improve_track_things.rb
@@ -0,0 +1,25 @@
+class ImproveTrackThings < ActiveRecord::Migration
+ def self.up
+ add_column :track_things, :track_type, :string, :null => false
+
+ add_column :track_things, :created_at, :datetime
+ add_column :track_things, :updated_at, :datetime
+ add_column :track_things_sent_emails, :created_at, :datetime
+ add_column :track_things_sent_emails, :updated_at, :datetime
+
+ add_column :users, :last_daily_track_email, :datetime
+ User.update_all "last_daily_track_email = '2000-01-01'"
+ change_column :users, :last_daily_track_email, :datetime, :default => "2000-01-01"
+ end
+
+ def self.down
+ remove_column :track_things, :track_type
+
+ remove_column :track_things, :created_at
+ remove_column :track_things, :updated_at
+ remove_column :track_things_sent_emails, :created_at
+ remove_column :track_things_sent_emails, :updated_at
+
+ remove_column :users, :last_daily_track_email
+ end
+end
diff --git a/db/schema.rb b/db/schema.rb
index e800b916d..33e01f82d 100644
--- a/db/schema.rb
+++ b/db/schema.rb
@@ -9,7 +9,7 @@
#
# It's strongly recommended to check this file into your version control system.
-ActiveRecord::Schema.define(:version => 49) do
+ActiveRecord::Schema.define(:version => 50) do
create_table "incoming_messages", :force => true do |t|
t.integer "info_request_id", :null => false
@@ -118,19 +118,24 @@ ActiveRecord::Schema.define(:version => 49) do
add_index "sessions", ["updated_at"], :name => "index_sessions_on_updated_at"
create_table "track_things", :force => true do |t|
- t.integer "tracking_user_id", :null => false
- t.string "track_query", :null => false
- t.integer "info_request_id"
- t.integer "tracked_user_id"
- t.integer "public_body_id"
- t.string "track_medium", :null => false
+ t.integer "tracking_user_id", :null => false
+ t.string "track_query", :null => false
+ t.integer "info_request_id"
+ t.integer "tracked_user_id"
+ t.integer "public_body_id"
+ t.string "track_medium", :null => false
+ t.string "track_type", :null => false
+ t.datetime "created_at"
+ t.datetime "updated_at"
end
create_table "track_things_sent_emails", :force => true do |t|
- t.integer "track_thing_id", :null => false
- t.integer "info_request_event_id"
- t.integer "user_id"
- t.integer "public_body_id"
+ t.integer "track_thing_id", :null => false
+ t.integer "info_request_event_id"
+ t.integer "user_id"
+ t.integer "public_body_id"
+ t.datetime "created_at"
+ t.datetime "updated_at"
end
create_table "user_info_request_sent_alerts", :force => true do |t|
@@ -143,14 +148,15 @@ ActiveRecord::Schema.define(:version => 49) do
add_index "user_info_request_sent_alerts", ["user_id", "info_request_id", "alert_type"], :name => "user_info_request_sent_alerts_unique_index", :unique => true
create_table "users", :force => true do |t|
- t.string "email", :null => false
- t.string "name", :null => false
- t.string "hashed_password", :null => false
- t.string "salt", :null => false
- t.datetime "created_at", :null => false
- t.datetime "updated_at", :null => false
- t.boolean "email_confirmed", :default => false, :null => false
- t.text "url_name", :null => false
+ t.string "email", :null => false
+ t.string "name", :null => false
+ t.string "hashed_password", :null => false
+ t.string "salt", :null => false
+ t.datetime "created_at", :null => false
+ t.datetime "updated_at", :null => false
+ t.boolean "email_confirmed", :default => false, :null => false
+ t.text "url_name", :null => false
+ t.datetime "last_daily_track_email", :default => '2000-01-01 00:00:00'
end
add_index "users", ["url_name"], :name => "index_users_on_url_name", :unique => true
diff --git a/script/alert-tracks b/script/alert-tracks
new file mode 100755
index 000000000..056a88078
--- /dev/null
+++ b/script/alert-tracks
@@ -0,0 +1,7 @@
+#!/bin/bash
+
+LOC=`dirname $0`
+
+$LOC/runner 'TrackMailer.alert_tracks'
+
+
diff --git a/spec/controllers/track_controller_spec.rb b/spec/controllers/track_controller_spec.rb
new file mode 100644
index 000000000..295f9353a
--- /dev/null
+++ b/spec/controllers/track_controller_spec.rb
@@ -0,0 +1,72 @@
+require File.dirname(__FILE__) + '/../spec_helper'
+
+describe TrackController, "when making a new track on a request" do
+ integrate_views
+ fixtures :info_requests, :outgoing_messages, :incoming_messages, :info_request_events, :users
+
+ it "should render with 'track_set' template" do
+ get :track_request, :url_title => info_requests(:fancy_dog_request).url_title
+ response.should render_template('track_set')
+ end
+
+ it "should assign the title" do
+ get :track_request, :url_title => info_requests(:fancy_dog_request).url_title
+
+ assigns[:title].should include("Track the request")
+ end
+
+ it "should require login when making new track" do
+ post :track_request, :url_title => info_requests(:fancy_dog_request).url_title,
+ :track_thing => { :track_medium => "email_daily" },
+ :submitted_track => 1
+ post_redirect = PostRedirect.get_last_post_redirect
+ response.should redirect_to(:controller => 'user', :action => 'signin', :token => post_redirect.token)
+ end
+
+ it "should make track and redirect if you are logged in " do
+ TrackThing.count.should == 1
+ session[:user_id] = users(:bob_smith_user).id
+ post :track_request, :url_title => info_requests(:fancy_dog_request).url_title,
+ :track_thing => { :track_medium => "email_daily" },
+ :submitted_track => 1
+ TrackThing.count.should == 2
+ response.should redirect_to(:controller => 'request', :action => 'show', :url_title => info_requests(:fancy_dog_request).url_title)
+ end
+
+end
+
+describe TrackController, "when sending alerts for a track" do
+ integrate_views
+ fixtures :info_requests, :outgoing_messages, :incoming_messages, :info_request_events, :users, :track_things
+
+ it "should send alerts" do
+ TrackMailer.alert_tracks
+
+ deliveries = ActionMailer::Base.deliveries
+ deliveries.size.should == 1
+ mail = deliveries[0]
+ mail.body.should =~ /Alter your subscription/
+ mail.to_addrs.to_s.should include(users(:silly_name_user).email)
+ mail.body =~ /(http:\/\/.*\/c\/(.*))/
+ mail_url = $1
+ mail_token = $2
+
+ # Check subscription managing link
+# XXX reenable this if we ever have a page manager in the track controller
+# session[:user_id].should be_nil
+# controller.test_code_redirect_by_email_token(mail_token, self) # XXX hack to avoid having to call User controller for email link
+# session[:user_id].should == users(:silly_name_user).id
+#
+# response.should render_template('users/show')
+# assigns[:display_user].should == users(:silly_name_user)
+
+ # Check nothing more is delivered if we try again
+ deliveries.clear
+ TrackMailer.alert_tracks
+ deliveries = ActionMailer::Base.deliveries
+ deliveries.size.should == 0
+ end
+
+end
+
+
diff --git a/spec/fixtures/track_things.yml b/spec/fixtures/track_things.yml
new file mode 100644
index 000000000..863db3c50
--- /dev/null
+++ b/spec/fixtures/track_things.yml
@@ -0,0 +1,11 @@
+track_fancy_dog:
+ id: "10"
+ track_query: request:why_do_you_have_such_a_fancy_dog
+ track_type: request_updates
+ track_medium: email_daily
+ tracking_user_id: "2"
+ info_request_id: "101"
+ tracked_user_id:
+ public_body_id:
+ created_at: 2007-10-01 00:00:00
+ updated_at: 2007-01-01 00:00:00
diff --git a/todo.txt b/todo.txt
index a46d61637..8b2ff46af 100644
--- a/todo.txt
+++ b/todo.txt
@@ -13,7 +13,7 @@ BAILII - relationship with law courts, robots.txt ?
Next
====
-Read how Matthew's alert thang works
+Search has been done
Overdue response events, so search / RSS picks up when response is late
@@ -39,9 +39,15 @@ Consider removing login links from notifications of new responses
Later
=====
+Now that we have LinkToHelper in mailer *objects* (not classes) call out to it
+everywhere that it should
+
+"Some of the information" option should give you choice of complaining if you like.
+
Wrapping long URLs in emails breaks the h off http off the beginning nastily
Use :order in the info_request.events belongs_to clause instead of each time it is queried
+Also sort user.info_requests for user pages
Offer search on 404s
@@ -80,6 +86,9 @@ updating
Response overdue alerts are only sent first time a request goes into that state :(
Store id in alert of last event which resets the due date
+Overdue response alert email click through should show how many days overdue
+ it is near where you write your reply
+
Get deploying of Lucene search working
Consider on staging sites making follow ups go to dummy address also