diff options
Diffstat (limited to 'app')
-rw-r--r-- | app/controllers/request_controller.rb | 13 | ||||
-rw-r--r-- | app/models/info_request_batch.rb | 12 | ||||
-rw-r--r-- | app/views/request/new.html.erb | 7 |
3 files changed, 27 insertions, 5 deletions
diff --git a/app/controllers/request_controller.rb b/app/controllers/request_controller.rb index 047fc7acf..ccf824e75 100644 --- a/app/controllers/request_controller.rb +++ b/app/controllers/request_controller.rb @@ -188,13 +188,9 @@ class RequestController < ApplicationController redirect_to select_authorities_path and return end - # TODO: I do think we should probably check for double submission of batch - # requests as we do in 'new' for ordinary requests with find_existing - # TODO: Decide if we make batch requesters describe their undescribed requests # before being able to make a new batch request - if !authenticated_user.can_file_requests? @details = authenticated_user.can_fail_html render :template => 'user/banned' and return @@ -205,12 +201,18 @@ class RequestController < ApplicationController return render_new_compose(batch=true) end + # Check for double submission of batch + @existing_batch = InfoRequestBatch.find_existing(authenticated_user, + params[:info_request][:title], + params[:outgoing_message][:body], + params[:public_body_ids]) + @info_request = InfoRequest.create_from_attributes(params[:info_request], params[:outgoing_message], authenticated_user) @outgoing_message = @info_request.outgoing_messages.first @info_request.is_batch_request_template = true - if !@info_request.valid? + if !@existing_batch.nil? || !@info_request.valid? # We don't want the error "Outgoing messages is invalid", as in this # case the list of errors will also contain a more specific error # describing the reason it is invalid. @@ -227,6 +229,7 @@ class RequestController < ApplicationController # TODO: give messages about bodies # that are no longer requestable @info_request_batch = InfoRequestBatch.create!(:title => params[:info_request][:title], + :body => params[:outgoing_message][:body], :user => authenticated_user) @public_bodies = PublicBody.where({:id => params[:public_body_ids]}).all @public_bodies.each do |public_body| diff --git a/app/models/info_request_batch.rb b/app/models/info_request_batch.rb index af6956095..05175a889 100644 --- a/app/models/info_request_batch.rb +++ b/app/models/info_request_batch.rb @@ -16,5 +16,17 @@ class InfoRequestBatch < ActiveRecord::Base validates_presence_of :user validates_presence_of :title + validates_presence_of :body + + # When constructing a new batch, use this to check user hasn't double submitted. + def InfoRequestBatch.find_existing(user, title, body, public_body_ids) + find(:first, :conditions => ['info_request_batches.user_id = ? + AND info_request_batches.title = ? + AND body = ? + AND info_requests.public_body_id in (?)', + user, title, body, public_body_ids], + :include => :info_requests) + end + end diff --git a/app/views/request/new.html.erb b/app/views/request/new.html.erb index 91171da3e..8534bf0da 100644 --- a/app/views/request/new.html.erb +++ b/app/views/request/new.html.erb @@ -33,6 +33,13 @@ </li> </ul></div> <% end %> + <% if @existing_batch %> + <div class="errorExplanation" id="errorExplanation"><ul> + <li> + <%= _('You already created the same batch of requests on {{date}}. You can either view the <a href="{{existing_batch}}">existing batch</a>, or edit the details below to make a new but similar batch of requests.', :date=>simple_date(@existing_batch.created_at), :existing_batch=>info_request_batch_path(@existing_batch)) %> + </li> + </ul></div> + <% end %> <%= foi_error_messages_for :info_request, :outgoing_message %> |