From 0c77f6e7f95ab7d412a8929e218ecc599ed32c40 Mon Sep 17 00:00:00 2001 From: Gareth Rees Date: Fri, 1 May 2015 15:40:40 +0100 Subject: Add InfoRequest#move_to_public_body --- app/models/info_request.rb | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) (limited to 'app/models/info_request.rb') diff --git a/app/models/info_request.rb b/app/models/info_request.rb index f9f6cffa9..8f464e786 100644 --- a/app/models/info_request.rb +++ b/app/models/info_request.rb @@ -1359,6 +1359,30 @@ public order('last_event_time') end + def move_to_public_body(destination_public_body, opts = {}) + old_body = public_body + editor = opts.fetch(:editor) + + attrs = { :public_body => destination_public_body } + + if destination_public_body + attrs.merge!({ + :law_used => destination_public_body.law_only_short.downcase + }) + end + + if update_attributes(attrs) + log_event('move_request', + :editor => editor, + :public_body_url_name => public_body.url_name, + :old_public_body_url_name => old_body.url_name) + + reindex_request_events + + public_body + end + end + private def set_defaults -- cgit v1.2.3 From 47fcd7ea7c9065e2727f1954be8bbffcf17e4114 Mon Sep 17 00:00:00 2001 From: Gareth Rees Date: Wed, 22 Apr 2015 17:40:17 +0100 Subject: Don't load PublicBody when initalizing InfoRequest Doesn't need to try to set the default law_used once it's persisted, so we save a query each time we find an InfoRequest --- app/models/info_request.rb | 3 ++- 1 file changed, 2 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 8f464e786..0ca3a1279 100644 --- a/app/models/info_request.rb +++ b/app/models/info_request.rb @@ -1394,8 +1394,9 @@ public # this should only happen on Model.exists?() call. It can be safely ignored. # See http://www.tatvartha.com/2011/03/activerecordmissingattributeerror-missing-attribute-a-bug-or-a-features/ end + # FOI or EIR? - if !self.public_body.nil? && self.public_body.eir_only? + if new_record? && public_body && public_body.eir_only? self.law_used = 'eir' end end -- cgit v1.2.3