aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--app/controllers/application.rb14
-rw-r--r--app/controllers/body_controller.rb17
-rw-r--r--app/helpers/application_helper.rb20
-rw-r--r--config/routes.rb4
-rw-r--r--todo.txt5
5 files changed, 39 insertions, 21 deletions
diff --git a/app/controllers/application.rb b/app/controllers/application.rb
index 0241ec66e..2affefa96 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.16 2007-10-24 11:39:37 francis Exp $
+# $Id: application.rb,v 1.17 2007-10-30 18:52:27 francis Exp $
class ApplicationController < ActionController::Base
@@ -138,6 +138,18 @@ class ApplicationController < ActionController::Base
return request.env["REMOTE_USER"]
end
end
+
+ # Simplified links to our objects
+ # XXX See controllers/user_controller.rb controllers/body_controller.rb for inverse
+ # XXX consolidate somehow with stuff in helpers/application_helper.rb
+ # use :helper_method => :your_method_name
+ def simplify_url_part(text)
+ text.downcase!
+ text.gsub!(/ /, "-")
+ text.gsub!(/[^a-z0-9_-]/, "")
+ text
+ end
+
end
diff --git a/app/controllers/body_controller.rb b/app/controllers/body_controller.rb
index 2027e13a1..0a267118a 100644
--- a/app/controllers/body_controller.rb
+++ b/app/controllers/body_controller.rb
@@ -4,13 +4,24 @@
# Copyright (c) 2007 UK Citizens Online Democracy. All rights reserved.
# Email: francis@mysociety.org; WWW: http://www.mysociety.org/
#
-# $Id: body_controller.rb,v 1.1 2007-10-11 22:01:36 francis Exp $
+# $Id: body_controller.rb,v 1.2 2007-10-30 18:52:27 francis Exp $
class BodyController < ApplicationController
+ # XXX tidy this up with better error messages, and a more standard infrastructure for the redirect to canonical URL
def show
- @public_bodies = PublicBody.find(:all, :conditions => [ "short_name = ?", params[:short_name] ])
+ @public_bodies = PublicBody.find(:all,
+ :conditions => [ "regexp_replace(replace(lower(short_name), ' ', '-'), '[^a-z0-9_-]', '', 'g') = ?", params[:simple_short_name] ])
if @public_bodies.size > 1
- raise "Two bodies with the same short name: " . params[:short_name]
+ raise "Two bodies with the same simplified short name: " . params[:simple_short_name]
+ end
+ # If none found, then search the history of short names, and do a redirect
+ if @public_bodies.size == 0
+ @public_bodies = PublicBody.find(:all,
+ :conditions => [ "id in (select public_body_id from public_body_versions where regexp_replace(replace(lower(short_name), ' ', '-'), '[^a-z0-9_-]', '', 'g') = ?)", params[:simple_short_name] ])
+ if @public_bodies.size > 1
+ raise "Two bodies with the same historical simplified short name: " . params[:simple_short_name]
+ end
+ redirect_to show_public_body_url(:simple_short_name => simplify_url_part(@public_bodies[0].short_name))
end
@public_body = @public_bodies[0]
end
diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb
index 495c61b61..ee0bd877e 100644
--- a/app/helpers/application_helper.rb
+++ b/app/helpers/application_helper.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: application_helper.rb,v 1.10 2007-10-30 17:31:31 francis Exp $
+# $Id: application_helper.rb,v 1.11 2007-10-30 18:52:27 francis Exp $
module ApplicationHelper
@@ -39,24 +39,20 @@ module ApplicationHelper
return date.strftime("%e %B %Y")
end
- # Simplified links to our objects
- # XXX See controllers/user_controller.rb for inverse
- def simplify_url_part(text)
- text.downcase!
- text.gsub!(/ /, "-")
- text.gsub!(/[^a-z0-9_-]/, "")
- text
- end
-
+
+ # Links to various models
+ # XXX consolidate with simplify_url_part in controllers/application.rb so
+ # ones with calls to simplify_url_part are only in one place
+
def request_link(info_request)
link_to h(info_request.title), show_request_url(:id => info_request)
end
def public_body_link_short(public_body)
- link_to h(public_body.short_name), show_public_body_url(:short_name => public_body.short_name)
+ link_to h(public_body.short_name), show_public_body_url(:simple_short_name => simplify_url_part(public_body.short_name))
end
def public_body_link(public_body)
- link_to h(public_body.name), show_public_body_url(:short_name => public_body.short_name)
+ link_to h(public_body.name), show_public_body_url(:simple_short_name => simplify_url_part(public_body.short_name))
end
def user_link(user)
diff --git a/config/routes.rb b/config/routes.rb
index 2ee97376c..66740a58a 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.18 2007-10-30 17:31:32 francis Exp $
+# $Id: routes.rb,v 1.19 2007-10-30 18:52:27 francis Exp $
ActionController::Routing::Routes.draw do |map|
# The priority is based upon order of creation: first created -> highest priority.
@@ -28,7 +28,7 @@ ActionController::Routing::Routes.draw do |map|
user.show_user "/user/:simple_name", :action => 'show'
end
- map.show_public_body "/body/:short_name", :controller => 'body', :action => 'show'
+ map.show_public_body "/body/:simple_short_name", :controller => 'body', :action => 'show'
map.connect '/admin/:action', :controller => 'admin', :action => 'index'
map.connect '/admin/body/:action/:id', :controller => 'admin_public_body'
diff --git a/todo.txt b/todo.txt
index 6e17e67d7..ae04b5130 100644
--- a/todo.txt
+++ b/todo.txt
@@ -2,9 +2,6 @@ Send confirmation email
Make it say "dear" as default letter
-Escape/simplify short name properly in URLs of public bodies
-For public bodies whose short names are renamed, make old URL still work and redirect
-
Shitty using sessions for redirect back - you lose if you click login
link elsewhere in same browser, and then do sign in on original.
It trashes your whole request.
@@ -35,6 +32,8 @@ Add SQL foreign keys to database schema
http://rubyforge.org/projects/mig-constraints/
Call "delete from sessions where now() - updated_at > 3600" (one hour) or whatever
+Do pretty error messages, e.g. on invalid public body name page etc.
+
Legal/privacy
=============