diff options
-rw-r--r-- | app/controllers/request_controller.rb | 78 | ||||
-rw-r--r-- | app/views/request/new.html.erb | 2 | ||||
-rw-r--r-- | app/views/request/preview.html.erb | 16 | ||||
-rw-r--r-- | spec/controllers/request_controller_spec.rb | 29 |
4 files changed, 102 insertions, 23 deletions
diff --git a/app/controllers/request_controller.rb b/app/controllers/request_controller.rb index d47e986b0..52f62d58d 100644 --- a/app/controllers/request_controller.rb +++ b/app/controllers/request_controller.rb @@ -184,11 +184,51 @@ class RequestController < ApplicationController end def new_batch + + # TODO: Check that have at least one public body in public_bodies param + + # TODO: Pass public bodies list through new and preview template forms + + # TODO: I don't think batch requesters should be subject to rate limits, + # but I do think we should probably check for double submission of batch + # requests as we do in 'new' for ordinary requests with find_by_existing_request + + # TODO: Decide if we make batch requesters describe their undescribed requests + # before being able to make a new batch request + + # TODO: Add logic for checking if the user is banned + @batch = true if params[:submitted_new_request].nil? || params[:reedit] return render_new_compose(batch=true) end + @info_request = InfoRequest.new(params[:info_request]) + @info_request.is_batch_request_template = true + @outgoing_message = OutgoingMessage.new(params[:outgoing_message].merge({ + :status => 'ready', + :message_type => 'initial_request', + :what_doing => 'normal_sort' + })) + @info_request.outgoing_messages << @outgoing_message + @outgoing_message.info_request = @info_request + @info_request.user = authenticated_user + if !@info_request.valid? + # TODO: add in code from 'new' for removing spurious extra + # "Outgoing messages is invalid" message - move to model? + render :action => 'new' + return + end + + # Show preview page, if it is a preview + if params[:preview].to_i == 1 + return render_new_preview + end + + # TODO: create info requests and associated outgoing messages from this + # template request, and send those that can be sent, giving messages about bodies + # that are no longer requestable + end # Page new form posts to @@ -272,24 +312,7 @@ class RequestController < ApplicationController # Show preview page, if it is a preview if params[:preview].to_i == 1 - message = "" - if @outgoing_message.contains_email? - if @user.nil? - message += _("<p>You do not need to include your email in the request in order to get a reply, as we will ask for it on the next screen (<a href=\"{{url}}\">details</a>).</p>", :url => (help_privacy_path+"#email_address").html_safe); - else - message += _("<p>You do not need to include your email in the request in order to get a reply (<a href=\"{{url}}\">details</a>).</p>", :url => (help_privacy_path+"#email_address").html_safe); - end - message += _("<p>We recommend that you edit your request and remove the email address. - If you leave it, the email address will be sent to the authority, but will not be displayed on the site.</p>") - end - if @outgoing_message.contains_postcode? - message += _("<p>Your request contains a <strong>postcode</strong>. Unless it directly relates to the subject of your request, please remove any address as it will <strong>appear publicly on the Internet</strong>.</p>"); - end - if not message.empty? - flash.now[:error] = message.html_safe - end - render :action => 'preview' - return + return render_new_preview end if user_exceeded_limit @@ -1013,5 +1036,24 @@ class RequestController < ApplicationController return end + def render_new_preview + message = "" + if @outgoing_message.contains_email? + if @user.nil? + message += _("<p>You do not need to include your email in the request in order to get a reply, as we will ask for it on the next screen (<a href=\"{{url}}\">details</a>).</p>", :url => (help_privacy_path+"#email_address").html_safe); + else + message += _("<p>You do not need to include your email in the request in order to get a reply (<a href=\"{{url}}\">details</a>).</p>", :url => (help_privacy_path+"#email_address").html_safe); + end + message += _("<p>We recommend that you edit your request and remove the email address. + If you leave it, the email address will be sent to the authority, but will not be displayed on the site.</p>") + end + if @outgoing_message.contains_postcode? + message += _("<p>Your request contains a <strong>postcode</strong>. Unless it directly relates to the subject of your request, please remove any address as it will <strong>appear publicly on the Internet</strong>.</p>"); + end + if not message.empty? + flash.now[:error] = message.html_safe + end + render :action => 'preview' + end end diff --git a/app/views/request/new.html.erb b/app/views/request/new.html.erb index 7b7ede79f..cce6c1397 100644 --- a/app/views/request/new.html.erb +++ b/app/views/request/new.html.erb @@ -36,7 +36,7 @@ <%= foi_error_messages_for :info_request, :outgoing_message %> - <%= form_for(@info_request, :url => new_request_path, :html => { :id => 'write_form' } ) do |f| %> + <%= form_for(@info_request, :url => (@batch ? new_batch_path : new_request_path), :html => { :id => 'write_form' } ) do |f| %> <div id="request_header"> <div id="request_header_body"> diff --git a/app/views/request/preview.html.erb b/app/views/request/preview.html.erb index 243dc90a9..a5c9a8a60 100644 --- a/app/views/request/preview.html.erb +++ b/app/views/request/preview.html.erb @@ -1,6 +1,9 @@ -<% @title = "Preview new " + h(@info_request.law_used_short) + " request to '" + h(@info_request.public_body.name) + "'" %> - -<%= form_for(@info_request, :url => new_request_path, :html => { :id => 'preview_form' } ) do |f| %> +<% if @batch %> + <% @title = _("Preview new {{law_used_short}} request", :law_used_short => h(@info_request.law_used_short)) %> +<% else %> + <% @title = _("Preview new {{law_used_short}} request to '{{public_body_name}}", :law_used_short => h(@info_request.law_used_short), :public_body_name => h(@info_request.public_body.name)) %> +<% end %> +<%= form_for(@info_request, :url => (@batch ? new_batch_path : new_request_path), :html => { :id => 'preview_form' } ) do |f| %> <h1><%= _('3. Now check your request') %></h1> <ul> @@ -14,7 +17,12 @@ <div class="correspondence" id="outgoing-0"> <p class="preview_subject"> - <strong><%= _('To:') %></strong> <%=h @info_request.public_body.name %> + <strong><%= _('To:') %></strong> + <% if @batch %> + <%= _("Your selected authorities")%> + <% else %> + <%=h(@info_request.public_body.name)%> + <% end %> <br><strong><%= _('Subject:') %></strong> <%=h @info_request.email_subject_request %> </p> diff --git a/spec/controllers/request_controller_spec.rb b/spec/controllers/request_controller_spec.rb index 2e928eb3b..d92eb6aa2 100644 --- a/spec/controllers/request_controller_spec.rb +++ b/spec/controllers/request_controller_spec.rb @@ -2533,6 +2533,35 @@ describe RequestController, "#new_batch", :focus => true do response.should render_template('request/new') end + + it "should render 'preview' when given a good title and body" do + + post :new_batch, { :info_request => { :title => "What does it all mean?", + :tag_string => "" }, + :outgoing_message => { :body => "This is a silly letter." }, + :submitted_new_request => 1, + :preview => 1 }, { :user_id => @user.id } + response.should render_template('preview') + end + + it "should give an error and render 'new' template when a summary isn't given" do + post :new_batch, { :info_request => { :tag_string => "" }, + :outgoing_message => { :body => "This is a silly letter." }, + :submitted_new_request => 1, + :preview => 1 }, { :user_id => @user.id } + assigns[:info_request].errors[:title].should == ['Please enter a summary of your request'] + response.should render_template('new') + end + + it "should allow re-editing of a request" do + post :new_batch, { :info_request => { :tag_string => "" }, + :outgoing_message => { :body => "This is a silly letter." }, + :submitted_new_request => 1, + :preview => 0, + :reedit => 1}, { :user_id => @user.id } + response.should render_template('new') + end + end context "when the current user can't make batch requests" do |