aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--app/controllers/user_controller.rb4
-rw-r--r--app/models/post_redirect.rb7
-rw-r--r--app/views/user/bad_token.rhtml11
-rw-r--r--config/crontab.ugly14
-rw-r--r--db/migrate/031_add_indices_for_session_deletion.rb9
-rw-r--r--db/schema.rb3
-rwxr-xr-xscript/delete-old-sessions8
-rw-r--r--todo.txt5
8 files changed, 49 insertions, 12 deletions
diff --git a/app/controllers/user_controller.rb b/app/controllers/user_controller.rb
index a8aa472c0..4aad19cd4 100644
--- a/app/controllers/user_controller.rb
+++ b/app/controllers/user_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: user_controller.rb,v 1.23 2008-01-10 18:20:35 francis Exp $
+# $Id: user_controller.rb,v 1.24 2008-02-12 11:42:09 francis Exp $
class UserController < ApplicationController
# XXX See controllers/application.rb simplify_url_part for reverse of expression in SQL below
@@ -67,7 +67,7 @@ class UserController < ApplicationController
post_redirect = PostRedirect.find_by_email_token(params[:email_token])
if post_redirect.nil?
- render 'user/bad_token'
+ render :template => 'user/bad_token.rhtml'
return
end
diff --git a/app/models/post_redirect.rb b/app/models/post_redirect.rb
index f98591c44..5227c64d0 100644
--- a/app/models/post_redirect.rb
+++ b/app/models/post_redirect.rb
@@ -25,7 +25,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.15 2008-02-06 09:41:44 francis Exp $
+# $Id: post_redirect.rb,v 1.16 2008-02-12 11:42:09 francis Exp $
require 'openssl' # for random bytes function
@@ -84,6 +84,11 @@ class PostRedirect < ActiveRecord::Base
return post_redirects[0]
end
+ # Called from cron job delete-old-sessions
+ def self.delete_old_post_redirects
+ PostRedirect.delete_all "now() - updated_at > '1 year'"
+ end
+
end
diff --git a/app/views/user/bad_token.rhtml b/app/views/user/bad_token.rhtml
index d47a3c8bd..bfdfc1a55 100644
--- a/app/views/user/bad_token.rhtml
+++ b/app/views/user/bad_token.rhtml
@@ -4,9 +4,14 @@ correctly from your email.
</p>
<p id="bad_token">
-If you can't click on it in the email, you'll have
-to select and copy it from the email. Then paste it into your browser, into
-the place you would type the address of any other webpage.
+If you can't click on it in the email, you'll have to select and copy it from
+the email. Then paste it into your browser, into the place you would type the
+address of any other webpage.
+</p>
+
+<p id="bad_token">
+If you got the email more than a year ago, then this login link won't work any
+more. Please try doing what you were doing from the beginning.
</p>
diff --git a/config/crontab.ugly b/config/crontab.ugly
new file mode 100644
index 000000000..e9822b7cd
--- /dev/null
+++ b/config/crontab.ugly
@@ -0,0 +1,14 @@
+# crontab.ugly:
+# Timed tasks for FOI site. Template file.
+#
+# Copyright (c) 2008 UK Citizens Online Democracy. All rights reserved.
+# Email: francis@mysociety.org. WWW: http://www.mysociety.org/
+#
+# $Id: crontab.ugly,v 1.1 2008-02-12 11:42:10 francis Exp $
+
+PATH=/usr/local/bin:/usr/bin:/bin
+MAILTO=team@mysociety.org
+
+# Once a day, early morning
+23 4 * * * !!(*= $user *)!! run-with-lockfile -n /data/vhost/!!(*= $vhost *)!!//delete-old-sessions.lock /data/vhost/!!(*= $vhost *)!!/mysociety/foi/scripts/delete-old-sessions || echo "stalled?"
+
diff --git a/db/migrate/031_add_indices_for_session_deletion.rb b/db/migrate/031_add_indices_for_session_deletion.rb
new file mode 100644
index 000000000..9a6f6b326
--- /dev/null
+++ b/db/migrate/031_add_indices_for_session_deletion.rb
@@ -0,0 +1,9 @@
+class AddIndicesForSessionDeletion < ActiveRecord::Migration
+ def self.up
+ add_index :post_redirects, :updated_at
+ end
+
+ def self.down
+ remove_index :post_redirects, :updated_at
+ end
+end
diff --git a/db/schema.rb b/db/schema.rb
index 07e62f893..72e075da7 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 => 30) do
+ActiveRecord::Schema.define(:version => 31) do
create_table "incoming_messages", :force => true do |t|
t.integer "info_request_id", :null => false
@@ -64,6 +64,7 @@ ActiveRecord::Schema.define(:version => 30) do
add_index "post_redirects", ["email_token"], :name => "index_post_redirects_on_email_token"
add_index "post_redirects", ["token"], :name => "index_post_redirects_on_token"
+ add_index "post_redirects", ["updated_at"], :name => "index_post_redirects_on_updated_at"
create_table "public_bodies", :force => true do |t|
t.text "name", :null => false
diff --git a/script/delete-old-sessions b/script/delete-old-sessions
new file mode 100755
index 000000000..0e4c91122
--- /dev/null
+++ b/script/delete-old-sessions
@@ -0,0 +1,8 @@
+#!/bin/bash
+
+LOC=`dirname $0`
+
+$LOC/runner 'PostRedirect.delete_old_post_redirects()'
+$LOC/runner "ActiveRecord::Base.connection.execute(\"delete from sessions where now() - updated_at > '1 month'\")"
+
+
diff --git a/todo.txt b/todo.txt
index 6b20cc337..6a648324c 100644
--- a/todo.txt
+++ b/todo.txt
@@ -59,17 +59,12 @@ Consider removing login links from notifications of new responses
Tidying
=======
-Test that it is actually sending the request outgoing mail, by using deliveries
-Test sending a message to bounce/envelope-from address
-
Add SQL foreign keys to database schema (THIS IS IMPORTANT, or things will screw up)
execute 'ALTER TABLE researchers ADD CONSTRAINT fk_researchers_departments FOREIGN KEY ( department_id ) REFERENCES departments( id ) '
http://wiki.rubyonrails.org/rails/pages/UsingMigrations link to:
http://www.surfdewey.com/2.html
http://www.redhillconsulting.com.au/rails_plugins.html#foreign_key_migrations
http://rubyforge.org/projects/mig-constraints/
-Call "delete from sessions where now() - updated_at > 3600" (one hour) or whatever
-Also delete old post_redirects (and similar)
Mark some requests as test requests