aboutsummaryrefslogtreecommitdiffstats
path: root/app
diff options
context:
space:
mode:
Diffstat (limited to 'app')
-rw-r--r--app/controllers/body_controller.rb7
-rw-r--r--app/controllers/request_controller.rb32
-rw-r--r--app/controllers/user_controller.rb5
-rw-r--r--app/helpers/link_to_helper.rb10
-rw-r--r--app/models/info_request.rb20
-rw-r--r--app/models/request_mailer.rb4
-rw-r--r--app/views/admin_request/list.rhtml6
7 files changed, 57 insertions, 27 deletions
diff --git a/app/controllers/body_controller.rb b/app/controllers/body_controller.rb
index 6ad713455..103b500b8 100644
--- a/app/controllers/body_controller.rb
+++ b/app/controllers/body_controller.rb
@@ -4,11 +4,16 @@
# 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.6 2008-02-27 12:09:03 francis Exp $
+# $Id: body_controller.rb,v 1.7 2008-02-27 13:59:51 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
+ if MySociety::Format.simplify_url_part(params[:url_name]) != params[:url_name]
+ redirect_to :url_name => MySociety::Format.simplify_url_part(params[:url_name])
+ return
+ end
+
@public_bodies = PublicBody.find(:all,
:conditions => [ "url_name = ?", params[:url_name] ])
if @public_bodies.size > 1
diff --git a/app/controllers/request_controller.rb b/app/controllers/request_controller.rb
index 3d7e1c869..d02694183 100644
--- a/app/controllers/request_controller.rb
+++ b/app/controllers/request_controller.rb
@@ -4,12 +4,22 @@
# 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.59 2008-02-25 11:17:29 francis Exp $
+# $Id: request_controller.rb,v 1.60 2008-02-27 13:59:51 francis Exp $
class RequestController < ApplicationController
def show
- @info_request = InfoRequest.find(params[:id])
+ # Look up by old style numeric identifiers
+ if params[:url_title].match(/^[0-9]+$/)
+ @info_request = InfoRequest.find(params[:url_title].to_i)
+ redirect_to request_url(@info_request)
+ return
+ end
+
+ # Look up by new style text names
+ @info_request = InfoRequest.find_by_url_title(params[:url_title])
+
+ # Other parameters
@info_request_events = @info_request.info_request_events
@info_request_events.sort! { |a,b| a.created_at <=> b.created_at }
@status = @info_request.calculate_status
@@ -110,7 +120,7 @@ class RequestController < ApplicationController
# XXX send_message needs the database id, so we send after saving, which isn't ideal if the request broke here.
@outgoing_message.send_message
flash[:notice] = "Your Freedom of Information request has been created and sent on its way."
- redirect_to show_request_url(:id => @info_request)
+ redirect_to show_request_url(:url_title => @info_request.url_title)
else
# do nothing - as "authenticated?" has done the redirect to signin page for us
end
@@ -125,7 +135,7 @@ class RequestController < ApplicationController
if !params[:submitted_describe_state].nil?
flash[:notice] = "The status of this request was made up to date elsewhere while you were filling in the form."
end
- redirect_to show_request_url(:id => @info_request)
+ redirect_to show_request_url(:url_title => @info_request.url_title)
return
end
@@ -137,7 +147,7 @@ class RequestController < ApplicationController
if @last_info_request_event_id.nil?
flash[:notice] = "Internal error - awaiting description, but no event to describe"
- redirect_to show_request_url(:id => @info_request)
+ redirect_to show_request_url(:url_title => @info_request.url_title)
return
end
@@ -169,10 +179,10 @@ class RequestController < ApplicationController
# Display appropriate next page (e.g. help for complaint etc.)
if @info_request.calculate_status == 'waiting_response'
flash[:notice] = "<p>Thank you! Hopefully your wait isn't too long.</p> <p>By law, you should get a response before the end of <strong>" + simple_date(@info_request.date_response_required_by) + "</strong>.</p>"
- redirect_to show_request_url(:id => @info_request)
+ redirect_to show_request_url(:url_title => @info_request.url_title)
elsif @info_request.calculate_status == 'waiting_response_overdue'
flash[:notice] = "<p>Thank you! Hope you don't have to wait much longer.</p> <p>By law, you should have got a response before the end of <strong>" + simple_date(@info_request.date_response_required_by) + "</strong>.</p>"
- redirect_to show_request_url(:id => @info_request)
+ redirect_to show_request_url(:url_title => @info_request.url_title)
elsif @info_request.calculate_status == 'rejected'
# XXX explain how to complain
flash[:notice] = "Oh no! Sorry to hear that your request was rejected. Here is what to do now."
@@ -180,17 +190,17 @@ class RequestController < ApplicationController
elsif @info_request.calculate_status == 'successful'
flash[:notice] = "We're glad you got all the information that you wanted. Thank you for using foi.mysociety.org"
# XXX quiz them here for a comment
- redirect_to show_request_url(:id => @info_request)
+ redirect_to show_request_url(:url_title => @info_request.url_title)
elsif @info_request.calculate_status == 'partially_successful'
flash[:notice] = "We're glad you got some of the information that you wanted."
# XXX explain how to complain / quiz them for a comment
- redirect_to show_request_url(:id => @info_request)
+ redirect_to show_request_url(:url_title => @info_request.url_title)
elsif @info_request.calculate_status == 'waiting_clarification'
flash[:notice] = "Please write your follow up message containing the necessary clarifications below."
redirect_to show_response_url(:id => @info_request.id, :incoming_message_id => @events_needing_description[-1].params[:incoming_message_id])
elsif @info_request.calculate_status == 'requires_admin'
flash[:notice] = "Thanks! The foi.mysociety.org team have been notified."
- redirect_to show_request_url(:id => @info_request)
+ redirect_to show_request_url(:url_title => @info_request.url_title)
else
raise "unknown calculate_status " + @info_request.calculate_status
end
@@ -242,7 +252,7 @@ class RequestController < ApplicationController
@outgoing_message.send_message
@outgoing_message.save!
flash[:notice] = "Your follow up message has been created and sent on its way."
- redirect_to show_request_url(:id => @info_request)
+ redirect_to show_request_url(:url_title => @info_request.url_title)
else
# do nothing - as "authenticated?" has done the redirect to signin page for us
end
diff --git a/app/controllers/user_controller.rb b/app/controllers/user_controller.rb
index 50f8ece10..94fe731ba 100644
--- a/app/controllers/user_controller.rb
+++ b/app/controllers/user_controller.rb
@@ -4,13 +4,14 @@
# 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.29 2008-02-27 12:20:22 francis Exp $
+# $Id: user_controller.rb,v 1.30 2008-02-27 13:59:52 francis Exp $
class UserController < ApplicationController
# Show page about a set of users with same url name
def show
- if MySociety::Format.simplify_url_part(params[:url_name]) != params[:url_name]
+ if MySociety::Format.simplify_url_part(params[:url_name]) != params[:url_name]
redirect_to :url_name => MySociety::Format.simplify_url_part(params[:url_name])
+ return
end
@display_users = User.find(:all, :conditions => [ "url_name = ?", params[:url_name] ], :order => "created_at desc")
diff --git a/app/helpers/link_to_helper.rb b/app/helpers/link_to_helper.rb
index 8d4a1baca..6d57ed353 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.18 2008-02-27 12:18:28 francis Exp $
+# $Id: link_to_helper.rb,v 1.19 2008-02-27 13:59:52 francis Exp $
module LinkToHelper
@@ -13,7 +13,7 @@ module LinkToHelper
# Requests
def request_url(info_request)
- return show_request_url(:id => info_request, :only_path => true)
+ return show_request_url(:url_title => info_request.url_title, :only_path => true)
end
def request_link(info_request)
link_to h(info_request.title), request_url(info_request)
@@ -74,11 +74,7 @@ module LinkToHelper
end
- def info_request_link(info_request)
- link_to h(info_request.title), show_request_url(:id => info_request)
- end
-
-
+ # Admin pages
def admin_url(relative_path)
admin_url_prefix = MySociety::Config.get("ADMIN_BASE_URL", "/admin/")
return admin_url_prefix + relative_path
diff --git a/app/models/info_request.rb b/app/models/info_request.rb
index 72bbf8b6a..c6dc88aea 100644
--- a/app/models/info_request.rb
+++ b/app/models/info_request.rb
@@ -20,12 +20,13 @@
# 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.47 2008-02-27 12:04:10 francis Exp $
+# $Id: info_request.rb,v 1.48 2008-02-27 13:59:52 francis Exp $
require 'digest/sha1'
class InfoRequest < ActiveRecord::Base
validates_presence_of :title, :message => "^Please enter a summary of your request"
+ validates_format_of :title, :with => /[a-z]/, :message => "^Please write a summary with some text in it", :if => Proc.new { |info_request| !info_request.title.nil? && !info_request.title.empty? }
belongs_to :user
#validates_presence_of :user_id # breaks during construction of new ones :(
@@ -62,6 +63,23 @@ class InfoRequest < ActiveRecord::Base
end
public
+ # When name is changed, also change the url name
+ def title=(title)
+ write_attribute(:title, title)
+ self.update_url_title
+ end
+ def update_url_title
+ url_title = MySociety::Format.simplify_url_part(self.title)
+ if url_title.size > 32
+ url_title = url_title[0..31]
+ end
+ # For request with same name as others, tag on the request numeric id
+ while not InfoRequest.find_by_url_title(url_title).nil?
+ url_title += "-" + self.id.to_s
+ end
+ write_attribute(:url_title, url_title)
+ end
+
# Email which public body should use to respond to request. This is in
# the format PREFIXrequest-ID-HASH@DOMAIN. Here ID is the id of the
# FOI request, and HASH is a signature for that id.
diff --git a/app/models/request_mailer.rb b/app/models/request_mailer.rb
index 20ac78b70..d4f85659b 100644
--- a/app/models/request_mailer.rb
+++ b/app/models/request_mailer.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_mailer.rb,v 1.23 2008-02-22 01:58:36 francis Exp $
+# $Id: request_mailer.rb,v 1.24 2008-02-27 13:59:52 francis Exp $
class RequestMailer < ApplicationMailer
@@ -55,7 +55,7 @@ class RequestMailer < ApplicationMailer
@recipients = @from
@subject = "Unusual FOI response, requires admin attention"
# XXX these are repeats of things in helpers/link_to_helper.rb, and shouldn't be
- url = show_request_url(:id => info_request)
+ url = show_request_url(:url_title => info_request.url_title)
admin_url = MySociety::Config.get("ADMIN_BASE_URL", "/admin/") + 'request/show/' + info_request.id.to_s
@body = {:info_request => info_request, :url => url, :admin_url => admin_url }
end
diff --git a/app/views/admin_request/list.rhtml b/app/views/admin_request/list.rhtml
index 9472ac8c1..0ffd07d0e 100644
--- a/app/views/admin_request/list.rhtml
+++ b/app/views/admin_request/list.rhtml
@@ -4,15 +4,15 @@
<table>
<tr>
- <% for column in InfoRequest.content_columns %>
- <th><%= column.human_name %></th>
+ <% for column in InfoRequest.content_columns.map { |c| c.human_name } - [ "Url title" ] %>
+ <th><%= column %></th>
<% end %>
</tr>
<% for info_request in @info_requests %>
<tr class="<%= cycle('odd', 'even') %>">
<td><%= link_to h(info_request.title), 'show/' + info_request.id.to_s %></td>
- <% for column in InfoRequest.content_columns.map { |c| c.name } - [ "title" ] %>
+ <% for column in InfoRequest.content_columns.map { |c| c.name } - [ "title", "url_title" ] %>
<td><%=h info_request.send(column) %></td>
<% end %>
</tr>