From 282cebc96cb9548e5af3f2ee7c635c39da4bdbce Mon Sep 17 00:00:00 2001 From: Louise Crow Date: Tue, 24 Sep 2013 18:14:35 +0100 Subject: Add a batch_request_template flag A virtual attribute to use to customise some info request behaviours when we are using one request as a template for creating multiple requests. --- app/models/info_request.rb | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'app/models/info_request.rb') diff --git a/app/models/info_request.rb b/app/models/info_request.rb index 0a073dc79..aaed99d81 100644 --- a/app/models/info_request.rb +++ b/app/models/info_request.rb @@ -40,7 +40,7 @@ class InfoRequest < ActiveRecord::Base validate :must_be_internal_or_external belongs_to :public_body, :counter_cache => true - validates_presence_of :public_body_id + validates_presence_of :public_body_id, :unless => Proc.new { |info_request| info_request.is_batch_request_template? } has_many :outgoing_messages, :order => 'created_at' has_many :incoming_messages, :order => 'created_at' @@ -50,6 +50,7 @@ class InfoRequest < ActiveRecord::Base has_many :comments, :order => 'created_at' has_many :censor_rules, :order => 'created_at desc' has_many :mail_server_logs, :order => 'mail_server_log_done_id' + attr_accessor :is_batch_request_template has_tag_string @@ -122,6 +123,10 @@ class InfoRequest < ActiveRecord::Base !InfoRequest.enumerate_states.include? described_state end + def is_batch_request_template? + is_batch_request_template == true + end + # The request must either be internal, in which case it has # a foreign key reference to a User object and no external_url or external_user_name, # or else be external in which case it has no user_id but does have an external_url, -- cgit v1.2.3 From 0028d63dce4db36fcb0877770c67131b652d3cfd Mon Sep 17 00:00:00 2001 From: Louise Crow Date: Tue, 24 Sep 2013 18:40:09 +0100 Subject: Handle the application of censor rules to a batch request template. --- app/models/info_request.rb | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'app/models/info_request.rb') diff --git a/app/models/info_request.rb b/app/models/info_request.rb index aaed99d81..a79ede809 100644 --- a/app/models/info_request.rb +++ b/app/models/info_request.rb @@ -1079,7 +1079,10 @@ public # Get the list of censor rules that apply to this request def applicable_censor_rules - applicable_rules = [self.censor_rules, self.public_body.censor_rules, CensorRule.global.all] + applicable_rules = [self.censor_rules, CensorRule.global.all] + unless is_batch_request_template? + applicable_rules << self.public_body.censor_rules + end if self.user && !self.user.censor_rules.empty? applicable_rules << self.user.censor_rules end -- cgit v1.2.3 From 9a5c01d781129aeb1ab2b18771ac131ecdfb56c1 Mon Sep 17 00:00:00 2001 From: Louise Crow Date: Thu, 24 Oct 2013 14:35:25 +0100 Subject: Add InfoRequestBatch model. Re-annotate models. Index InfoRequestBatches by user - we'll display the batches for a user when they view their own requests. --- app/models/info_request.rb | 3 +++ 1 file changed, 3 insertions(+) (limited to 'app/models/info_request.rb') diff --git a/app/models/info_request.rb b/app/models/info_request.rb index a79ede809..3c3afe0ea 100644 --- a/app/models/info_request.rb +++ b/app/models/info_request.rb @@ -1,5 +1,6 @@ # encoding: utf-8 # == Schema Information +# Schema version: 20131024114346 # # Table name: info_requests # @@ -21,6 +22,7 @@ # external_url :string(255) # attention_requested :boolean default(FALSE) # comments_allowed :boolean default(TRUE), not null +# info_request_batch_id :integer # require 'digest/sha1' @@ -40,6 +42,7 @@ class InfoRequest < ActiveRecord::Base validate :must_be_internal_or_external belongs_to :public_body, :counter_cache => true + belongs_to :info_request_batch validates_presence_of :public_body_id, :unless => Proc.new { |info_request| info_request.is_batch_request_template? } has_many :outgoing_messages, :order => 'created_at' -- cgit v1.2.3 From cf11b959899d54cf3c7f4e018f11c2c89c83d4af Mon Sep 17 00:00:00 2001 From: Louise Crow Date: Thu, 24 Oct 2013 16:00:10 +0100 Subject: Simple code for the happy path Create the batch and associate new requests with it, send the outgoing messages, and redirect to a page for the new batch. --- app/models/info_request.rb | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'app/models/info_request.rb') diff --git a/app/models/info_request.rb b/app/models/info_request.rb index 3c3afe0ea..b990f4b41 100644 --- a/app/models/info_request.rb +++ b/app/models/info_request.rb @@ -936,6 +936,20 @@ public self.idhash = InfoRequest.hash_from_id(self.id) end + def InfoRequest.create_from_attributes(info_request_atts, outgoing_message_atts, user=nil) + info_request = new(info_request_atts) + default_message_params = { + :status => 'ready', + :message_type => 'initial_request', + :what_doing => 'normal_sort' + } + outgoing_message = OutgoingMessage.new(outgoing_message_atts.merge(default_message_params)) + info_request.outgoing_messages << outgoing_message + outgoing_message.info_request = info_request + info_request.user = user + info_request + end + def InfoRequest.hash_from_id(id) return Digest::SHA1.hexdigest(id.to_s + AlaveteliConfiguration::incoming_email_secret)[0,8] end -- cgit v1.2.3 From 4b2e3ef0b6f5b881597242a4afe1404415256f3b Mon Sep 17 00:00:00 2001 From: Louise Crow Date: Thu, 24 Oct 2013 16:19:22 +0100 Subject: Make method names for finding existing objects clearer They're not finding by the existing object, they're finding an existing object. --- app/models/info_request.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'app/models/info_request.rb') diff --git a/app/models/info_request.rb b/app/models/info_request.rb index b990f4b41..c95b7427e 100644 --- a/app/models/info_request.rb +++ b/app/models/info_request.rb @@ -387,7 +387,7 @@ public # repeated requests, say once a quarter for time information, then might need to do that. # XXX this *should* also check outgoing message joined to is an initial # request (rather than follow up) - def InfoRequest.find_by_existing_request(title, public_body_id, body) + def InfoRequest.find_existing(title, public_body_id, body) return InfoRequest.find(:first, :conditions => [ "title = ? and public_body_id = ? and outgoing_messages.body = ?", title, public_body_id, body ], :include => [ :outgoing_messages ] ) end -- cgit v1.2.3