aboutsummaryrefslogtreecommitdiffstats
path: root/app
diff options
context:
space:
mode:
Diffstat (limited to 'app')
-rw-r--r--app/controllers/request_controller.rb11
-rw-r--r--app/models/info_request_batch.rb26
2 files changed, 15 insertions, 22 deletions
diff --git a/app/controllers/request_controller.rb b/app/controllers/request_controller.rb
index bef3575cc..2bf1a2c0c 100644
--- a/app/controllers/request_controller.rb
+++ b/app/controllers/request_controller.rb
@@ -244,11 +244,12 @@ class RequestController < ApplicationController
return render_new_preview
end
- batch_results = InfoRequestBatch.create_batch!(params[:info_request],
- params[:outgoing_message],
- params[:public_body_ids],
- authenticated_user)
- @info_request_batch = batch_results[:batch]
+ @info_request_batch = InfoRequestBatch.create!(:title => params[:info_request][:title],
+ :body => params[:outgoing_message][:body],
+ :public_bodies => @public_bodies,
+ :user => authenticated_user )
+
+ batch_results = @info_request_batch.create_batch!
flash[:notice] = _("<p>Your {{law_used_full}} requests have been <strong>sent</strong>!</p>
<p><strong>We will email you</strong> when there is a response to any of them, or after {{late_number_of_days}} working days if the authorities still haven't
replied by then.</p>
diff --git a/app/models/info_request_batch.rb b/app/models/info_request_batch.rb
index c4075e5e4..d6227808b 100644
--- a/app/models/info_request_batch.rb
+++ b/app/models/info_request_batch.rb
@@ -29,38 +29,30 @@ class InfoRequestBatch < ActiveRecord::Base
:include => :info_requests)
end
- # Create a batch of information requests, returning the batch, and a list of public bodies
+ # Create a batch of information requests, returning a list of public bodies
# that are unrequestable from the initial list of public body ids passed.
- def InfoRequestBatch.create_batch!(info_request_params, outgoing_message_params, public_body_ids, user)
- info_request_batch = nil
+ def create_batch!
unrequestable = []
created = []
- public_bodies = PublicBody.where({:id => public_body_ids}).all
ActiveRecord::Base.transaction do
- info_request_batch = InfoRequestBatch.create!(:title => info_request_params[:title],
- :body => outgoing_message_params[:body],
- :user => user)
public_bodies.each do |public_body|
if public_body.is_requestable?
- created << info_request_batch.create_request!(public_body,
- info_request_params,
- outgoing_message_params,
- user)
+ created << create_request!(public_body)
else
unrequestable << public_body
end
end
end
created.each{ |info_request| info_request.outgoing_messages.first.send_message }
- return {:batch => info_request_batch, :unrequestable => unrequestable}
+ return {:unrequestable => unrequestable}
end
# Create and send an FOI request to a public body
- def create_request!(public_body, info_request_params, outgoing_message_params, user)
- body = OutgoingMessage.fill_in_salutation(outgoing_message_params[:body], public_body)
- info_request = InfoRequest.create_from_attributes(info_request_params,
- outgoing_message_params.merge(:body => body),
- user)
+ def create_request!(public_body)
+ body = OutgoingMessage.fill_in_salutation(self.body, public_body)
+ info_request = InfoRequest.create_from_attributes({:title => self.title},
+ {:body => body},
+ self.user)
info_request.public_body_id = public_body.id
info_request.info_request_batch = self
info_request.save!