diff options
author | Gareth Rees <gareth@mysociety.org> | 2015-05-07 13:34:41 +0100 |
---|---|---|
committer | Gareth Rees <gareth@mysociety.org> | 2015-05-07 13:34:41 +0100 |
commit | 63f65e7b75c1d5eb85c6176b0c79ffeda0257a13 (patch) | |
tree | 3ad2d65b49d18b422041afa0da89b16b142a9350 /app/models/info_request.rb | |
parent | e2d2c80ef59ddf8b5925246bf82582b2f82aea7e (diff) | |
parent | b624c4735c325bbc1c062d8e6c9aa89a5b7fcf19 (diff) |
Merge branch 'initialize-info-request' into rails-3-develop
Diffstat (limited to 'app/models/info_request.rb')
-rw-r--r-- | app/models/info_request.rb | 27 |
1 files changed, 26 insertions, 1 deletions
diff --git a/app/models/info_request.rb b/app/models/info_request.rb index f9f6cffa9..0ca3a1279 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 @@ -1370,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 |