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 From df0583a94c6a3ce7ded818cb46688b7edc928302 Mon Sep 17 00:00:00 2001 From: Louise Crow Date: Wed, 11 Dec 2013 14:28:23 +0000 Subject: Cache frequently accessed request lists. Make specs a bit more focused, remove view specs - they're not relevant to the new code in their current form and don't seem to merit updating. --- app/models/info_request.rb | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) (limited to 'app/models/info_request.rb') diff --git a/app/models/info_request.rb b/app/models/info_request.rb index 0a073dc79..4624cefaf 100644 --- a/app/models/info_request.rb +++ b/app/models/info_request.rb @@ -1228,6 +1228,23 @@ public return [xapian_similar, xapian_similar_more] end + def InfoRequest.request_list(filters, page, per_page, max_results) + xapian_object = ActsAsXapian::Search.new([InfoRequestEvent], + InfoRequestEvent.make_query_from_params(filters), + :offset => (page - 1) * per_page, + :limit => 25, + :sort_by_prefix => 'created_at', + :sort_by_ascending => true, + :collapse_by_prefix => 'request_collapse' + ) + list_results = xapian_object.results.map { |r| r[:model] } + matches_estimated = xapian_object.matches_estimated + show_no_more_than = [matches_estimated, max_results].min + return { :results => list_results, + :matches_estimated => matches_estimated, + :show_no_more_than => show_no_more_than } + end + def InfoRequest.recent_requests request_events = [] request_events_all_successful = false -- cgit v1.2.3 From 8477e156d5aa4d7fc9624a0f2ab2ecc7101e7a7a Mon Sep 17 00:00:00 2001 From: Mark Longair Date: Thu, 2 Jan 2014 14:57:33 +0000 Subject: The reasons for making a report need to be translatable MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Thanks to György Peng for pointing out this omission. --- app/models/info_request.rb | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) (limited to 'app/models/info_request.rb') diff --git a/app/models/info_request.rb b/app/models/info_request.rb index 0a073dc79..4eb64dc13 100644 --- a/app/models/info_request.rb +++ b/app/models/info_request.rb @@ -113,8 +113,12 @@ class InfoRequest < ActiveRecord::Base # Possible reasons that a request could be reported for administrator attention def report_reasons - ["Contains defamatory material", "Not a valid request", "Request for personal information", - "Contains personal information", "Vexatious", "Other"] + [_("Contains defamatory material"), + _("Not a valid request"), + _("Request for personal information"), + _("Contains personal information"), + _("Vexatious"), + _("Other")] end def must_be_valid_state -- cgit v1.2.3 From bfd1a71eeb4962996db5b226a976558b9f7a50bd Mon Sep 17 00:00:00 2001 From: Louise Crow Date: Wed, 18 Dec 2013 19:08:08 +0000 Subject: Clean up admin index Refactor a bit so it's easier to read. --- app/models/info_request.rb | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'app/models/info_request.rb') diff --git a/app/models/info_request.rb b/app/models/info_request.rb index 0a073dc79..7c5ce6388 100644 --- a/app/models/info_request.rb +++ b/app/models/info_request.rb @@ -1275,6 +1275,12 @@ public return [request_events, request_events_all_successful] end + def InfoRequest.find_in_state(state) + find(:all, :select => '*, ' + last_event_time_clause + ' as last_event_time', + :conditions => ["described_state = ?", state], + :order => "last_event_time") + end + private def set_defaults -- cgit v1.2.3