aboutsummaryrefslogtreecommitdiffstats
path: root/app/controllers
diff options
context:
space:
mode:
authorRobin Houston <robin.houston@gmail.com>2012-08-01 14:39:18 +0100
committerRobin Houston <robin.houston@gmail.com>2012-08-01 14:39:18 +0100
commit67a3a43cc26f8ad7218f33a13af04c3c74347866 (patch)
tree3fc5f27905332ba4647915eb5823d3d37615fe4c /app/controllers
parentc1d2580892033d28ff05f3d47cee78aaef963c29 (diff)
parentcc3268df4c9de319ea16aa99238e3c4c40dae7c5 (diff)
Merge branch 'develop' into wdtk
Diffstat (limited to 'app/controllers')
-rw-r--r--app/controllers/admin_censor_rule_controller.rb2
-rw-r--r--app/controllers/admin_request_controller.rb2
-rw-r--r--app/controllers/api_controller.rb16
-rw-r--r--app/controllers/application_controller.rb11
-rw-r--r--app/controllers/services_controller.rb20
5 files changed, 38 insertions, 13 deletions
diff --git a/app/controllers/admin_censor_rule_controller.rb b/app/controllers/admin_censor_rule_controller.rb
index 52df8dfc1..ec86cdf8e 100644
--- a/app/controllers/admin_censor_rule_controller.rb
+++ b/app/controllers/admin_censor_rule_controller.rb
@@ -31,6 +31,8 @@ class AdminCensorRuleController < AdminController
redirect_to admin_url('request/show/' + @censor_rule.info_request.id.to_s)
elsif !@censor_rule.user.nil?
redirect_to admin_url('user/show/' + @censor_rule.user.id.to_s)
+ elsif @censor_rule.regexp?
+ redirect_to admin_url('')
else
raise "internal error"
end
diff --git a/app/controllers/admin_request_controller.rb b/app/controllers/admin_request_controller.rb
index fd1405319..ae4bb511a 100644
--- a/app/controllers/admin_request_controller.rb
+++ b/app/controllers/admin_request_controller.rb
@@ -28,7 +28,7 @@ class AdminRequestController < AdminController
@info_request = InfoRequest.find(params[:id])
# XXX is this *really* the only way to render a template to a
# variable, rather than to the response?
- vars = OpenStruct.new(:name_to => @info_request.user.name,
+ vars = OpenStruct.new(:name_to => @info_request.user_name,
:name_from => MySociety::Config.get("CONTACT_NAME", 'Alaveteli'),
:info_request => @info_request, :reason => params[:reason],
:info_request_url => 'http://' + MySociety::Config.get('DOMAIN') + request_url(@info_request),
diff --git a/app/controllers/api_controller.rb b/app/controllers/api_controller.rb
index 4db07b4c9..a7853c787 100644
--- a/app/controllers/api_controller.rb
+++ b/app/controllers/api_controller.rb
@@ -71,10 +71,18 @@ class ApiController < ApplicationController
end
+ def _get_attachments_from_params(params)
+ attachments = []
+ params.each_pair do |k, v|
+ attachments << v if v.is_a? Tempfile
+ end
+ return attachments
+ end
+
def add_correspondence
request = InfoRequest.find(params[:id])
json = ActiveSupport::JSON.decode(params[:correspondence_json])
- attachments = params[:attachments]
+ attachments = _get_attachments_from_params(params)
direction = json["direction"]
body = json["body"]
@@ -147,12 +155,12 @@ class ApiController < ApplicationController
:filename => filename
)
end
-
mail = RequestMailer.create_external_response(request, body, sent_at, attachment_hashes)
request.receive(mail, mail.encoded, true)
end
-
- head :no_content
+ render :json => {
+ 'url' => make_url("request", request.url_title),
+ }
end
def body_request_events
diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb
index 41adf1848..a124743b2 100644
--- a/app/controllers/application_controller.rb
+++ b/app/controllers/application_controller.rb
@@ -27,6 +27,7 @@ class ApplicationController < ActionController::Base
before_filter :check_in_post_redirect
before_filter :session_remember_me
before_filter :set_vary_header
+ before_filter :set_popup_banner
# scrub sensitive parameters from the logs
filter_parameter_logging :password
@@ -133,6 +134,10 @@ class ApplicationController < ActionController::Base
# Make sure expiry time for session is set (before_filters are
# otherwise missed by this override)
session_remember_me
+
+ # Make sure the locale is set correctly too
+ set_gettext_locale
+
case exception
when ActiveRecord::RecordNotFound, ActionController::UnknownAction, ActionController::RoutingError
@status = 404
@@ -156,6 +161,9 @@ class ApplicationController < ActionController::Base
# otherwise missed by this override)
session_remember_me
+ # Make sure the locale is set correctly too
+ set_gettext_locale
+
# Display default, detailed error for developers
original_rescue_action_locally(exception)
end
@@ -553,6 +561,9 @@ class ApplicationController < ActionController::Base
return country
end
+ def set_popup_banner
+ @popup_banner = render_to_string(:partial => "general/popup_banner").strip
+ end
# URL generating functions are needed by all controllers (for redirects),
# views (for links) and mailers (for use in emails), so include them into
# all of all.
diff --git a/app/controllers/services_controller.rb b/app/controllers/services_controller.rb
index 00c0e61bd..8fa860fb2 100644
--- a/app/controllers/services_controller.rb
+++ b/app/controllers/services_controller.rb
@@ -9,15 +9,19 @@ class ServicesController < ApplicationController
if country_from_ip.downcase != iso_country_code
found_country = WorldFOIWebsites.by_code(country_from_ip)
found_country_name = !found_country.nil? && found_country[:country_name]
- old_locale = FastGettext.locale
- FastGettext.locale = FastGettext.best_locale_in(request.env['HTTP_ACCEPT_LANGUAGE'])
- if found_country_name
- text = _("Hello! You can make Freedom of Information requests within {{country_name}} at {{link_to_website}}", :country_name => found_country_name, :link_to_website => "<a href=\"#{found_country[:url]}\">#{found_country[:name]}</a>")
- else
- current_country = WorldFOIWebsites.by_code(iso_country_code)[:country_name]
- text = _("Hello! We have an <a href=\"/help/alaveteli?country_name=#{CGI.escape(current_country)}\">important message</a> for visitors outside {{country_name}}", :country_name => current_country)
+
+ old_fgt_locale = FastGettext.locale
+ begin
+ FastGettext.locale = FastGettext.best_locale_in(request.env['HTTP_ACCEPT_LANGUAGE'])
+ if found_country_name
+ text = _("Hello! You can make Freedom of Information requests within {{country_name}} at {{link_to_website}}", :country_name => found_country_name, :link_to_website => "<a href=\"#{found_country[:url]}\">#{found_country[:name]}</a>")
+ else
+ current_country = WorldFOIWebsites.by_code(iso_country_code)[:country_name]
+ text = _("Hello! We have an <a href=\"/help/alaveteli?country_name=#{CGI.escape(current_country)}\">important message</a> for visitors outside {{country_name}}", :country_name => current_country)
+ end
+ ensure
+ FastGettext.locale = old_fgt_locale
end
- FastGettext.locale = old_locale
end
if !text.empty?
text += ' <span class="close-button">X</span>'