aboutsummaryrefslogtreecommitdiffstats
path: root/app
diff options
context:
space:
mode:
Diffstat (limited to 'app')
-rw-r--r--app/controllers/admin_request_controller.rb19
-rw-r--r--app/models/info_request.rb27
-rw-r--r--app/models/info_request_event.rb8
-rw-r--r--app/models/post_redirect.rb6
-rw-r--r--app/models/public_body.rb19
5 files changed, 52 insertions, 27 deletions
diff --git a/app/controllers/admin_request_controller.rb b/app/controllers/admin_request_controller.rb
index 1e083f57e..db20e8dcc 100644
--- a/app/controllers/admin_request_controller.rb
+++ b/app/controllers/admin_request_controller.rb
@@ -114,21 +114,14 @@ class AdminRequestController < AdminController
end
redirect_to admin_request_url(info_request)
elsif params[:commit] == 'Move request to authority' && !params[:public_body_url_name].blank?
- old_public_body = info_request.public_body
destination_public_body = PublicBody.find_by_url_name(params[:public_body_url_name])
- if destination_public_body.nil?
- flash[:error] = "Couldn't find public body '" + params[:public_body_url_name] + "'"
- else
- info_request.public_body = destination_public_body
- info_request.save!
- info_request.log_event("move_request", {
- :editor => admin_current_user(),
- :old_public_body_url_name => old_public_body.url_name,
- :public_body_url_name => destination_public_body.url_name
- })
- info_request.reindex_request_events
- flash[:notice] = "Request has been moved to new body"
+ if info_request.move_to_public_body(destination_public_body,
+ :editor => admin_current_user,
+ :reindex => true)
+ flash[:notice] = "Request has been moved to new body"
+ else
+ flash[:error] = "Couldn't find public body '#{ params[:public_body_url_name] }'"
end
redirect_to admin_request_url(info_request)
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
diff --git a/app/models/info_request_event.rb b/app/models/info_request_event.rb
index 635ba8f58..0ee82d30c 100644
--- a/app/models/info_request_event.rb
+++ b/app/models/info_request_event.rb
@@ -278,9 +278,15 @@ class InfoRequestEvent < ActiveRecord::Base
end
self.params_yaml = params.to_yaml
end
+
def params
- YAML.load(self.params_yaml)
+ param_hash = YAML.load(params_yaml)
+ param_hash.each do |key, value|
+ param_hash[key] = value.force_encoding('UTF-8') if value.respond_to?(:force_encoding)
+ end
+ param_hash
end
+
def params_yaml_as_html
ret = ''
# split out parameters into old/new diffs, and other ones
diff --git a/app/models/post_redirect.rb b/app/models/post_redirect.rb
index 8049349d0..59160381c 100644
--- a/app/models/post_redirect.rb
+++ b/app/models/post_redirect.rb
@@ -71,7 +71,11 @@ class PostRedirect < ActiveRecord::Base
end
def reason_params
- YAML.load(reason_params_yaml)
+ param_hash = YAML.load(reason_params_yaml)
+ param_hash.each do |key, value|
+ param_hash[key] = value.force_encoding('UTF-8') if value.respond_to?(:force_encoding)
+ end
+ param_hash
end
# Extract just local path part, without domain or #
diff --git a/app/models/public_body.rb b/app/models/public_body.rb
index 5bce8ecc7..dac77d4c5 100644
--- a/app/models/public_body.rb
+++ b/app/models/public_body.rb
@@ -339,19 +339,20 @@ class PublicBody < ActiveRecord::Base
# Are all requests to this body under the Environmental Information Regulations?
def eir_only?
- return self.has_tag?('eir_only')
+ has_tag?('eir_only')
end
+
def law_only_short
- if self.eir_only?
- return "EIR"
- else
- return "FOI"
- end
+ eir_only? ? 'EIR' : 'FOI'
end
# Schools are allowed more time in holidays, so we change some wordings
def is_school?
- return self.has_tag?('school')
+ has_tag?('school')
+ end
+
+ def site_administration?
+ has_tag?('site_administration')
end
# The "internal admin" is a special body for internal use.
@@ -379,10 +380,6 @@ class PublicBody < ActiveRecord::Base
end
end
- def site_administration?
- has_tag?('site_administration')
- end
-
class ImportCSVDryRun < StandardError
end