diff options
Diffstat (limited to 'app')
-rw-r--r-- | app/controllers/request_controller.rb | 14 | ||||
-rw-r--r-- | app/helpers/link_to_helper.rb | 18 | ||||
-rw-r--r-- | app/views/request/new.rhtml | 11 |
3 files changed, 39 insertions, 4 deletions
diff --git a/app/controllers/request_controller.rb b/app/controllers/request_controller.rb index 72042138c..bc03fd539 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.26 2008-01-03 12:54:40 francis Exp $ +# $Id: request_controller.rb,v 1.27 2008-01-04 10:56:22 francis Exp $ class RequestController < ApplicationController @@ -32,6 +32,13 @@ class RequestController < ApplicationController # Page new form posts to def create + # See if the exact same request has already been submitted + # XXX this *should* also check outgoing message joined to is an initial request (rather than follow up) + # XXX this check could go in the model, except we really want to pass @existing_request to the view so it can link to it. + # XXX could have a date range here, so say only check last month's worth of new requests. If somebody is making + # repeated requests, say once a quarter for time information, then might need to do that. + @existing_request = InfoRequest.find(:first, :conditions => [ 'title = ? and public_body_id = ? and outgoing_messages.body = ?', params[:info_request][:title], params[:info_request][:public_body_id], params[:outgoing_message][:body] ], :include => [ :outgoing_messages ] ) + # Create both FOI request and the first request message @info_request = InfoRequest.new(params[:info_request]) @outgoing_message = OutgoingMessage.new(params[:outgoing_message].merge({ @@ -41,8 +48,8 @@ class RequestController < ApplicationController @info_request.outgoing_messages << @outgoing_message @outgoing_message.info_request = @info_request - # This automatically saves dependent objects, such as @info_request, in the same transaction - if not @info_request.valid? + # See if values were valid or not + if !@existing_request.nil? || !@info_request.valid? render :action => 'new' elsif authenticated?( :web => "To send your FOI request", @@ -50,6 +57,7 @@ class RequestController < ApplicationController :email_subject => "Confirm that you want to send an FOI request to " + @info_request.public_body.name ) @info_request.user = authenticated_user + # This automatically saves dependent objects, such as @outgoing_message, in the same transaction @info_request.save! @outgoing_message.send_message flash[:notice] = "Your Freedom of Information request has been created and sent on its way." diff --git a/app/helpers/link_to_helper.rb b/app/helpers/link_to_helper.rb index 41a462280..b26c7d020 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.7 2008-01-02 20:18:06 francis Exp $ +# $Id: link_to_helper.rb,v 1.8 2008-01-04 10:56:22 francis Exp $ module LinkToHelper @@ -36,6 +36,22 @@ module LinkToHelper def user_link(user) link_to h(user.name), user_url(user) end + def user_or_you_link(user) + if @user && user == @user + link_to h("you"), user_url(user) + else + link_to h(user.name), user_url(user) + end + end + def user_or_you_capital_link(user) + if @user && user == @user + link_to h("You"), user_url(user) + else + link_to h(user.name), user_url(user) + end + end + + def info_request_link(info_request) link_to h(info_request.title), show_request_url(:id => info_request) diff --git a/app/views/request/new.rhtml b/app/views/request/new.rhtml index 8fcc43c90..8621fdf9e 100644 --- a/app/views/request/new.rhtml +++ b/app/views/request/new.rhtml @@ -1,5 +1,16 @@ <% @title = "New FOI request" %> +<% if @existing_request %> + <div class="errorExplanation" id="errorExplanation"><ul> + <li> + <%= user_or_you_capital_link(@existing_request.user) %> already + created the same request on <%=simple_date(@existing_request.created_at)%>. + You can either view the <a href="<%=request_url(@existing_request)%>">existing request</a>, + or edit the details below to make a new but similar request. + </li> + </ul></div> +<% end %> + <%= foi_error_messages_for :info_request, :outgoing_message %> <% form_for(:info_request, @info_request, :url => { :action => :create }, :html => { :id => 'writeForm' } ) do |f| %> |